Skip to content

Commit

Permalink
In the wrapper class, call the value in decode, if it's a callable.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Apr 9, 2015
1 parent b35daa3 commit 1f338a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
0.3 (unreleased)
----------------

- In the wrapper class, call the value in decode, if it's a callable.
[thet]

- When serializing datetime, date, time or DateTime properties, just use the
unicode representation which can be parsed.
[thet]
Expand Down
7 changes: 5 additions & 2 deletions collective/jsonify/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ def __init__(self, context):
def decode(self, s, encodings=('utf8', 'latin1', 'ascii')):
"""Sometimes we have to guess charset
"""
if callable(s):
s = s()
if isinstance(s, unicode):
return s
test_encodings = encodings
if self.charset:
test_encodings = (self.charset, ) + encodings
test_encodings = (self.charset, ) + test_encodings
for encoding in test_encodings:
try:
return s.decode(encoding)
Expand Down Expand Up @@ -208,7 +211,7 @@ def get_archetypes_fields(self):

if value and type_ in ['ComputedField']:
if isinstance(value, str):
value = value.decode('utf-8')
value = self.decode(value)

if value and type_ in ['StringField', 'TextField']:
try:
Expand Down

0 comments on commit 1f338a0

Please sign in to comment.