更新代码

main
周平 10 months ago
parent baef5ee8a9
commit 6931e7914e

@ -10,12 +10,12 @@ import tornado.ioloop
import tornado.options
import tornado.web
# import tornado.websocket
import torndb
# import torndb
import importlib
# from confluent_kafka import Producer
# from rediscluster import StrictRedisCluster
# from redis import sentinel
from rediscluster import RedisCluster
# from rediscluster import RedisCluster
# from redis.sentinel import Sentinel
# from tornado.options import define, options
from tornado.options import options, define as _define, parse_command_line
@ -59,54 +59,54 @@ from website.urls import handlers, page_handlers
# from website.urls import handlers_v2
# print(os.path.dirname(os.path.abspath(__file__)))
class Connection(torndb.Connection):
def __init__(self,
host,
database,
user=None,
password=None,
max_idle_time=7 * 3600,
connect_timeout=500,
time_zone="+0:00"):
self.host = host
self.database = database
self.max_idle_time = float(max_idle_time)
args = dict(conv=torndb.CONVERSIONS,
use_unicode=True,
charset="utf8",
db=database,
init_command=('SET time_zone = "%s";' %
time_zone),
connect_timeout=connect_timeout,
sql_mode="TRADITIONAL")
if user is not None:
args["user"] = user
if password is not None:
args["passwd"] = password
# We accept a path to a MySQL socket file or a host(:port) string
if "/" in host:
args["unix_socket"] = host
else:
self.socket = None
pair = host.split(":")
if len(pair) == 2:
args["host"] = pair[0]
args["port"] = int(pair[1])
else:
args["host"] = host
args["port"] = 3306
self._db = None
self._db_args = args
self._last_use_time = time.time()
try:
self.reconnect()
except Exception:
logging.error("Cannot connect to MySQL on %s",
self.host,
exc_info=True)
# class Connection(torndb.Connection):
# def __init__(self,
# host,
# database,
# user=None,
# password=None,
# max_idle_time=7 * 3600,
# connect_timeout=500,
# time_zone="+0:00"):
# self.host = host
# self.database = database
# self.max_idle_time = float(max_idle_time)
#
# args = dict(conv=torndb.CONVERSIONS,
# use_unicode=True,
# charset="utf8",
# db=database,
# init_command=('SET time_zone = "%s";' %
# time_zone),
# connect_timeout=connect_timeout,
# sql_mode="TRADITIONAL")
# if user is not None:
# args["user"] = user
# if password is not None:
# args["passwd"] = password
#
# # We accept a path to a MySQL socket file or a host(:port) string
# if "/" in host:
# args["unix_socket"] = host
# else:
# self.socket = None
# pair = host.split(":")
# if len(pair) == 2:
# args["host"] = pair[0]
# args["port"] = int(pair[1])
# else:
# args["host"] = host
# args["port"] = 3306
#
# self._db = None
# self._db_args = args
# self._last_use_time = time.time()
# try:
# self.reconnect()
# except Exception:
# logging.error("Cannot connect to MySQL on %s",
# self.host,
# exc_info=True)
# class NoCacheStaticFileHandler(tornado.web.StaticFileHandler):
@ -158,11 +158,12 @@ class Application(tornado.web.Application):
# self.r_app = rs.master_for(settings.redis_sentinel_master,
# socket_timeout=0.1,
# password=settings.redis_sentinel_pwd)
if settings.redis_cluster == 1:
self.r_app = RedisCluster(startup_nodes=settings.redis_app_cluster_notes, decode_responses=True,
password=settings.redis_cluster_pwd)
else:
self.r_app = redis.Redis(*settings.redis_app, decode_responses=True)
# if settings.redis_cluster == 1:
# self.r_app = RedisCluster(startup_nodes=settings.redis_app_cluster_notes, decode_responses=True,
# password=settings.redis_cluster_pwd)
# else:
# self.r_app = redis.Redis(*settings.redis_app, decode_responses=True)
self.r_app = redis.Redis(*settings.redis_app, decode_responses=True)
# self.r_app = redis.Redis(*settings.redis_app)
# self.kafka_producer = Producer(**settings.kafka_conf)

@ -20,12 +20,13 @@ from tornado.httpclient import AsyncHTTPClient, HTTPRequest
from tornado.options import options
# from tornado.web import RequestHandler as BaseRequestHandler, HTTPError, asynchronous
from tornado.web import RequestHandler as BaseRequestHandler, HTTPError
from torndb import Row
from website import errors
from website import settings
from website.service.license import get_license_status
# from torndb import Row
if settings.enable_curl_async_http_client:
AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
else:
@ -34,6 +35,16 @@ else:
REMOVE_SLASH_RE = re.compile(".+/$")
class Row(dict):
"""A dict that allows for object-like property access syntax."""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
def _callback_wrapper(callback):
"""A wrapper to handling basic callback error"""

@ -44,7 +44,10 @@ class LicenseUploadHandler(APIHandler):
file = file_metas[0]
filename = file.filename
punctuation = """!"#$%&'()*+,/:;<=>?@[\]^`{|}~ """
# punctuation = """!"#$%&'()*+,/:;<=>?@[\]^`{|}~ """
# punctuation = """!"#$%&'()*+,/:;<=>?@[\\]^`{|}~ """
punctuation = r"""!"#$%&'()*+,/:;<=>?@[\]^`{|}~ """
regex = re.compile('[%s]' % re.escape(punctuation))
filename = regex.sub("", filename.replace('..', ''))
file_size = len(file.body)

@ -171,13 +171,13 @@ class LoginHandler(APIHandler):
class UserInfoHandler(APIHandler):
def post(self):
token = self.get_argument("token")
user = self.get_current_user(token_body=self.tostr(token))
# token = self.get_argument("token")
# user = self.get_current_user(token_body=self.tostr(token))
user = self.get_current_user()
if not user:
raise errors.HTTPAPIError(errors.ERROR_UNAUTHORIZED)
self.finish({"name": user.name, "role": user.role})
self.finish({"name": user.name, "avtar": ""})
class UserListHandler(APIHandler):
@authenticated

@ -8,6 +8,7 @@ handlers = [
# ("/user/info", handler.UserInfoHandler),
("/login", handler.LoginHandler),
("/logout", handler.LogoutHandler),
("/user/info", handler.UserInfoHandler),
("/users", handler.UserListHandler),
]

Loading…
Cancel
Save