Python tornado.options.options.port() Examples
The following are 30
code examples of tornado.options.options.port().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.options.options
, or try the search function
.
Example #1
Source File: ip-ssl-subject-api.py From crl-monitor with GNU General Public License v3.0 | 6 votes |
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))
Example #2
Source File: twitterdemo.py From tornado-zh with MIT License | 6 votes |
def main(): parse_command_line(final=False) parse_config_file(options.config_file) app = Application( [ ('/', MainHandler), ('/login', LoginHandler), ('/logout', LogoutHandler), ], login_url='/login', **options.group_dict('application')) app.listen(options.port) logging.info('Listening on http://localhost:%d' % options.port) IOLoop.current().start()
Example #3
Source File: webserver.py From torngas with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #4
Source File: chatdemo.py From tornado-zh with MIT License | 6 votes |
def main(): parse_command_line() app = tornado.web.Application( [ (r"/", MainHandler), (r"/a/message/new", MessageNewHandler), (r"/a/message/updates", MessageUpdatesHandler), ], cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__", template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), xsrf_cookies=True, debug=options.debug, ) app.listen(options.port) tornado.ioloop.IOLoop.current().start()
Example #5
Source File: chunk_benchmark.py From tornado-zh with MIT License | 6 votes |
def main(): parse_command_line() app = Application([('/', ChunkHandler)]) app.listen(options.port, address='127.0.0.1') def callback(response): response.rethrow() assert len(response.body) == (options.num_chunks * options.chunk_size) logging.warning("fetch completed in %s seconds", response.request_time) IOLoop.current().stop() logging.warning("Starting fetch with curl client") curl_client = CurlAsyncHTTPClient() curl_client.fetch('http://localhost:%d/' % options.port, callback=callback) IOLoop.current().start() logging.warning("Starting fetch with simple client") simple_client = SimpleAsyncHTTPClient() simple_client.fetch('http://localhost:%d/' % options.port, callback=callback) IOLoop.current().start()
Example #6
Source File: bast.py From Bast with MIT License | 6 votes |
def run(self): """ Function to Run the server. Server runs on host: 127.0.0.1 and port: 2000 by default. Debug is also set to false by default Can be overriden by using the config.ini file """ define("port", default=self.port, help="Run on given port", type=int) define("host", default=self.host, help="Run on given host", type=str) define("debug", default=self.debug, help="True for development", type=bool) parse_command_line() print(Fore.GREEN + "Starting Bast Server....") print(Fore.GREEN + "Bast Server Running on %s:%s" % (options.host, options.port)) application = Application(self.handler, debug=options.debug) server = HTTPServer(application) server.listen(options.port, options.host) IOLoop.current().start()
Example #7
Source File: master_server.py From kaldi-gstreamer-server with BSD 2-Clause "Simplified" License | 6 votes |
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()
Example #8
Source File: chunk_benchmark.py From honeything with GNU General Public License v3.0 | 6 votes |
def main(): parse_command_line() app = Application([('/', ChunkHandler)]) app.listen(options.port, address='127.0.0.1') def callback(response): response.rethrow() assert len(response.body) == (options.num_chunks * options.chunk_size) logging.warning("fetch completed in %s seconds", response.request_time) IOLoop.instance().stop() logging.warning("Starting fetch with curl client") curl_client = CurlAsyncHTTPClient() curl_client.fetch('http://localhost:%d/' % options.port, callback=callback) IOLoop.instance().start() logging.warning("Starting fetch with simple client") simple_client = SimpleAsyncHTTPClient() simple_client.fetch('http://localhost:%d/' % options.port, callback=callback) IOLoop.instance().start()
Example #9
Source File: server.py From politicos with GNU Affero General Public License v3.0 | 6 votes |
def main(): app = Application() app.listen(options.port) loop = asyncio.get_event_loop() app.init_with_loop(loop) enable_pretty_logging() if options.debug: env = 'development' else: env = 'production' print(f'Starting {env} server at http://localhost:{options.port}/') print('Quit the server with CONTROL-C.') loop.run_forever()
Example #10
Source File: blog.py From trace-examples with BSD 3-Clause "New" or "Revised" License | 6 votes |
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()
Example #11
Source File: run_tornado.py From django-tornado with MIT License | 6 votes |
def main(): os.environ['DJANGO_SETTINGS_MODULE'] = 'demosite.settings' # TODO: edit this sys.path.append('./demosite') # path to your project if needed parse_command_line() wsgi_app = get_wsgi_application() container = tornado.wsgi.WSGIContainer(wsgi_app) tornado_app = tornado.web.Application( [ ('/hello-tornado', HelloHandler), ('.*', tornado.web.FallbackHandler, dict(fallback=container)), ]) server = tornado.httpserver.HTTPServer(tornado_app) server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #12
Source File: application.py From k8sMG with GNU General Public License v3.0 | 6 votes |
def start_server(self): """ 启动 tornado 服务 :return: """ try: ins_log.read_log('info', 'progressid: %(progid)s' % dict(progid=options.progid)) ins_log.read_log('info', 'server address: %(addr)s:%(port)d' % dict(addr=options.addr, port=options.port)) ins_log.read_log('info', 'web server start sucessfuled.') self.io_loop.start() except KeyboardInterrupt: self.io_loop.stop() except: import traceback ins_log.read_log('error', '%(tra)s'% dict(tra=traceback.format_exc())) #Logger.error(traceback.format_exc())
Example #13
Source File: webserver.py From Scanver with Apache License 2.0 | 6 votes |
def _portlistget_action(self,data): '''获取主机对应端口''' hostid = data.get('hostid') MH = models.HostResult MR = models.PortResult RH = MH.get() query = MR.select().join(MH).where(MH.host_id == hostid).order_by(MR.port) ret = [] for RP in query: ret.append({ 'port' : str(RP.port), 'service' : str(RP.service_name), 'softname' : str(RP.soft_name), 'softtype' : str(RP.soft_type), 'softver' : str(RP.soft_ver), 'note' : str(RP.response), }) return ret
Example #14
Source File: webserver.py From Scanver with Apache License 2.0 | 6 votes |
def _portedit_action(self,data): '''端口资料更新''' hostid = data.get('hostid') port = data.get('port') MH = models.HostResult MP = models.PortResult RH = MH.get(MH.host_id == hostid) try: R = MP.get(MP.hostid == RH, MP.port == port) except MP.DoesNotExist: R = MP() R.host = RH R.host_ip = RH.host_ip R.port = port R.service_name = data.get('service') R.soft_name = data.get('softname') R.soft_type = data.get('softtype') R.soft_ver = data.get('softver') R.response = data.get('note') R.updatedate = datetime.datetime.now() R.save() return str(R.port)
Example #15
Source File: main.py From autoops with Apache License 2.0 | 6 votes |
def main(): settings = { 'template_path': os.path.join(base_dir, 'templates'), 'static_path': os.path.join(base_dir, '../static/webssh_static'), # 'cookie_secret': uuid.uuid1().hex, # 'xsrf_cookies': True, 'debug': True } handlers = [ (r'/', IndexHandler), (r'/ws', WsockHandler) ] parse_command_line() app = tornado.web.Application(handlers, **settings) app.listen(options.port, options.address) logging.info('Listening on {}:{}'.format(options.address, options.port)) IOLoop.current().start()
Example #16
Source File: fake-registration-server.py From tuya-convert with MIT License | 6 votes |
def main(): parse_command_line() get_file_stats('../files/upgrade.bin') app = tornado.web.Application( [ (r"/", MainHandler), (r"/gw.json", JSONHandler), (r"/d.json", JSONHandler), ('/files/(.*)', FilesHandler, {'path': str('../files/')}), (r".*", tornado.web.RedirectHandler, {"url": "http://" + options.addr + "/", "permanent": False}), ], #template_path=os.path.join(os.path.dirname(__file__), "templates"), #static_path=os.path.join(os.path.dirname(__file__), "static"), debug=options.debug, ) try: app.listen(options.port, options.addr) print("Listening on " + options.addr + ":" + str(options.port)) tornado.ioloop.IOLoop.current().start() except OSError as err: print("Could not start server on port " + str(options.port)) if err.errno == 98: # EADDRINUSE print("Close the process on this port and try again") else: print(err)
Example #17
Source File: main.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 6 votes |
def main(first): #if os.fork() != 0: # exit() if str(first) == 'duo': freeze_support() print("Quit the server with CONTROL-C.") app = application http_server = tornado.httpserver.HTTPServer(app) http_server.bind(options.port) http_server.start(num_processes = 8) tornado.ioloop.IOLoop.instance().start() elif str(first) == 'dan': app = application app.listen(options.port) print ("Starting development server at http://172.29.152.3:" + str(options.port) ) print ("Quit the server with CONTROL-C.") tornado.ioloop.IOLoop.instance().start() else: print ("error command: duo or dan?")
Example #18
Source File: init.py From RobotAIEngine with Apache License 2.0 | 6 votes |
def main(): ''' main 函数 ''' # 开启 search_engin_server ioloop = tornado.ioloop.IOLoop.instance() server = tornado.httpserver.HTTPServer(Application(), xheaders=True) server.listen(options.port) def sig_handler(sig, _): ''' 信号接收函数 ''' logging.warn("Caught signal: %s", sig) shutdown(ioloop, server) signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGINT, sig_handler) ioloop.start()
Example #19
Source File: main.py From adminset with GNU General Public License v2.0 | 5 votes |
def main(): options.parse_command_line() loop = tornado.ioloop.IOLoop.current() app = make_app(make_handlers(loop, options), get_app_settings(options)) ssl_ctx = get_ssl_context(options) server_settings = get_server_settings(options) app_listen(app, options.port, options.address, server_settings) if ssl_ctx: server_settings.update(ssl_options=ssl_ctx) app_listen(app, options.sslport, options.ssladdress, server_settings) loop.start()
Example #20
Source File: run.py From cookiecutter-tornado with GNU General Public License v3.0 | 5 votes |
def main(): parse_command_line() if options.config: parse_config_file(options.config) app = MainApplication() app.listen(options.port) tornado.ioloop.IOLoop.current().start()
Example #21
Source File: quickly_cmd.py From webspider with MIT License | 5 votes |
def run_web_app_by_gunicorn(): define(name='port', default=8000, type=int, help='run on the given port') logger.info( '\n================ spider web server(require gunicorn and gevent) has started ================ ') logger.info('\n server start at port -> {}, debug mode = {} '.format(options.port, constants.DEBUG)) os.system( "env/bin/gunicorn 'webspider.web_app:make_wsgi_app()' -b 0.0.0.0:{port} -w 1 -k gevent".format( port=options.port ) )
Example #22
Source File: webserver.py From torngas with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #23
Source File: app.py From listen1 with MIT License | 5 votes |
def main(): app = TornadoBoilerplate() http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #24
Source File: run_application.py From machine_learning_in_application with MIT License | 5 votes |
def main(): # tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) port = int(os.environ.get("PORT", options.port)) print("server is running on port {0}".format(port)) http_server.listen(port) tornado.ioloop.IOLoop.current().start()
Example #25
Source File: hello.py From greentor with MIT License | 5 votes |
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()
Example #26
Source File: application.py From k8sMG with GNU General Public License v3.0 | 5 votes |
def __init__(self, handlers=None, default_host="", transforms=None, **settings): #print('options.port=>>>',options.port) tnd_options.parse_command_line() #解析命令行 --port=9001 #print('options.port=>>>',options.port) Logger(options.progid) # Logger().init_logger(options.progid) super(Application, self).__init__(handlers, default_host, transforms, **settings) http_server = httpserver.HTTPServer(self) http_server.listen(options.port, address=options.addr) self.io_loop = ioloop.IOLoop.instance()
Example #27
Source File: hello.py From greentor with MIT License | 5 votes |
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]))
Example #28
Source File: webserver.py From Scanver with Apache License 2.0 | 5 votes |
def _portdatabypid_action(self,data): '''端口服务分布''' projectid = data.get('projectid') MU = models.User MP = models.Project MT = models.ScanTask MH = models.HostResult MR = models.PortResult RU = MU.get(MU.uid == self.session['userid']) sw = MP.project_user == RU if projectid: sw &= (MP.project_id == projectid) ret = {} ret['port'] = {} query_port = (MR .select(MR.port,models.orm.fn.Count(MR.port)) .group_by(MR.port) .join(MH) .switch(MP) .join(MP) .where(sw) ) for q in query_port: ret['port'][port] = str(q.count) return ret
Example #29
Source File: application.py From greentor with MIT License | 5 votes |
def main(): parse_command_line() wsgi_app = tornado.wsgi.WSGIContainer( django.core.handlers.wsgi.WSGIHandler()) urls = app.urls.urls + [('.*', tornado.web.FallbackHandler, dict( fallback=wsgi_app)), ] tornado_app = tornado.web.Application(urls, **tornado_settings) server = tornado.httpserver.HTTPServer(tornado_app) server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #30
Source File: websocket.py From jupyter-server-proxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): tornado.options.parse_command_line() app = Application() app.listen(options.port) tornado.ioloop.IOLoop.current().start()