New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if chinese directory path,SimpleTemplate Faied. #552

Open
D-L opened this Issue Sep 29, 2013 · 0 comments

Comments

Projects
None yet
1 participant
@D-L

D-L commented Sep 29, 2013

directory path contain any chinese word,when launch the bottle server.
it's crushed. Error: 500 Internal Server Error

this directory views:

中文
  ├── bottle.py    latest version
  ├── test.py
  └── views
     ├── foot.tpl
     └── home.tpl

== test.py ==

#!/usr/bin/env python2
#coding: utf8
from bottle import get,run,template
@get("/")
def test():
    return template("home")
if __name__=="__main__":
    host='127.0.0.1'
    port=8080
    run(host=host,port=port)

== home.tpl ==

<!doctype html>
<html>
    <head>  
        <meta charset="utf-8">
        <title>test Chinese dir path</title>
    </head>
    <body>
        test chinese path!
        %include foot
    </body>
</html>

== foot.tpl ==

<p>we @ foot</p>

== error msg ==

Traceback (most recent call last):
  File "/home/david/test/中文/bottle.py", line 861, in _handle
    return route.call(**args)
  File "/home/david/test/中文/bottle.py", line 1725, in wrapper
    rv = callback(*a, **ka)
  File "./test.py", line 7, in test
    return template("home")
  File "/home/david/test/中文/bottle.py", line 3465, in template
    return TEMPLATES[tplid].render(kwargs)
  File "/home/david/test/中文/bottle.py", line 3273, in render
    self.execute(stdout, env)
  File "/home/david/test/中文/bottle.py", line 3260, in execute
    eval(self.co, env)
  File "/home/david/test/中文/views/home.tpl", line 9, in <module>
    %include foot
  File "/home/david/test/中文/bottle.py", line 3249, in _include
    self.cache[_name] = self.__class__(name=_name, lookup=self.lookup)
  File "/home/david/test/中文/bottle.py", line 3088, in __init__
    self.filename = self.search(self.name, self.lookup)
  File "/home/david/test/中文/bottle.py", line 3109, in search
    fname = os.path.abspath(os.path.join(spath, name))
  File "/home/david/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/posixpath.py", line 69, in join
    path +=  b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 17: ordinal not in range(128)

=== solution? ===
i change the line 3088

  self.filename = self.search(self.name, self.lookup)

to:

  self.filename = self.search(tob(self.name,encoding), self.lookup)

Looks fixed.

test case @: https://www.dropbox.com/s/njf0un7i96aqjhv/chinesepath.tar.gz

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