Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions 40 construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5578,6 +5578,46 @@ def _build(self, obj, stream, context, path):
def _sizeof(self, context, path):
return self.checksumfield._sizeof(context, path)

def _emitparse(self, code):
fname = f"parse_select_{code.allocateId()}"

block = f"""
def {fname}(io, this):
fallback = io.tell()
"""
for sc in self.subcons:
cb = sc._compileparse(code)
if cb == "None":
block += """
return None
"""
else:
block += f"""
try:
return {cb}
except ExplicitError:
raise
except Exception:
io.seek(fallback)
"""
code.append(block)
return "%s(io, this)" % (fname,)

def _emitbuild(self, code):
fname = f"build_select_{code.allocateId()}"

block = f"""
def {fname}(obj, io, this):
"""
for sc in self.subcons:
block += f"""
try:
return {sc._compilebuild(code)}
except:
pass
"""
code.append(block)
return "%s(obj, io, this)" % (fname,)

class Compressed(Tunnel):
r"""
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.