1. Andrey Vlasovskikh
  2. obraz

Commits

Andrey Vlasovskikh  committed 4b546e0

Fixed Unicode URL handling

  • Participants
  • Parent commits f1462dd
  • Branches default

Comments (0)

Files changed (1)

File obraz.py

View file
 from docopt import docopt
 
 
-PAGE_ENCODING = 'UTF-8'
+PAGE_ENCODING = URL_ENCODING = 'UTF-8'
+PY2 = sys.version_info < (3,)
 
 _quiet = False
 _loaders = []
     m = re.match(r'(.*)[/\\]index.html?$', path)
     if m:
         path = m.group(1) + os.path.sep
-    return pathname2url(os.path.sep + path)
+    path = os.path.sep + path
+    url = pathname2url(path.encode(URL_ENCODING))
+    return url.decode('ASCII') if PY2 else url
 
 
 def url2path(url):
     if url.endswith('/'):
         url += 'index.html'
-    return url2pathname(url).lstrip(os.path.sep)
+    path = url2pathname(url.encode('ASCII') if PY2 else url)
+    return (path.decode(URL_ENCODING) if PY2 else path).lstrip(os.path.sep)
 
 
 def make_dirs(path):