@@ -17,35 +17,33 @@ class ReformatContentHandler(YajlContentHandler):
17
17
'''
18
18
def __init__ (self , beautify = True , indent = " " ):
19
19
self .out = sys .stdout
20
- self .conf = yajl_gen_config (beautify , indent )
20
+ self .beautify = beautify
21
+ self .indent = indent
21
22
def parse_start (self ):
22
- self .g = yajl . yajl_gen_alloc ( byref ( self .conf ), None )
23
+ self .g = YajlGen ( beautify = self .beautify , indent = self . indent )
23
24
def parse_buf (self ):
24
- l = c_uint ()
25
- buf = POINTER (c_ubyte )()
26
- yajl .yajl_gen_get_buf (self .g , byref (buf ), byref (l ))
27
- self .out .write (string_at (buf , l .value ))
28
- yajl .yajl_gen_clear (self .g )
25
+ self .out .write (self .g .yajl_gen_get_buf ())
29
26
def parse_complete (self ):
30
- yajl .yajl_gen_free (self .g )
27
+ # not necessary, gc will do this @ python shutdown
28
+ del self .g
31
29
def yajl_null (self , ctx ):
32
- yajl . yajl_gen_null ( self .g )
30
+ self .g . yajl_gen_null ( )
33
31
def yajl_boolean (self , ctx , boolVal ):
34
- yajl . yajl_gen_bool ( self .g , boolVal )
32
+ self .g . yajl_gen_bool ( boolVal )
35
33
def yajl_number (self , ctx , stringNum ):
36
- yajl . yajl_gen_number ( self .g , c_char_p (stringNum ), len ( stringNum ) )
34
+ self .g . yajl_gen_number (stringNum )
37
35
def yajl_string (self , ctx , stringVal ):
38
- yajl . yajl_gen_string ( self .g , c_char_p (stringVal ), len ( stringVal ) )
36
+ self .g . yajl_gen_string (stringVal )
39
37
def yajl_start_map (self , ctx ):
40
- yajl . yajl_gen_map_open ( self .g )
38
+ self .g . yajl_gen_map_open ( )
41
39
def yajl_map_key (self , ctx , stringVal ):
42
- yajl . yajl_gen_string ( self .g , c_char_p (stringVal ), len ( stringVal ) )
40
+ self .g . yajl_gen_string (stringVal )
43
41
def yajl_end_map (self , ctx ):
44
- yajl . yajl_gen_map_close ( self .g )
42
+ self .g . yajl_gen_map_close ( )
45
43
def yajl_start_array (self , ctx ):
46
- yajl . yajl_gen_array_open ( self .g )
44
+ self .g . yajl_gen_array_open ( )
47
45
def yajl_end_array (self , ctx ):
48
- yajl . yajl_gen_array_close ( self .g )
46
+ self .g . yajl_gen_array_close ( )
49
47
50
48
51
49
def main ():
0 commit comments