python 2.4 adjustment diff
guzzijones opened this issue · 3 comments
guzzijones commented
Here is the diff I made for fix __encode for python 2.4. I assume it will work for python on up:
def __encode(self, obj):
s = ''
tab = self.tab
newline = self.newline
tp = type(obj)
if tp is str:
s += '"%s"' % obj.replace(r'"', r'\"')
elif tp in [int, float, long, complex]:
s += str(obj)
elif tp is bool:
s += str(obj).lower()
elif tp in [list, tuple, dict]:
self.depth += 1
if len(obj) == 0 or ( tp is not dict and len(filter(
lambda x: type(x) in (int, float, long) \
or (type(x) is str and len(x) < 10), obj
)) == len(obj) ):
newline = tab = ''
dp = tab * self.depth
s += "%s{%s" % (tab * (self.depth - 2), newline)
if tp is dict:
listtmp=[]
for k,v in obj.iteritems():
if type(k) is int:
self.__encode(v)
else:
listtmp.append(dp + '%s = %s' % (k, self.__encode(v)))
s += (',%s' % newline).join(listtmp)
else:
s += (',%s' % newline).join(
[dp + self.__encode(el) for el in obj])
self.depth -= 1
s += "%s%s}" % (newline, tab * self.depth)
return s
I also had to fix the exception handling on line 223
except ParseError as e:
print e
return 0
should be changed to
except ParseError :
t, e = sys.exc_info()[:2]
print(e)
return 0
Deleted user commented
Thx !
guzzijones commented
I will post it up to my fork tonight and do a pull request.
On Fri, Jan 1, 2016, at 07:23 AM, etcher wrote:
Thx !
— Reply to this email directly or view it on GitHub[1].
Aaron Jonen
ajonen@mailcan.com
Links:
guzzijones commented
I am going to close this in favor of the pull request