Skip to content

Commit

Permalink
fix wrong stringfied non-string value in sqlalchemy.projectdb
Browse files Browse the repository at this point in the history
fix function unicode not exists in py3 in utils.utf8
  • Loading branch information
binux committed May 27, 2015
1 parent 36027a4 commit 734cb3b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pyspider/database/sqlalchemy/projectdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ def __init__(self, url):
def _parse(data):
if six.PY3:
for key, value in list(six.iteritems(data)):
data[utils.text(key)] = utils.text(value)
if isinstance(value, six.binary_type):
data[utils.text(key)] = utils.text(value)
else:
data[utils.text(key)] = value
return data

@staticmethod
def _stringify(data):
if six.PY3:
for key, value in list(six.iteritems(data)):
data[key] = utils.utf8(value)
if isinstance(value, six.string_types):
data[key] = utils.utf8(value)
return data

def insert(self, name, obj={}):
Expand Down
2 changes: 1 addition & 1 deletion pyspider/libs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def utf8(string):
elif isinstance(string, six.binary_type):
return string
else:
return unicode(string).encode('utf8')
return six.text_type(string).encode('utf8')


def text(string, encoding='utf8'):
Expand Down

0 comments on commit 734cb3b

Please sign in to comment.