Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix ``node.utils.StrCodec.encode`` to return value as is if str and d…

…ecoding
  • Loading branch information...
commit 6d322c43f7fd7c4c10100d3fee7f29d0ae33742c 1 parent a875c38
@rnixx rnixx authored
View
6 README.rst
@@ -285,6 +285,12 @@ Contributors
Changes
=======
+0.9.10dev
+---------
+
+- Fix ``node.utils.StrCodec.encode`` to return value as is if str and decoding
+ failed.
+ [rnix, 2012-11-07]
0.9.9
-----
View
2  setup.py
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '0.9.9'
+version = '0.9.10dev'
shortdesc = "Building data structures as node trees"
longdesc = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
longdesc += open(os.path.join(os.path.dirname(__file__), 'LICENSE.rst')).read()
View
12 src/node/utils.py
@@ -141,7 +141,11 @@ def encode(self, arg):
"""Return an encoded copy of the argument
- strs are decoded and reencode to make sure they conform to the
- encoding
+ encoding.
+ XXX: makes no sence, especially because a UnicodeDecodeError ends up
+ in a recursion error due to re-trying to encode. See below.
+ Added condition to return if str is still str after decoding.
+ This behavior should be removed completely.
- unicodes are encoded as str according to encoding
@@ -154,7 +158,11 @@ def encode(self, arg):
elif isinstance(arg, dict):
arg = dict([self.encode(t) for t in arg.iteritems()])
elif isinstance(arg, str):
- arg = self.encode(self.decode(arg))
+ arg = self.decode(arg)
+ # If UnicodeDecodeError, binary data is expected. Return value
+ # as is.
+ if not isinstance(arg, str):
+ arg = self.encode(arg)
elif isinstance(arg, unicode):
arg = arg.encode(self._encoding)
elif INode.providedBy(arg):
View
4 src/node/utils.rst
@@ -95,6 +95,10 @@ StrCodec decode and encode
... encode,
... decode,
... )
+ >>> encode('\x01\x05\x00\x00\x00\x00\x00\x05\x15\x00\x00\x00\xd4'
+ ... '\xa0\xff\xff\xaeW\x82\xa9P\xcf8\xaf&\x0e\x00\x00')
+ '\x01\x05\x00\x00\x00\x00\x00\x05\x15\x00\x00\x00\xd4\xa0\xff\xff\xaeW\x82\xa9P\xcf8\xaf&\x0e\x00\x00'
+
>>> encode(u'\xe4')
'\xc3\xa4'
Please sign in to comment.
Something went wrong with that request. Please try again.