-
Notifications
You must be signed in to change notification settings - Fork 1
SL-18330: Refactor notation parsing to manage a lookahead char. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
180238a
b1abf5e
d707921
358aa11
02b27f0
66164b4
16ca726
f06b761
228103e
6591194
f5aab9f
d31981d
b83295a
e53c051
9249fce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ | |
_str_to_bytes, binary, is_integer, is_string, uri) | ||
|
||
|
||
try: | ||
# Python 2: make 'range()' lazy like Python 3 | ||
range = xrange | ||
except NameError: | ||
# Python 3: 'range()' is already lazy | ||
pass | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /me shakes fist at python 2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed ... but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah not trying to derail things too much, I just wish we could pretend to be more like python3, something like
and then we could use proper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay: 9249fce |
||
class LLSDBinaryParser(LLSDBaseParser): | ||
""" | ||
Parse application/llsd+binary to a python object. | ||
|
@@ -56,15 +64,16 @@ def __init__(self): | |
for c, func in _dispatch_dict.items(): | ||
self._dispatch[ord(c)] = func | ||
|
||
def parse(self, buffer, ignore_binary = False): | ||
def parse(self, something, ignore_binary = False): | ||
""" | ||
This is the basic public interface for parsing. | ||
|
||
:param buffer: the binary data to parse in an indexable sequence. | ||
:param something: serialized LLSD to parse: a bytes object, a binary | ||
stream or an LLSDBaseParser subclass. | ||
:param ignore_binary: parser throws away data in llsd binary nodes. | ||
:returns: returns a python object. | ||
""" | ||
self._reset(buffer) | ||
self._reset(something) | ||
self._keep_binary = not ignore_binary | ||
try: | ||
return self._parse() | ||
|
@@ -107,15 +116,10 @@ def _parse_array(self): | |
"Parse a single llsd array" | ||
rv = [] | ||
size = struct.unpack("!i", self._getc(4))[0] | ||
count = 0 | ||
cc = self._peek() | ||
while (cc != b']') and (count < size): | ||
for count in range(size): | ||
rv.append(self._parse()) | ||
count += 1 | ||
cc = self._peek() | ||
if cc != b']': | ||
if self._getc() != b']': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar. New error condition walks over offending char, old condition left it at position to be read again. Nobody may care. (This is something that happens at several points so I'm not going to mention it anymore.) |
||
self._error("invalid array close token") | ||
self._getc() | ||
return rv | ||
|
||
def _parse_string(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New version leaves the position one byte advanced relative to original. Do we care?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't. This is in the
LLSDBaseParser._error()
function, whose whole purpose is to raiseLLSDParseError
. Any consumer relying on the read position of a stream passed tollsd.parse()
afterLLSDParseError
needs to be fixed.