forked from mailgyc/doudizhu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96d65db
commit 1e5fc9a
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,3 @@ htmlcov/ | |
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# personal file | ||
base.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
from tornado.escape import json_encode | ||
from tornado.web import RequestHandler | ||
|
||
from contrib.db import AsyncConnection | ||
|
||
|
||
class BaseHandler(RequestHandler): | ||
|
||
@property | ||
def db(self) -> AsyncConnection: | ||
return self.application.db | ||
|
||
@property | ||
def executor(self) -> ThreadPoolExecutor: | ||
return self.application.executor | ||
|
||
@property | ||
def client_ip(self): | ||
headers = self.request.headers | ||
return headers.get('X-Forwarded-For', headers.get('X-Real-Ip', self.request.remote_ip)) | ||
|
||
def data_received(self, chunk): | ||
pass | ||
|
||
def get_query_params(self, name, default=None, strip=True): | ||
if not hasattr(self, 'query_params'): | ||
query_params = json.loads(self.request.body.decode('utf-8')) | ||
setattr(self, 'query_params', query_params) | ||
return self.query_params.get(name, default) | ||
|
||
def get_current_user(self): | ||
return self.get_secure_cookie('user') | ||
|
||
def set_current_user(self, uid, username): | ||
info = { | ||
'uid': uid, | ||
'username': username, | ||
} | ||
self.set_secure_cookie('user', json_encode(info)) | ||
|
||
def on_finish(self): | ||
# self.session.flush() | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
PROJECT_DIR = os.path.dirname(BASE_DIR) | ||
|
||
STATIC_URL = '/static/' | ||
STATIC_ROOT = os.path.join(BASE_DIR, 'static') | ||
|
||
TEMPLATE_ROOT = os.path.join(BASE_DIR, 'templates') | ||
|
||
DEBUG = True | ||
|
||
PORT = 8080 |