Skip to content

Commit 5329bd2

Browse files
committed
Updating examples to show what changed for py3.
1 parent be5536f commit 5329bd2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

examples/json_reformat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ReformatContentHandler(YajlContentHandler):
2020
'''
2121
Content handler to reformat a json file using yajl_gen
2222
'''
23-
def __init__(self, beautify=True, indent_string=" ", stream=False):
23+
def __init__(self, beautify=True, indent_string=b" ", stream=False):
2424
self.out = sys.stdout
2525
self.beautify = beautify
2626
self.indent_string = indent_string
@@ -31,7 +31,7 @@ def parse_start(self):
3131
indent_string=self.indent_string,
3232
)
3333
def parse_buf(self):
34-
self.out.write(self.g.yajl_gen_get_buf())
34+
self.out.write(self.g.yajl_gen_get_buf().decode('utf-8'))
3535
def parse_complete(self):
3636
if not stream:
3737
# not necessary, gc will do this @ python shutdown
@@ -41,7 +41,7 @@ def check_and_return(self, func, *args, **kwargs):
4141
func(*args, **kwargs)
4242
except YajlGenException as e:
4343
if self.stream and e.value == 'yajl_gen_generation_complete':
44-
self.g.yajl_gen_reset('\n')
44+
self.g.yajl_gen_reset(b'\n')
4545
func(*args, **kwargs)
4646
else:
4747
raise

examples/json_verify.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Python implementation of the Yajl C json_verify application
33
'''
44

5+
import six
56
import os
67
import sys
78
BASEPATH = os.path.dirname(os.path.realpath(__file__))
@@ -31,12 +32,12 @@ def main():
3132
retval = 0
3233
try:
3334
yajl_parser.parse()
34-
except YajlError, e:
35+
except YajlError as e:
3536
retval = 1
3637
if options.verbose:
37-
sys.stderr.write(str(e))
38+
sys.stderr.write(e.value)
3839
if options.verbose:
39-
print "JSON is %s" %("invalid" if retval else "valid")
40+
six.print_("JSON is %s" %("invalid" if retval else "valid"))
4041
raise SystemExit(retval)
4142

4243
if __name__ == "__main__":

0 commit comments

Comments
 (0)