本文整理汇总了Python中tornado.options.port方法的典型用法代码示例。如果您正苦于以下问题:Python options.port方法的具体用法?Python options.port怎么用?Python options.port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.options
的用法示例。
在下文中一共展示了options.port方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_httpserver
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def load_httpserver(self, sockets=None, **kwargs):
if not sockets:
from tornado.netutil import bind_sockets
if settings.IPV4_ONLY:
import socket
sockets = bind_sockets(options.port, options.address, family=socket.AF_INET)
else:
sockets = bind_sockets(options.port, options.address)
http_server = tornado.httpserver.HTTPServer(self.application, **kwargs)
http_server.add_sockets(sockets)
self.httpserver = http_server
return self.httpserver
示例2: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
logging.basicConfig(level=logging.DEBUG, format="%(levelname)8s %(asctime)s %(message)s ")
logging.debug('Starting up server')
from tornado.options import define, options
define("certfile", default="", help="certificate file for secured SSL connection")
define("keyfile", default="", help="key file for secured SSL connection")
tornado.options.parse_command_line()
app = Application()
if options.certfile and options.keyfile:
ssl_options = {
"certfile": options.certfile,
"keyfile": options.keyfile,
}
logging.info("Using SSL for serving requests")
app.listen(options.port, ssl_options=ssl_options)
else:
app.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
示例3: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
tornado.options.parse_command_line()
# Create the global connection pool.
async with aiopg.create_pool(
host=options.db_host,
port=options.db_port,
user=options.db_user,
password=options.db_password,
dbname=options.db_database,
) as db:
await maybe_create_tables(db)
app = Application(db)
app.listen(options.port)
# In this demo the server will simply run until interrupted
# with Ctrl-C, but if you want to shut down more gracefully,
# call shutdown_event.set().
shutdown_event = tornado.locks.Event()
await shutdown_event.wait()
示例4: get
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def get(self, input):
try:
r = redis.StrictRedis(host='127.0.0.1', port=8323)
except:
print "Unable to connect to the Redis server"
sys.exit(255)
fp = input.lower()
if not checksha1(value=fp):
self.clear()
self.set_status(400)
self.finish('Incorrect format of the certificate fingerprint (expected SHA1 in hex format)')
out = {}
out['certificate'] = fp
out['seen'] = []
ips = r.smembers('s:{}'.format(fp))
out['hits'] = len(ips)
for ip in ips:
out['seen'].append(ip)
if not self._finished:
self.set_header('Content-Type', 'application/json')
self.set_header('Server', servername)
self.write(json.dumps(out))
示例5: run_request
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def run_request(self, q):
try:
r = redis.StrictRedis(host='127.0.0.1', port=8323)
except:
print("Unable to connect to the Redis server")
sys.exit(255)
fp = q.lower()
if not checksha1(value=fp):
self.clear()
self.set_status(400)
self.finish('Incorrect format of the certificate fingerprint (expected SHA1 in hex format)')
out = {}
out['certificate'] = fp
out['seen'] = []
ips = r.smembers('s:{}'.format(fp))
out['hits'] = len(ips)
for ip in ips:
out['seen'].append(ip)
if not self._finished:
self.set_header('Content-Type', 'application/json')
self.set_header('Server', servername)
return json.dumps(out)
示例6: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
tornado.options.parse_command_line()
app = Application()
app.listen(options.port)
tornado.ioloop.IOLoop.current().start()
示例7: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([
(r"/", MainHandler),
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.current().start()
示例8: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.current().start()
示例9: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
tornado.options.parse_command_line()
if not (options.facebook_api_key and options.facebook_secret):
print("--facebook_api_key and --facebook_secret must be set")
return
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.current().start()
示例10: get
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def get(self):
connect = MySQLdb.connect(user='root',
passwd='',
db='test',
host='localhost',
port=3306,
charset='utf8')
cursor = connect.cursor()
cursor.execute('SELECT * FROM app_blog LIMIT 1')
result = cursor.fetchone()
cursor.close()
connect.close()
self.finish(u'<p>{}</p><p>{}</p>'.format(result[1], result[2]))
示例11: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([(r"/", MainHandler),
(r"/pool/", ConnectionPoolHandler)],
debug=True)
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
示例12: main
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def main():
# 该方法会将根日志的级别设置为INFO
tornado.options.parse_command_line()
# 将日志的级别重新设置为LOGGING_LEVEL指定的级别
logger.setLevel(config.LOGGING_LEVEL)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
logger.info('tornado server is running on %s' % options.port)
tornado.ioloop.IOLoop.instance().start()
示例13: print_settings_info
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def print_settings_info(self):
if settings.DEBUG:
print('tornado version: %s' % tornado.version)
print('locale support: %s' % settings.TRANSLATIONS)
print('load apps:')
for app in settings.INSTALLED_APPS:
print(' - %s' % str(app))
print('template engine: %s' % (settings.TEMPLATE_CONFIG.template_engine or 'default'))
print('server started. development server at http://%s:%s/' % (options.address, options.port))
示例14: parse_logger_callback
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def parse_logger_callback(self):
if options.disable_log:
options.logging = None
if options.log_file_prefix and options.log_port_prefix:
options.log_file_prefix += ".%s" % options.port
if options.log_patch:
logging.handlers.TimedRotatingFileHandler = ProcessLogTimedFileHandler
tornado_logger = logging.getLogger('tornado')
enable_pretty_logging(logger=tornado_logger)
logdir = options.logging_dir or settings.LOGGING_DIR
for log in settings.LOGGING:
opt = OptionParser()
define_logging_options(opt)
self.define(opt)
opt.log_rotate_when = log.get('when', 'midnight')
opt.log_to_stderr = log.get('log_to_stderr', False) if options.log_to_stderr is None else options.log_to_stderr
opt.logging = log.get('level', 'INFO')
opt.log_file_prefix = os.path.join(logdir, log['filename'])
if log.get('backups'):
opt.log_file_num_backups = log.get('backups')
if opt.log_port_prefix:
opt.log_file_prefix += ".%s" % options.port
opt.log_rotate_interval = log.get('interval', 1)
opt.log_rotate_mode = 'time'
logger = logging.getLogger(log['name'])
logger.propagate = 0
enable_pretty_logging(options=opt, logger=logger)
map(lambda h: h.setFormatter(LogFormatter(fmt=log.get("formatter", LogFormatter.DEFAULT_FORMAT),
color=settings.DEBUG)), logger.handlers)
示例15: define
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import port [as 别名]
def define(self, options=options):
"""
定义命令行参数,你可以自定义很多自己的命令行参数,或重写此方法覆盖默认参数
:return:
"""
try:
# 增加timerotating日志配置
options.define("log_rotate_when", type=str, default='midnight',
help=("specify the type of TimedRotatingFileHandler interval "
"other options:('S', 'M', 'H', 'D', 'W0'-'W6')"))
options.define("log_rotate_interval", type=int, default=1,
help="The interval value of timed rotating")
options.define("log_rotate_mode", type=str, default='time',
help="The mode of rotating files(time or size)")
except:
pass
options.define("port", default=8000, help="run server on it", type=int)
options.define("settings", default='', help="setting module name", type=str)
options.define("address", default='0.0.0.0', help='listen host,default:0.0.0.0', type=str)
options.define("log_patch", default=True,
help='Use ProcessTimedRotatingFileHandler instead of the default TimedRotatingFileHandler.',
type=bool)
options.define("log_port_prefix", default=None, help='add port to log file prefix.', type=bool)
options.define("logging_dir", default='', help='custom log dir.')
options.define("disable_log", default=True, help='disable tornado log function.')