def start(self): if self.current_thread is None: try: self.loop = ServerLoop( create_http_handler(self.handler.dispatch), opts=self.opts, log=self.log, access_log=self.access_log, plugins=self.plugins ) self.loop.initialize_socket() except Exception as e: self.loop = None self.exception = e if self.start_failure_callback is not None: try: self.start_failure_callback(as_unicode(e)) except Exception: pass return self.handler.set_jobs_manager(self.loop.jobs_manager) self.current_thread = t = Thread( name='EmbeddedServer', target=self.serve_forever ) t.daemon = True t.start()
def __init__(self, libraries, opts): log = access_log = None log_size = opts.max_log_size * 1024 * 1024 if opts.log: log = RotatingLog(opts.log, max_size=log_size) if opts.access_log: access_log = RotatingLog(opts.access_log, max_size=log_size) self.handler = Handler(libraries, opts) if opts.custom_list_template: with lopen(opts.custom_list_template, 'rb') as f: self.handler.router.ctx.custom_list_template = json.load(f) plugins = [] if opts.use_bonjour: plugins.append(BonJour()) self.loop = ServerLoop( create_http_handler(self.handler.dispatch), opts=opts, log=log, access_log=access_log, plugins=plugins) self.handler.set_log(self.loop.log) self.handler.set_jobs_manager(self.loop.jobs_manager) self.serve_forever = self.loop.serve_forever self.stop = self.loop.stop if is_running_from_develop: from calibre.utils.rapydscript import compile_srv compile_srv()
def __init__(self, libraries, opts): log = access_log = None log_size = opts.max_log_size * 1024 * 1024 if opts.log: log = RotatingLog(opts.log, max_size=log_size) if opts.access_log: access_log = RotatingLog(opts.access_log, max_size=log_size) self.handler = Handler(libraries, opts) if opts.custom_list_template: with lopen(os.path.expanduser(opts.custom_list_template), 'rb') as f: self.handler.router.ctx.custom_list_template = json.load(f) if opts.search_the_net_urls: with lopen(os.path.expanduser(opts.search_the_net_urls), 'rb') as f: self.handler.router.ctx.search_the_net_urls = json.load(f) plugins = [] if opts.use_bonjour: plugins.append(BonJour(wait_for_stop=max(0, opts.shutdown_timeout - 0.2))) self.loop = ServerLoop( create_http_handler(self.handler.dispatch), opts=opts, log=log, access_log=access_log, plugins=plugins) self.handler.set_log(self.loop.log) self.handler.set_jobs_manager(self.loop.jobs_manager) self.serve_forever = self.loop.serve_forever self.stop = self.loop.stop if is_running_from_develop: from calibre.utils.rapydscript import compile_srv compile_srv()
def __init__(self, listen_on): Thread.__init__(self, name='ReloadServer') self.reload_handler = ReloadHandler() self.loop = ServerLoop( create_http_handler(websocket_handler=self.reload_handler), opts=Options(shutdown_timeout=0.1, listen_on=(listen_on or '127.0.0.1'), port=0)) self.loop.LISTENING_MSG = None self.notify_reload = self.reload_handler.notify_reload self.ping = self.reload_handler.ping self.start()
def __init__(self, libraries, opts): log = None if opts.log: log = RotatingLog(opts.log, max_size=opts.max_log_size) self.handler = Handler(libraries, opts) plugins = [] if opts.use_bonjour: plugins.append(BonJour()) self.loop = ServerLoop(create_http_handler(self.handler.dispatch), opts=opts, log=log, plugins=plugins) self.handler.set_log(self.loop.log) self.serve_forever = self.loop.serve_forever self.stop = self.loop.stop
def __init__(self, handler, **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.http_response import create_http_handler kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1) self.loop = ServerLoop( create_http_handler(handler), opts=Options(**kwargs), bind_address=('localhost', 0), log=TestLog(level=ThreadSafeLog.WARN), ) self.log = self.loop.log
def __init__(self, handler, plugins=(), **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.http_response import create_http_handler self.setup_defaults(kwargs) self.loop = ServerLoop( create_http_handler(handler), opts=Options(**kwargs), plugins=plugins, log=ServerLog(level=ServerLog.DEBUG), ) self.log = self.loop.log
def __init__(self, handler, plugins=(), specialize=lambda srv:None, **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.http_response import create_http_handler self.setup_defaults(kwargs) self.loop = ServerLoop( create_http_handler(handler), opts=Options(**kwargs), plugins=plugins, log=ServerLog(level=ServerLog.WARN), ) self.log = self.loop.log specialize(self)
def __init__(self, handler, plugins=(), specialize=lambda srv:None, **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.http_response import create_http_handler self.setup_defaults(kwargs) self.loop = ServerLoop( create_http_handler(handler), opts=Options(**kwargs), plugins=plugins, log=ServerLog(level=ServerLog.WARN), ) self.log = self.loop.log self.silence_log = self.log specialize(self)
def __init__(self, libraries, opts): log = None if opts.log: log = RotatingLog(opts.log, max_size=opts.max_log_size) self.handler = Handler(libraries, opts) plugins = [] if opts.use_bonjour: plugins.append(BonJour()) self.loop = ServerLoop(create_http_handler(self.handler.dispatch), opts=opts, log=log, plugins=plugins) self.handler.set_log(self.loop.log) self.serve_forever = self.loop.serve_forever self.stop = self.loop.stop _df = os.environ.get('CALIBRE_DEVELOP_FROM', None) if _df and os.path.exists(_df): from calibre.utils.rapydscript import compile_srv compile_srv()
def __init__(self, handler, plugins=(), specialize=lambda srv:None, **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.http_response import create_http_handler kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1) kwargs['listen_on'] = kwargs.get('listen_on', 'localhost') kwargs['port'] = kwargs.get('port', 0) self.loop = ServerLoop( create_http_handler(handler), opts=Options(**kwargs), plugins=plugins, log=ServerLog(level=ServerLog.WARN), ) self.log = self.loop.log specialize(self)
def __init__(self, library_path, libraries=(), plugins=(), specialize=lambda x:None, **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.handler import Handler from calibre.srv.http_response import create_http_handler self.setup_defaults(kwargs) opts = Options(**kwargs) self.libraries = libraries or (library_path,) self.handler = Handler(self.libraries, opts, testing=True) self.loop = ServerLoop( create_http_handler(self.handler.dispatch), opts=opts, plugins=plugins, log=ServerLog(level=ServerLog.WARN), ) self.handler.set_log(self.loop.log) specialize(self)
def __init__(self, library_path, libraries=(), plugins=(), **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.handler import Handler from calibre.srv.http_response import create_http_handler self.setup_defaults(kwargs) opts = Options(**kwargs) self.libraries = libraries or (library_path, ) self.handler = Handler(self.libraries, opts, testing=True) self.loop = ServerLoop( create_http_handler(self.handler.dispatch), opts=opts, plugins=plugins, log=ServerLog(level=ServerLog.DEBUG), ) self.log = self.loop.log self.handler.set_log(self.log)
def __init__(self, library_path, libraries=(), plugins=(), specialize=lambda x:None, **kwargs): Thread.__init__(self, name='ServerMain') from calibre.srv.opts import Options from calibre.srv.loop import ServerLoop from calibre.srv.handler import Handler from calibre.srv.http_response import create_http_handler kwargs['shutdown_timeout'] = kwargs.get('shutdown_timeout', 0.1) kwargs['listen_on'] = kwargs.get('listen_on', 'localhost') kwargs['port'] = kwargs.get('port', 0) opts = Options(**kwargs) self.libraries = libraries or (library_path,) self.handler = Handler(self.libraries, opts, testing=True) self.loop = ServerLoop( create_http_handler(self.handler.dispatch), opts=opts, plugins=plugins, log=ServerLog(level=ServerLog.WARN), ) self.handler.set_log(self.loop.log) specialize(self)
def __init__(self, libraries, opts): log = access_log = None log_size = opts.max_log_size * 1024 * 1024 if opts.log: log = RotatingLog(opts.log, max_size=log_size) if opts.access_log: access_log = RotatingLog(opts.access_log, max_size=log_size) self.handler = Handler(libraries, opts) plugins = [] if opts.use_bonjour: plugins.append(BonJour()) self.loop = ServerLoop(create_http_handler(self.handler.dispatch), opts=opts, log=log, access_log=access_log, plugins=plugins) self.handler.set_log(self.loop.log) self.handler.set_jobs_manager(self.loop.jobs_manager) self.serve_forever = self.loop.serve_forever self.stop = self.loop.stop if is_running_from_develop: from calibre.utils.rapydscript import compile_srv compile_srv()
def __init__(self, handler): TestServer.__init__(self, None, shutdown_timeout=5) from calibre.srv.http_response import create_http_handler self.loop.handler = create_http_handler(websocket_handler=handler())
def run_echo_server(): s = ServerLoop(create_http_handler(websocket_handler=EchoHandler())) with HandleInterrupt(s.wakeup): s.serve_forever()
def change_handler(self, handler): from calibre.srv.http_response import create_http_handler self.loop.handler = create_http_handler(handler)