Permalink
Browse files

tornado works for dir / file

  • Loading branch information...
1 parent 8eb8da3 commit c21c095f6050bd16c4ee6a40accc4cf634c6b479 @alswl committed Jul 4, 2014
View
@@ -0,0 +1,41 @@
+# coding=utf-8
+
+import tornado.ioloop
+import tornado.web
+
+from handlers import dir, file
+import settings
+
+
+re_safe_name_with_slash = ur'[ \w\u2e80-\u9fff\-_\.,/]'
+
+
+class MainHandler(tornado.web.RequestHandler):
+ def get(self):
+ self.write("Hello, world")
+
+
+application = tornado.web.Application([
+ (r'/_admin/', MainHandler),
+ (r'/_admin/login', MainHandler),
+ (r'/_admin/logout', MainHandler),
+ (r'/_admin/upload', MainHandler),
+ (r'/_admin/mkdir', MainHandler),
+ (r'/_admin/delete', MainHandler),
+ (r'/()', dir.DirHandler),
+ (r'/(%s+/)' % re_safe_name_with_slash, dir.DirHandler),
+ (r'/(%s+)' % re_safe_name_with_slash, tornado.web.StaticFileHandler, {'path': settings.UPLOAD_PATH}),
+])
+
+
+if __name__ == "__main__":
+ print """Kuku Start Work!
+ _ __ _ __
+| | / / | | / /
+| |/ / _ _| |/ / _ _
+| \| | | | \| | | |
+| |\ \ |_| | |\ \ |_| |
+\_| \_/\__,_\_| \_/\__,_|
+ """
+ application.listen(8888)
+ tornado.ioloop.IOLoop.instance().start()
No changes.
View
No changes.
View
@@ -0,0 +1 @@
+
View
@@ -0,0 +1,28 @@
+# coding=utf-8
+
+import os
+
+import tornado.ioloop
+import tornado.web
+
+import settings
+
+
+class DirHandler(tornado.web.RequestHandler):
+
+ def get(self, path):
+ abs_path = os.path.abspath(os.path.join(settings.UPLOAD_PATH, path))
+ if settings.UPLOAD_PATH not in abs_path:
+ raise tornado.web.HTTPError(404)
+
+ dirs = []
+ files = []
+ l = os.listdir(abs_path)
+ for f in l:
+ if os.path.isdir(os.path.join(abs_path, f)):
+ dirs.append(f)
+ else:
+ files.append(f)
+
+ self.write(','.join(dirs) + '; ' + ','.join(files))
+
View
@@ -0,0 +1,13 @@
+# coding=utf-8
+
+import os
+
+import tornado.ioloop
+import tornado.web
+
+
+class FileHandler(tornado.web.RequestHandler):
+
+ def get(self):
+ self.write('file')
+
View
@@ -0,0 +1,21 @@
+# coding=utf-8
+
+import os
+
+DEBUG = True
+
+ADMIN = 'alswl'
+PASSWORD = '123456'
+
+ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
+TEMPLATES_PATH = os.path.abspath(os.path.join(ROOT_PATH, 'templates'))
+UPLOAD_PATH = os.path.abspath(os.path.join(ROOT_PATH, '..', 'upload'))
+
+MAX_FILE_SIZE = 5 * 1024 * 1024 # 3 * 1024 * 1024 bytes
+ALLOWED_EXTENSIONS = ['jpg', 'png', 'gif', 'zip', 'rar', 'gz']
+
+#DEFAULT_DIR_MODE = '755'
+#DEFAULT_FILE_MODE = '644'
+
+#NOT_ALLOWD_NAME = ['admin']
+

0 comments on commit c21c095

Please sign in to comment.