Skip to content

Commit 3cb48f9

Browse files
committed
Yajl-Py 2.0.2
Details: Massive changes to support Yajl 2. There is a slight API breaking change in YajlParser and YajlGen: YajlParser: no longer is configured by __init__, it is not configured by attaching attributes to the parser before calling parse. Attribute names are similar to that of yajl Yajl Gen: indent is now changed to indent_string to comply with yajl naming scheme. Now accpets all yajl gen config with names similar to that of yajl's
1 parent 5d41882 commit 3cb48f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+205
-79
lines changed

examples/README.rst

Lines changed: 1 addition & 1 deletion

examples/json_reformat.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ class ReformatContentHandler(YajlContentHandler):
1515
'''
1616
Content handler to reformat a json file using yajl_gen
1717
'''
18-
def __init__(self, beautify=True, indent=" "):
18+
def __init__(self, beautify=True, indent_string=" "):
1919
self.out = sys.stdout
2020
self.beautify = beautify
21-
self.indent = indent
21+
self.indent_string = indent_string
2222
def parse_start(self):
23-
self.g = YajlGen(beautify=self.beautify, indent=self.indent)
23+
self.g = YajlGen(beautify=self.beautify, indent_string=self.indent_string)
2424
def parse_buf(self):
2525
self.out.write(self.g.yajl_gen_get_buf())
2626
def parse_complete(self):
@@ -54,12 +54,13 @@ def main():
5454
dest="beautify", action="store_false", default=True,
5555
help="minimize json rather than beautify (default)")
5656
opt_parser.add_option("-u",
57-
dest="check_utf8", action='store_false', default=True,
57+
dest="dont_validate_strings", action='store_true', default=False,
5858
help="allow invalid UTF8 inside strings during parsing")
5959
(options, args) = opt_parser.parse_args()
60-
yajl_parser = YajlParser(
61-
ReformatContentHandler(beautify=options.beautify),
62-
check_utf8=options.check_utf8)
60+
ch = ReformatContentHandler(beautify=options.beautify)
61+
yajl_parser = YajlParser(ch)
62+
yajl_parser.allow_comments = True # let's allow comments by default
63+
yajl_parser.dont_validate_strings = options.dont_validate_strings
6364
yajl_parser.parse()
6465

6566
if __name__ == "__main__":

examples/json_verify.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def main():
2222
dest="allow_comments", action="store_true", default=False,
2323
help="allow comments")
2424
opt_parser.add_option("-u",
25-
dest="check_utf8", action='store_false', default=True,
25+
dest="dont_validate_strings", action='store_true', default=False,
2626
help="allow invalid utf8 inside strings")
2727
(options, args) = opt_parser.parse_args()
28-
yajl_parser = YajlParser(
29-
allow_comments=options.allow_comments,
30-
check_utf8=options.check_utf8)
28+
yajl_parser = YajlParser()
29+
yajl_parser.allow_comments = options.allow_comments
30+
yajl_parser.dont_validate_strings = options.dont_validate_strings
3131
retval = 0
3232
try:
3333
yajl_parser.parse()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
map open '{'
2+
key: 'this'
3+
string: 'is'
4+
key: 'really'
5+
string: 'simple'
6+
key: 'json'
7+
string: 'right?'
8+
map close '}'
9+
memory leaks: 0

0 commit comments

Comments
 (0)