Comments (7)
what's the exception?
from construct.
Full backtrack:
Traceback (most recent call last):
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 211, in build
self.build_stream(obj, stream)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 218, in build_stream
self._build(obj, stream, Container())
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 682, in _build
sc._build(subobj, stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 1133, in _build
self.subcon._build(obj, stream2, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 272, in _build
self.subcon._build(obj, stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 682, in _build
sc._build(subobj, stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 289, in _build
self.subcon._build(self._encode(obj, context), stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/adapters.py", line 51, in _encode
obj2 = int_to_bin(obj, width = self.width)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/lib/binary.py", line 116, in int_to_bin
i = width - 1
TypeError: unsupported operand type(s) for -: 'function' and 'int'
Here, width is the lambda from MetaField.
from construct.
For a quick fix, I added
if callable(self.width):
width = self.width(context)
else:
width = self.width
before file "/home/erenlii/.local/lib/python2.7/site-packages/construct/adapters.py", line 51, in _encode
obj2 = int_to_bin(obj, width = self.width)
from construct.
great! you can even make it shorter with obj2 = int_to_bin(obj, width = self.width(context) if callable(self.width) else self.width)
. could you test it and submit a pull request?
from construct.
Sure, i break it to pass pep8 check.
And is it the right place to fix? i'm not sure it can fix all problems with the same type.
from construct.
yeah, i think it's the right place. thanks!
Tomer Filiba
tomerfiliba.com http://www.facebook.com/tomerfiliba
http://il.linkedin.com/in/tomerfiliba
On Fri, Mar 28, 2014 at 4:24 AM, tdsparrow [email protected] wrote:
Sure, i break it to pass pep8 check.
And is it the right place to fix? i'm not sure it can fix all problems
with the same type.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/39#issuecomment-38880455
.
from construct.
This seems to have been patched a long time ago. Added regression test in a4eb053.
from construct.
Related Issues (20)
- Missing tag for 2.10.70 HOT 1
- Asyncio support HOT 1
- Determine byte size of construct containing a Switch() using sizeof() with context fails on parent construct HOT 21
- Proposals for improvements HOT 27
- [Feature] Construct build to return also parse
- [Example] ELF64 parser HOT 5
- Rebuild() with Conditional/Optional Keys HOT 2
- Scope issue when using BitStruct
- Using custom functions in Rebuild HOT 1
- pytest 8.0.0 does not run the testsuite
- sizeof() Terminated raises an error instead of returning 0 HOT 1
- `OneOf` validator fails when given a set of byte characters HOT 5
- Question: how to get the subcontext length in an Adapter? HOT 2
- PaddedString decoding error handling HOT 8
- 2.10.70: pytest fails because it cannot find `tests` HOT 7
- Fixing `_sizeof()` for variable-size fields. HOT 1
- Construct contributions to an academic paper? HOT 3
- `Computed` fields that defined later not seen in fields defined above HOT 2
- Long strings in `ListContainer` are not truncated
- Key Error: Accessing previous element in Array or GreedyRange during parsing. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from construct.