You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What would you like to be added to Construct? #824
I'm still looking for a way to differentiate exceptions raised by Checksum.
I have multiple Checksums in my application which check different conditions (e.g. file validation, credentials authentication), but I have to print out a really generic error message when any of these fail because there's no way to tell the exceptions apart.
I dont think this is really necessary to be available to everyone. But the solution is simple, just copy paste the source of Checksum into your script and change the constructor to take an exception type. Simple.
MESSAGE TO EVERYONE: I am about to remove Embedded and EmbeddedSwitch from the core library. I know its in use here and there but please understand, the semantics have changed so much that using this as is now is pointless.
The alternative to embedding is simply nesting. Nesting is already covered in the docs through and through. Nesting is the recommended way of doing things anyway.
@arekbulski GreedyByte is no longer able to build from bytearray in python 3.
the example below works in python 2.7 but not 3. prior to 2.10 this was working for both 2 and 3. I believe btyearray should be treated as bytes.
d = bytearray(b'\x11\x01\x05')
GreedyBytes.build(d)
Sorry to hear that, just wanted to share this concept as it might benefit this project.
(the linked repo was opened simply to show the example code to give the idea (regarding recent discussion about type annotations), so further work can be migrated here if the idea is good enough)
My main desire at the moment is to see the currently monolithic nature of the project refactored properly into separately named files. This would have benefits to debugging by improving the quality of the stack trace (i.e. _sizeof in <subcon>.py, rather than _sizeof (which, there's many!) in core.py). It would also enable quicker zooming in on a specific subcon, or class for modification or understanding, and allow switching between different classes without scrolling loads in a file or using IDE bookmarks.
This is not going to happen as long as I am the main developer of this library. When I took over the project, I found it jumping between modules to be a hassle and keeping everything (well almost everything) together to be much more manageable. You seem to be unaware of the fact that now all exceptions include path information (see ticket #826).
In the stack trace, I see the following (latest version) when running something which will cause exceptions (the sizeof thing being discussed in aother ticket, incidentally):
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 382, in sizeof
return self._sizeof(context, "(sizeof)")
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 3642, in _sizeof
return sc._sizeof(context, path)
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 2016, in _sizeof
return sum(sc._sizeof(context, path) for sc in self.subcons)
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 2016, in
return sum(sc._sizeof(context, path) for sc in self.subcons)
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 2447, in _sizeof
return self.subcon._sizeof(context, path)
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 685, in _sizeof
return self.subcon._sizeof(context, path)
File "C:\Users\me\ConstructVenv\lib\site-packages\construct\core.py", line 4592, in _sizeof
There are six different sizeof calls in six different locations of the core.py file, something specifying in which classes the issue occurred would be suitable, don't particularly care what method is used, though...
Whilst python is known for it's good use of "flat" files and classes, a 5k line file is pushing it a bit, IMO, however I accept that the refactor work would be a lot of effort for not much gain.
The new path exceptions are very nice though, thanks @Evidlo for those!
As you know, I'd also like to see better checksumming/exceptions with ignorable checksum warnings etc
Any other ideas are forgotten since that Gitter post, but I will be working again with Construct to parse another binary format imminently which will I'm sure throw up some ideas!
Well, if you want to thank for the path exceptions info then half of that goes to me. I implemented half of it way way back. The difference that Evidlo made was that before, it was only visible on Travis as locals, now it displays for users on their consoles. Still, on everyone's behalf thank you @Evidlo.
Checksum warnings are not gonna appear in the core library. I suggest that you open a new Issue and post there a modified version of Checksum. Just so other people can find this "recipe".
EDIT: Already beat you to it.
Activity
arekbulski commentedon Jan 17, 2020
@yannayl
I also welcome your input. How is Lazy* stuff working for ya?
[-]Chat with DanseMacabre[/-][+]What would you like to be added to Construct?[/+]Evidlo commentedon Jan 18, 2020
I'm still looking for a way to differentiate exceptions raised by
Checksum.I have multiple
Checksumsin my application which check different conditions (e.g. file validation, credentials authentication), but I have to print out a really generic error message when any of these fail because there's no way to tell the exceptions apart.arekbulski commentedon Jan 18, 2020
I dont think this is really necessary to be available to everyone. But the solution is simple, just copy paste the source of Checksum into your script and change the constructor to take an exception type. Simple.
arekbulski commentedon Jan 18, 2020
This approach was kinda already written in the docs, just not so directly. See for yourself:
https://construct.readthedocs.io/en/latest/extending.html#constructs
I added the green box just now.
arekbulski commentedon Jan 18, 2020
I just found your old Issue that you had for this: #731
arekbulski commentedon Jan 19, 2020
I guess we can also post here #826 which is showing path in exceptin messages. Already done.
arekbulski commentedon Jan 19, 2020
MESSAGE TO EVERYONE: I am about to remove Embedded and EmbeddedSwitch from the core library. I know its in use here and there but please understand, the semantics have changed so much that using this as is now is pointless.
sbasharati commentedon Jan 20, 2020
@arekbulski Some code examples to migrate Embedded and EmbeddedSwitch to 2.10 would be useful.
arekbulski commentedon Jan 20, 2020
The alternative to embedding is simply nesting. Nesting is already covered in the docs through and through. Nesting is the recommended way of doing things anyway.
arekbulski commentedon Jan 20, 2020
I updated the docs accordingly:
https://construct.readthedocs.io/en/latest/basics.html#nesting-and-embedding
sbasharati commentedon Jan 21, 2020
@arekbulski GreedyByte is no longer able to build from bytearray in python 3.
the example below works in python 2.7 but not 3. prior to 2.10 this was working for both 2 and 3. I believe btyearray should be treated as bytes.
arekbulski commentedon Jan 21, 2020
This must have been an issue at 2.9 or earlier, because 2.10 didnt touch these things.Fixed it.But yes, I will fix this.
58 remaining items
arekbulski commentedon Feb 8, 2020
What I think is that you are doing unsolicited advertisement of your project. It has nothing to do with Construct at all.
BLooperZ commentedon Feb 8, 2020
Sorry to hear that, just wanted to share this concept as it might benefit this project.
(the linked repo was opened simply to show the example code to give the idea (regarding recent discussion about type annotations), so further work can be migrated here if the idea is good enough)
arekbulski commentedon Feb 8, 2020
Okay okay. The example you provide is even less comprehensible than examples that were provided in this thread. Unreadable.
arekbulski commentedon Feb 11, 2020
Hmm what happened to @DanseMacabre ...
DanseMacabre commentedon Feb 19, 2020
@arekbulski Hi! GMail decided that it didn't want me to see any emails from github for a while.
Should be fixed now, although I am looking in utter disgust at the increase in backlog!
arekbulski commentedon Feb 19, 2020
@DanseMacabre I seen your post on gitter and wanted to ask, what are your suggestions for further expansion of Construct?
DanseMacabre commentedon Feb 21, 2020
My main desire at the moment is to see the currently monolithic nature of the project refactored properly into separately named files. This would have benefits to debugging by improving the quality of the stack trace (i.e. _sizeof in <subcon>.py, rather than _sizeof (which, there's many!) in core.py). It would also enable quicker zooming in on a specific subcon, or class for modification or understanding, and allow switching between different classes without scrolling loads in a file or using IDE bookmarks.
arekbulski commentedon Feb 21, 2020
This is not going to happen as long as I am the main developer of this library. When I took over the project, I found it jumping between modules to be a hassle and keeping everything (well almost everything) together to be much more manageable. You seem to be unaware of the fact that now all exceptions include path information (see ticket #826).
DanseMacabre commentedon Feb 21, 2020
In the stack trace, I see the following (latest version) when running something which will cause exceptions (the sizeof thing being discussed in aother ticket, incidentally):
There are six different sizeof calls in six different locations of the core.py file, something specifying in which classes the issue occurred would be suitable, don't particularly care what method is used, though...
Whilst python is known for it's good use of "flat" files and classes, a 5k line file is pushing it a bit, IMO, however I accept that the refactor work would be a lot of effort for not much gain.
The new path exceptions are very nice though, thanks @Evidlo for those!
As you know, I'd also like to see better checksumming/exceptions with ignorable checksum warnings etc
Any other ideas are forgotten since that Gitter post, but I will be working again with Construct to parse another binary format imminently which will I'm sure throw up some ideas!
arekbulski commentedon Feb 22, 2020
Well, if you want to thank for the path exceptions info then half of that goes to me. I implemented half of it way way back. The difference that Evidlo made was that before, it was only visible on Travis as locals, now it displays for users on their consoles. Still, on everyone's behalf thank you @Evidlo.
Checksum warnings are not gonna appear in the core library. I suggest that you open a new Issue and post there a modified version of Checksum. Just so other people can find this "recipe".
EDIT: Already beat you to it.