Permalink
Browse files

add unicode handling to C extension module.

  • Loading branch information...
1 parent 32bdf62 commit 5bfc74dd37be3de700bd7749cba2767a7cd834bb @rfk committed May 6, 2011
Showing with 389 additions and 150 deletions.
  1. +14 −14 tnetstring/__init__.py
  2. +290 −74 tnetstring/_tnetstring.c
  3. +19 −21 tnetstring/tests/test_format.py
  4. +45 −23 tnetstring/tns_core.c
  5. +20 −17 tnetstring/tns_core.h
  6. +1 −1 tools/shootout.py
View
@@ -49,7 +49,7 @@
def dumps(value,encoding=None):
- """dumps(object) -> string
+ """dumps(object,encoding=None) -> string
This function dumps a python object as a tnetstring.
"""
@@ -65,7 +65,7 @@ def dumps(value,encoding=None):
def dump(value,file,encoding=None):
- """dump(object, file)
+ """dump(object,file,encoding=None)
This function dumps a python object as a tnetstring and writes it to
the given file.
@@ -132,7 +132,7 @@ def _rdumpq(q,size,value,encoding=None):
write("]")
init_size = size = size + 1
for item in reversed(value):
- size = _rdumpq(q,size,item)
+ size = _rdumpq(q,size,item,encoding)
span = str(size - init_size)
write(":")
write(span)
@@ -141,8 +141,8 @@ def _rdumpq(q,size,value,encoding=None):
write("}")
init_size = size = size + 1
for (k,v) in value.iteritems():
- size = _rdumpq(q,size,v)
- size = _rdumpq(q,size,k)
+ size = _rdumpq(q,size,v,encoding)
+ size = _rdumpq(q,size,k,encoding)
span = str(size - init_size)
write(":")
write(span)
@@ -225,7 +225,7 @@ def _gdumps(value,encoding):
def loads(string,encoding=None):
- """loads(string) -> object
+ """loads(string,encoding=None) -> object
This function parses a tnetstring into a python object.
"""
@@ -236,7 +236,7 @@ def loads(string,encoding=None):
def load(file,encoding=None):
- """load(file) -> object
+ """load(file,encoding=None) -> object
This function reads a tnetstring from a file and parses it into a
python object. The file must support the read() method, and this
@@ -293,22 +293,22 @@ def load(file,encoding=None):
if type == "]":
l = []
while data:
- (item,data) = pop(data)
+ (item,data) = pop(data,encoding)
l.append(item)
return l
if type == "}":
d = {}
while data:
- (key,data) = pop(data)
- (val,data) = pop(data)
+ (key,data) = pop(data,encoding)
+ (val,data) = pop(data,encoding)
d[key] = val
return d
raise ValueError("unknown type tag")
def pop(string,encoding=None):
- """pop(string) -> (object, remain)
+ """pop(string,encoding=None) -> (object, remain)
This function parses a tnetstring into a python object.
It returns a tuple giving the parsed object and a string
@@ -355,14 +355,14 @@ def pop(string,encoding=None):
if type == "]":
l = []
while data:
- (item,data) = pop(data)
+ (item,data) = pop(data,encoding)
l.append(item)
return (l,remain)
if type == "}":
d = {}
while data:
- (key,data) = pop(data)
- (val,data) = pop(data)
+ (key,data) = pop(data,encoding)
+ (val,data) = pop(data,encoding)
d[key] = val
return (d,remain)
raise ValueError("unknown type tag")
Oops, something went wrong.

0 comments on commit 5bfc74d

Please sign in to comment.