Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if codes:
for code in codes.split(","):
code = code.split(";")[0]
for l in locale.get_supported_locales():
if code.lower() == l.split("_")[0]:
return locale.get(l)
return None
class BaseWebSocketHandler(WebSocketHandler):
""" Handles websocket connections """
_session = None
_memcached = None
io_loop = IOLoop.instance()
manager = EventManager.instance()
config = options # backward compatability
def check_origin(self, origin):
""" Parses the request's origin header """
try:
request_origin = urlparse(origin)
origin = urlparse(self.config.origin)
logging.debug(
"Checking request origin '%s' ends with '%s'" % (request_origin, origin)
)
return request_origin.netloc.endswith(origin)
except:
logging.exception("Failed to parse request origin: %r" % origin)
return False
def main():
tornado.options.parse_command_line()
app = Application()
app.listen(options.port)
print('Listening at port %s' % options.port)
tornado.ioloop.IOLoop.instance().start()
def run(port=PORT, public=PUBLIC):
global PORT
global PUBLIC
PORT = port
PUBLIC = public
print('serving directory %s on port %d' % (root_directory, PORT))
application.listen(port, None if public else "localhost")
try:
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print("bye!")
def main():
try:
tornado.options.parse_command_line()
application = tornado.web.Application([
(r'/', MainHandler),
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.bind(8888)
http_server.start(0) # Forks multiple sub-processes
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print('Exit')
)
options.parse_command_line()
opts = options.options
# regex from docker volume create
api_handlers = [
(r'/api/mounts(/([a-zA-Z0-9][a-zA-Z0-9_.-])+)?', MountsHandler),
(r'/api/volumes', VolumesHander),
]
api_app = web.Application(api_handlers)
api_app.listen(opts.port, opts.ip, xheaders=True)
app_log.info("Listening on {}:{}".format(opts.ip, opts.port))
ioloop.IOLoop.instance().start()
def build_ethernet_loop(alice_nic="tapa", bob_nic="tapb"):
alice_sock = attach(alice_nic)
bob_sock = attach(bob_nic)
def write_fn(sock):
def _fn(data):
return sock.send(data)
return _fn
io_loop = tornado.ioloop.IOLoop.instance()
alice_stream = tornado.iostream.IOStream(alice_sock)
bob_stream = tornado.iostream.IOStream(bob_sock)
link_layer = LinkLayer([alice_stream, bob_stream])
alice_cb = functools.partial(eth_callback, link_layer, 0)
bob_cb = functools.partial(eth_callback, link_layer, 1)
io_loop.add_handler(alice_sock.fileno(), alice_cb, io_loop.READ)
io_loop.add_handler(bob_sock.fileno(), bob_cb, io_loop.READ)
return io_loop, link_layer
def start(handlers):
template_dir = os.path.abspath(os.path.join(os.path.dirname(__main__.__file__), "templates"))
if not os.path.isdir(template_dir):
os.makedirs(template_dir)
static_dir = os.path.abspath(os.path.join(os.path.dirname(__main__.__file__), "static"))
if not os.path.isdir(static_dir):
os.makedirs(static_dir)
tornado.options.logging = "none"
ssl_options = None
if 'ssl_options' in config['tornado']:
ssl_options = {'certfile': config['tornado']['ssl_options']['certfile'], 'keyfile': config['tornado']['ssl_options']['keyfile']}
log.info("Starting tornado server on port %s" % config['tornado']['port'])
http_server = tornado.httpserver.HTTPServer(Application(handlers), ssl_options=ssl_options, xheaders=True)
http_server.listen(config['tornado']['port'])
tornado.ioloop.IOLoop.instance().start()
def _handle_response(response):
print response.request.url, response.code, response.error
if response.code == 200 and response.error is None:
results[(http_request.proxy_host, http_request.proxy_port)]['success'] += 1
else:
results[(http_request.proxy_host, http_request.proxy_port)]['fail'] += 1
counters['current_client'] -= 1
# 访问网页
counters['current_client'] += 1
try:
client.fetch(http_request, callback=_handle_response)
except Exception, e:
print e
# 加入下一次循环
ioloop.IOLoop.instance().add_timeout(
datetime.timedelta(milliseconds=interval), _fetch)
# 当最大并发度已经饱和了
else:
ioloop.IOLoop.instance().add_timeout(
datetime.timedelta(milliseconds=interval), _fetch)
else:
print counters['current_client']
if counters['current_client'] > 0:
ioloop.IOLoop.instance().add_timeout(
datetime.timedelta(milliseconds=interval), _fetch)
else:
ioloop.IOLoop.instance().stop()
def run_server():
from tornado.log import enable_pretty_logging
enable_pretty_logging()
application = tornado.web.Application([
(r"/", MainHandler),
])
application.listen(8888)
logging.info('starting server at 8888')
tornado.ioloop.IOLoop.instance().start()
cfg = Config(args.config_file)
c = redis.StrictRedis(host=args.redis_host, port=args.redis_port, db=args.redis_db, password=args.redis_pass)
logging.basicConfig(level=getattr(logging, args.loglevel.upper()))
application = R3ServiceApp(redis=c, config=cfg, log_level=args.loglevel.upper(), debug=args.debug, show_index_page=not args.hide_index_page)
server = HTTPServer(application)
server.bind(args.port, args.bind)
server.start(1)
try:
logging.debug('r³ service app running at %s:%d' % (args.bind, args.port))
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print
print "-- r³ service app closed by user interruption --"