Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

small documentation updates

  • Loading branch information...
commit 81d9767f3dfd6a6ded3774e46ce23ef0426699d2 1 parent 130cc49
@Falicon authored
Showing with 38 additions and 38 deletions.
  1. +1 −1  README
  2. +37 −37 app/basic.py
View
2  README
@@ -1,4 +1,4 @@
-This is a base tornado framework derived from the way bit.ly use to use Tornado.
+This is a base Python tornado framework implementation.
Running:
View
74 app/basic.py
@@ -1,37 +1,37 @@
-import tornado.web
-
-import simplejson as json
-
-class BaseHandler(tornado.web.RequestHandler):
-
- def get_current_user(self):
- return self.get_secure_cookie("character")
-
- def api_response(self, data):
- # return an api response in the proper output format with status_code == 200
- self.write_api_response(data, 200, "OK")
-
- def error(self, status_code, status_txt, data=None):
- # return an api error in the proper output format
- self.write_api_response(status_code=status_code, status_txt=status_txt, data=data)
-
- def write_api_response(self, data, status_code, status_txt):
- # return an api error based on the appropriate request format (ie: json/xml)
- format = self.get_argument('format', 'json')
- callback = self.get_argument('callback', None)
- if format not in ["json"]:
- status_code = 500
- status_txt = "INVALID_ARG_FORMAT"
- data = None
- format = "json"
- response = {'status_code':status_code, 'status_txt':status_txt, 'data':data}
-
- if format == "json":
- data = json.dumps(response)
- if callback:
- self.set_header("Content-Type", "application/javascript; charset=utf-8")
- self.write('%s(%s)' % (callback, data))
- else:
- self.set_header("Content-Type", "application/json; charset=utf-8")
- self.write(data)
- self.finish()
+import tornado.web
+
+import simplejson as json
+
+class BaseHandler(tornado.web.RequestHandler):
+
+ def get_current_user(self):
+ return self.get_secure_cookie("character")
+
+ def api_response(self, data):
+ # return an api response in the proper output format with status_code == 200
+ self.write_api_response(data, 200, "OK")
+
+ def error(self, status_code, status_txt, data=None):
+ # return an api error in the proper output format
+ self.write_api_response(status_code=status_code, status_txt=status_txt, data=data)
+
+ def write_api_response(self, data, status_code, status_txt):
+ # return an api error based on the appropriate request format (ie: json)
+ format = self.get_argument('format', 'json')
+ callback = self.get_argument('callback', None)
+ if format not in ["json"]:
+ status_code = 500
+ status_txt = "INVALID_ARG_FORMAT"
+ data = None
+ format = "json"
+ response = {'status_code':status_code, 'status_txt':status_txt, 'data':data}
+
+ if format == "json":
+ data = json.dumps(response)
+ if callback:
+ self.set_header("Content-Type", "application/javascript; charset=utf-8")
+ self.write('%s(%s)' % (callback, data))
+ else:
+ self.set_header("Content-Type", "application/json; charset=utf-8")
+ self.write(data)
+ self.finish()
Please sign in to comment.
Something went wrong with that request. Please try again.