pyeve / eve-sqlalchemy

SQLAlchemy data layer for Eve-powered RESTful APIs
http://eve-sqlalchemy.readthedocs.io
Other
234 stars 70 forks source link

Unicode problem in python 3 #62

Closed amleczko closed 9 years ago

amleczko commented 9 years ago

After #61 we have this problem:

(...)
    r = f(resource, **combined_args)
  File "/home/goneri/git_repos/eve/eve/methods/get.py", line 105, in get
    build_response_document(document, resource, embedded_fields)
  File "/home/goneri/git_repos/eve/eve/methods/common.py", line 506, in build_response_document
    resolve_embedded_documents(document, resource, embedded_fields)
  File "/home/goneri/git_repos/eve/eve/methods/common.py", line 692, in resolve_embedded_documents
    subdocument[last_field]))
  File "/home/goneri/git_repos/eve/eve/methods/common.py", line 684, in <lambda>
    getter = lambda ref: embedded_document(ref, data_relation, field)  # noqa
  File "/home/goneri/git_repos/eve/eve/methods/common.py", line 623, in embedded_document
    **{config.ID_FIELD: reference})
  File "/home/goneri/git_repos/eve-sqlalchemy/eve_sqlalchemy/__init__.py", line 174, in find_one
    parse_dictionary(lookup, model))
  File "/home/goneri/git_repos/eve-sqlalchemy/eve_sqlalchemy/parser.py", line 45, in parse_dictionary
    if(type(v) is unicode):
NameError: name 'unicode' is not defined
terrysclaw commented 9 years ago

line 45 change to if(type(v) == type(u'')): can solved the problem in python 3

    try:
        if(type(v) == type(u'')):
            conditions += parse('{0}{1}'.format(k, v.encode('utf-8')), model)
        else:
            conditions += parse('{0}{1}'.format(k, v), model)
    except ParseError:
        pass
    else:
        continue
joystein commented 9 years ago

Pep8 test in tox now complains about the way of testing type:

pep8 runtests: PYTHONHASHSEED='803820383'
pep8 runtests: commands[0] | flake8
./eve_sqlalchemy/parser.py:45:24: E721 do not compare types, use 'isinstance()'