Python tornado.options.options.address() Examples

The following are 13 code examples of tornado.options.options.address(). 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: webserver.py    From torngas with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #2
Source File: main.py    From autoops with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: server.py    From magpie with MIT License 5 votes vote down vote up
def main():
    server = make_app()
    server.listen(options.port, options.address)
    autoreload.start()
    autoreload.watch(config_path.web)
    IOLoop.instance().start() 
Example #4
Source File: webserver.py    From torngas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #5
Source File: webserver.py    From torngas with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #6
Source File: main.py    From chain with Apache License 2.0 5 votes vote down vote up
def main():
    parse_command_line()
    settings = get_application_settings()

    handlers = [
        (r'/',   IndexHandler),
        (r'/ws', WsockHandler)
    ]

    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 #7
Source File: main.py    From webssh with MIT License 5 votes vote down vote up
def app_listen(app, port, address, server_settings):
    app.listen(port, address, **server_settings)
    if not server_settings.get('ssl_options'):
        server_type = 'http'
    else:
        server_type = 'https'
        handler.redirecting = True if options.redirect else False
    logging.info(
        'Listening on {}:{} ({})'.format(address, port, server_type)
    ) 
Example #8
Source File: main.py    From webssh with MIT License 5 votes vote down vote up
def main():
    options.parse_command_line()
    check_encoding_setting(options.encoding)
    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 #9
Source File: main.py    From adminset with GNU General Public License v2.0 5 votes vote down vote up
def app_listen(app, port, address, server_settings):
    app.listen(port, address, **server_settings)
    server_type = 'https' if server_settings.get('ssl_options') else 'http'
    logging.info(
        'Listening on {}:{} ({})'.format(address, port, server_type)
    )
    config_open_to_public(address, server_type) 
Example #10
Source File: main.py    From adminset with GNU General Public License v2.0 5 votes vote down vote up
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 #11
Source File: bind-restapi.py    From bind-restapi with GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        while True:
            app = Application()
            app.listen(options.port, options.address)
            IOLoop.instance().start() 
Example #12
Source File: test_command.py    From wscelery with MIT License 5 votes vote down vote up
def test_address(self):
        with self.mock_option('address', '127.0.0.1'):
            command = WsCeleryCommand()
            command.apply_options('wscelery', argv=['--address=foobar'])
            self.assertEqual(options.address, 'foobar') 
Example #13
Source File: server.py    From magpie with MIT License 4 votes vote down vote up
def make_app(config=None):
    root = path.dirname(__file__)
    static_path = path.join(root, 'static')
    template_path = path.join(root, 'template')

    app_config = dict(static_path=static_path,
                      template_path=template_path,
                      login_url='/login')

    define('port', default='8080', type=int)
    define('address', default='localhost', type=str)
    define('testing', default=False, type=bool)
    define('repo', default=None, type=str)
    define('username', default=None, type=str)
    define('pwdhash', default=None, type=str)
    define('autosave', default=False, type=bool)
    define('autosave_interval', default='5', type=int)
    define('wysiwyg', default=False, type=bool)

    if config is not None:
        # This should only ever be used for testing
        parse_config_file(config)
    else:
        parse_config_file(config_path.web)

    if options.testing:
        app_config.update(debug=True)

    server = Application(urls, **app_config)
    server.settings = AttrDict(server.settings)
    server.settings.repo = options.repo
    server.settings.username = options.username
    server.settings.pwdhash = options.pwdhash
    server.settings.session = _rand_str()
    server.settings.config_path = config_path
    server.settings.autosave = options.autosave
    server.settings.autosave_interval = options.autosave_interval
    server.settings.wysiwyg = options.wysiwyg

    server.git = git.bake(_cwd=server.settings.repo)

    return server