Last active
August 29, 2015 14:08
-
-
Save abdelouahabb/1557c0bb9db59a8d5b17 to your computer and use it in GitHub Desktop.
This is a gist how to use unicode as Tornado URLS (here i used arabic char)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding: utf-8 | |
import tornado.ioloop | |
import tornado.web | |
import tornado.escape | |
#import urllib2 old way | |
arabic_word = u'السلام' | |
arab = tornado.escape.url_escape(arabic_word) | |
#arab = urllib2.quote(arabic_word.encode('utf8')) old way | |
# it will return '%D8%A7%D9%84%D8%B3%D9%84%D8%A7%D9%85' | |
# this is what is called url escaping, in javascript you use encodeURI('السلام') | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("السلام عليكم") | |
application = tornado.web.Application([ | |
(r"/{0}".format(arab), MainHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8000) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment