Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

web.debugerror doesn't display utf-8 #26

Closed
w0rm opened this Issue Nov 8, 2010 · 5 comments

Comments

Projects
None yet
3 participants

w0rm commented Nov 8, 2010

Cannot get error display correctly, check this test case

# coding: utf-8
import web
urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:        
    def GET(self, name):
        a = u"ошибка" # if remove this line and coding declaration—then everything is fine
        raise Exception("test")
if __name__ == "__main__":
    app.run()

Most of the time i get this in the browser instead of pretty djangoerror:

Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/web/wsgiserver/__init__.py", line 1174, in communicate
    req.respond()
  File "/Library/Python/2.6/site-packages/web/wsgiserver/__init__.py", line 544, in respond
    self._respond()
  File "/Library/Python/2.6/site-packages/web/wsgiserver/__init__.py", line 558, in _respond
    for chunk in response:
  File "/Library/Python/2.6/site-packages/web/utils.py", line 353, in safestr
    return str(obj)
  File "/Library/Python/2.6/site-packages/web/template.py", line 1260, in __str__
    return self["__body__"].encode('utf-8')
  File "/Library/Python/2.6/site-packages/web/template.py", line 1253, in __getitem__
    self["__body__"] = u"".join(self._data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 19: ordinal not in range(128)

chuangbo commented Nov 9, 2010

I fix this ugly

             # create template to make sure it compiles
             t = Template(open(path).read(), path)
@@ -1252,7 +1250,7 @@ class TemplateResult(storage, DictMixin):

     def __getitem__(self, name):
         if name == "__body__" and storage.__getitem__(self, '__body__') is None:
-            self["__body__"] = u"".join(map(safeunicode, self._data))
+            self["__body__"] = u"".join(self._data)
         return storage.__getitem__(self, name)

     def __unicode__(self): 

w0rm commented Nov 9, 2010

Thanks, using safeunicode helped me.

chuangbo commented Nov 9, 2010

This just works. But far away exactly. I don't know how the template work.

w0rm commented Nov 9, 2010

Unicode inconsistency in webpy troubles me a lot, every time it puts me in a doubt either I should use u"" prefix or not. webpy#27 is from the same opera.

Contributor

anandology commented Nov 10, 2010

Fixed unicode error in generating debugerror (closed by fdda96d).

The web.net.websafe function works on strings, not on unicode. I wrote a
unicode version of that in template.py. Using that as filter for debugerror
template fixed the problem.

@anandology anandology added a commit to anandology/webpy that referenced this issue May 3, 2011

@anandology anandology Fixed unicode error in generating debugerror (closes #26).
The web.net.websafe function works on strings, not on unicode. I wrote a
unicode version of that in template.py. Using that as filter for debugerror
template fixed the problem.
fdda96d

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment