Python tornado.options.port() Examples
The following are 28
code examples of tornado.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
, 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 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)
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: helloworld.py From honeything with GNU General Public License v3.0 | 5 votes |
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.instance().start()
Example #7
Source File: run_server.py From DevOpsCloud with GNU General Public License v2.0 | 5 votes |
def main(): from django.core.wsgi import get_wsgi_application import tornado.wsgi wsgi_app = get_wsgi_application() container = tornado.wsgi.WSGIContainer(wsgi_app) setting = { 'cookie_secret': 'DFksdfsasdfkasdfFKwlwfsdfsa1204mx', 'template_path': os.path.join(os.path.dirname(__file__), 'templates'), 'static_path': os.path.join(os.path.dirname(__file__), 'static'), 'debug': False, } tornado_app = tornado.web.Application( [ (r'/ws/monitor', MonitorHandler), (r'/ws/terminal', WebTerminalHandler), (r'/ws/kill', WebTerminalKillHandler), (r'/ws/exec', ExecHandler), (r"/static/(.*)", tornado.web.StaticFileHandler, dict(path=os.path.join(os.path.dirname(__file__), "static"))), ('.*', tornado.web.FallbackHandler, dict(fallback=container)), ], **setting) server = tornado.httpserver.HTTPServer(tornado_app) server.listen(options.port, address=IP) tornado.ioloop.IOLoop.instance().start()
Example #8
Source File: ip-ssl-subject-api.py From crl-monitor with GNU General Public License v3.0 | 5 votes |
def main(): tornado.options.parse_command_line() app = tornado.web.Application(handlers=[ (r"/query/(.*)", SSLQueryHandler), (r"/cquery/(.*)", CertificateQueryHandler), (r"/cfetch/(.*)", FetchCertificateHandler) ]) http_server = tornado.httpserver.HTTPServer(app) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #9
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()
Example #10
Source File: authdemo.py From honeything with GNU General Public License v3.0 | 5 votes |
def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #11
Source File: facebook.py From honeything with GNU General Public License v3.0 | 5 votes |
def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #12
Source File: blog.py From honeything with GNU General Public License v3.0 | 5 votes |
def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #13
Source File: chatdemo.py From tornado-zh with MIT License | 5 votes |
def main(): tornado.options.parse_command_line() app = Application() app.listen(options.port) tornado.ioloop.IOLoop.current().start()
Example #14
Source File: chatdemo.py From honeything with GNU General Public License v3.0 | 5 votes |
def main(): tornado.options.parse_command_line() app = Application() app.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #15
Source File: server.py From tornado-websocket-client-example with MIT License | 5 votes |
def main(): tornado.options.parse_command_line() app = Application() app.listen(options.port) tornado.ioloop.IOLoop.instance().start()
Example #16
Source File: webserver.py From torngas with BSD 3-Clause "New" or "Revised" License | 5 votes |
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.')
Example #17
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 #18
Source File: webserver.py From torngas with BSD 3-Clause "New" or "Revised" License | 5 votes |
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))
Example #19
Source File: proxy.py From web-proxy with GNU General Public License v2.0 | 5 votes |
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()
Example #20
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 #21
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 #22
Source File: facebook.py From tornado-zh with MIT License | 5 votes |
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()
Example #23
Source File: blog.py From tornado-zh with MIT License | 5 votes |
def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.current().start()
Example #24
Source File: helloworld.py From tornado-zh with MIT License | 5 votes |
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()
Example #25
Source File: helloworld.py From honeything with GNU General Public License v3.0 | 4 votes |
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.instance().start()
Example #26
Source File: ip-ssl-subject-api.py From crl-monitor with GNU General Public License v3.0 | 4 votes |
def get(self, input): try: #Redis structure Set of (FP) per IP r = redis.StrictRedis(host='127.0.0.1', port=8323) except: print "Unable to connect to the Redis server" sys.exit(255) subnets = [input] out = {} for subnet in subnets: if re.findall(r":", subnet): self.clear() self.set_status(400) self.finish('IPv6 is not (yet) supported') continue try: iplist = netaddr.IPNetwork(subnet) except: self.clear() self.set_status(400) self.finish('Incorrect format') continue if iplist.size > ipmaxsize: self.clear() self.set_status(400) self.finish('Maximum CIDR block size reached >/23') if not self._finished: self.finish() for ip in iplist: s = r.smembers(str(ip)) if s: out[str(ip)] = {} out[str(ip)]['certificates'] = [] out[str(ip)]['subjects'] = {} for fingerprint in s: subjects = r.smembers(fingerprint) out[str(ip)]['certificates'].append(fingerprint) if subjects: out[str(ip)]['subjects'][fingerprint] = {} out[str(ip)]['subjects'][fingerprint]['values'] = [] for subject in subjects: out[str(ip)]['subjects'][fingerprint]['values'].append(subject) if not self._finished: self.set_header('Content-Type', 'application/json') self.set_header('Server', servername) self.write(json.dumps(out))
Example #27
Source File: ip-ssl-subject-api.py From crl-monitor with GNU General Public License v3.0 | 4 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) #ICSI data try: ricsi = redis.StrictRedis(host='localhost', port=6380, db=5) except: print ("Unable to connect to the Redis ICSI notary server") 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)') certpath = bpath(ha=fp) certpath = os.path.join(certpath, fp) certpath = certrepo.format(certpath) if not os.path.exists(certpath): self.clear() self.set_status(400) self.finish('Not existing certificate') cert = M2Crypto.X509.load_cert(certpath, M2Crypto.X509.FORMAT_DER) out = {} out['pem'] = cert.as_pem() out['info'] = {} out['info']['issuer'] = cert.get_issuer().as_text() out['info']['subject'] = cert.get_subject().as_text() out['info']['fingerprint'] = cert.get_fingerprint(md='sha1') out['info']['keylength'] = cert.get_pubkey().get_rsa().__len__() out['info']['key'] = cert.get_pubkey().get_rsa().as_pem() out['info']['not_before'] = cert.get_not_before().get_datetime().isoformat() out['info']['not_after'] = cert.get_not_after().get_datetime().isoformat() out['info']['extension'] = {} extcount = cert.get_ext_count() for i in range(0, extcount): out['info']['extension'][cert.get_ext_at(i).get_name()] = cert.get_ext_at(i).get_value() if ricsi.exists(fp): icsi = ricsi.hgetall(fp) out['icsi'] = icsi if not self._finished: self.set_header('Content-Type', 'application/json') self.set_header('Server', servername) self.write(json.dumps(out))
Example #28
Source File: ip-ssl-subject-api.py From crl-monitor with GNU General Public License v3.0 | 4 votes |
def run_request(self, q): try: # Redis structure Set of (FP) per IP r = redis.StrictRedis(host='127.0.0.1', port=8323) except: print("Unable to connect to the Redis server") sys.exit(255) subnets = [q] out = {} for subnet in subnets: if re.findall(r":", subnet): self.clear() self.set_status(400) self.finish('IPv6 is not (yet) supported') continue try: iplist = netaddr.IPNetwork(subnet) except: self.clear() self.set_status(400) self.finish('Incorrect format') continue if iplist.size > ipmaxsize: self.clear() self.set_status(400) self.finish('Maximum CIDR block size reached >/23') if not self._finished: self.finish() for ip in iplist: s = r.smembers(ip) if s: out[str(ip)] = {} out[str(ip)]['certificates'] = [] out[str(ip)]['subjects'] = {} for fingerprint in s: subjects = r.smembers(fingerprint) out[str(ip)]['certificates'].append(fingerprint) if subjects: out[str(ip)]['subjects'][fingerprint] = {} out[str(ip)]['subjects'][fingerprint]['values'] = [] for subject in subjects: out[str(ip)]['subjects'][fingerprint]['values'].append(subject) if not self._finished: self.set_header('Content-Type', 'application/json') self.set_header('Server', servername) return json.dumps(out) def get(self, q): print("Query:", q) try: r = yield self.run_request(q) self.write(r) except Exception as e: print('Something went wrong with {}:\n{}'.format(q, e))