Skip to content

Commit 6586308

Browse files
committed
CR changes
1 parent 78601c0 commit 6586308

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

llsd/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _array_to_python(node, depth=0):
317317
def _to_python(node, depth=0):
318318
"Convert node to a python object."
319319
if depth > MAX_PARSE_DEPTH:
320-
raise LLSDParseError("Cannot serialize depth of more than %d" % MAX_FORMAT_DEPTH)
320+
raise LLSDSerializationError("Cannot serialize depth of more than %d" % MAX_FORMAT_DEPTH)
321321

322322
return NODE_HANDLERS[node.tag](node, depth)
323323

llsd/serde_binary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def parse(self, something, ignore_binary = False):
8383
def _parse(self):
8484
"The actual parser which is called recursively when necessary."
8585
if self._depth > MAX_PARSE_DEPTH:
86-
self._error("Parse depth exceeded max.")
86+
self._error("Parse depth exceeded maximum depth of %d." % MAX_PARSE_DEPTH)
8787

8888
cc = self._getc()
8989
try:
@@ -100,7 +100,7 @@ def _parse_map(self):
100100
count = 0
101101
cc = self._getc()
102102
key = b''
103-
self._depth = self._depth + 1
103+
self._depth += 1
104104
while (cc != b'}') and (count < size):
105105
if cc == b'k':
106106
key = self._parse_string()
@@ -114,7 +114,7 @@ def _parse_map(self):
114114
cc = self._getc()
115115
if cc != b'}':
116116
self._error("invalid map close token")
117-
self._depth = self._depth - 1
117+
self._depth -= 1
118118
return rv
119119

120120
def _parse_array(self):

llsd/serde_notation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _get_until(self, delim):
109109
def _parse(self, cc):
110110
"The notation parser workhorse."
111111
if self._depth > MAX_PARSE_DEPTH:
112-
self._error("Parse depth exceeded max.")
112+
self._error("Parse depth exceeded max of %d" % MAX_PARSE_DEPTH)
113113
try:
114114
func = self._dispatch[ord(cc)]
115115
except IndexError:

llsd/serde_xml.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ class LLSDXMLFormatter(LLSDBaseFormatter):
6969
interface to this functionality.
7070
"""
7171

72-
def __init__(self, indent_atom = None):
72+
def __init__(self, indent_atom = b'', eol = b''):
7373
"Construct a serializer."
7474
# Call the super class constructor so that we have the type map
7575
super(LLSDXMLFormatter, self).__init__()
76-
self._indent_atom = b''
77-
self._eol = b''
76+
self._indent_atom = indent_atom
77+
self._eol = eol
7878
self._depth = 1
7979

8080
def _indent(self):
@@ -178,14 +178,10 @@ class LLSDXMLPrettyFormatter(LLSDXMLFormatter):
178178
This class is not necessarily suited for serializing very large objects.
179179
It sorts on dict (llsd map) keys alphabetically to ease human reading.
180180
"""
181-
def __init__(self, indent_atom = b' '):
181+
def __init__(self, indent_atom = b' ', eol = b'\n'):
182182
"Construct a pretty serializer."
183183
# Call the super class constructor so that we have the type map
184-
super(LLSDXMLPrettyFormatter, self).__init__()
185-
186-
# Private data used for indentation.
187-
self._indent_atom = indent_atom
188-
self._eol = b'\n'
184+
super(LLSDXMLPrettyFormatter, self).__init__(indent_atom = indent_atom, eol = eol)
189185

190186
def _indent(self):
191187
"Write an indentation based on the atom and indentation level."

tests/llsd_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import pytest
1717

1818
import llsd
19-
from llsd.base import PY2, is_integer, is_string, is_unicode
19+
from llsd.base import PY2, is_integer, is_string, is_unicode, MAX_FORMAT_DEPTH, MAX_PARSE_DEPTH
2020
from llsd.serde_xml import remove_invalid_xml_bytes
2121
from tests.fuzz import LLSDFuzzer
2222

@@ -533,7 +533,7 @@ def testDeepMap(self):
533533
"""
534534

535535
test_map = {"foo":"bar", "depth":0}
536-
max_depth = 199
536+
max_depth = MAX_FORMAT_DEPTH - 1
537537
for depth in range(max_depth):
538538
test_map = {"foo":"bar", "depth":depth, "next":test_map}
539539

@@ -990,7 +990,7 @@ def testDeepMap(self):
990990
"""
991991

992992
test_map = {"foo":"bar", "depth":0}
993-
max_depth = 199
993+
max_depth = MAX_FORMAT_DEPTH -1
994994
for depth in range(max_depth):
995995
test_map = {"foo":"bar", "depth":depth, "next":test_map}
996996

@@ -1525,7 +1525,7 @@ def testDeepMap(self):
15251525
"""
15261526

15271527
test_map = {"foo":"bar", "depth":0}
1528-
max_depth = 199
1528+
max_depth = MAX_FORMAT_DEPTH - 1
15291529
for depth in range(max_depth):
15301530
test_map = {"foo":"bar", "depth":depth, "next":test_map}
15311531

0 commit comments

Comments
 (0)