当前位置: 首页>>代码示例>>Python>>正文


Python simple_server.WSGIRequestHandler方法代码示例

本文整理汇总了Python中wsgiref.simple_server.WSGIRequestHandler方法的典型用法代码示例。如果您正苦于以下问题:Python simple_server.WSGIRequestHandler方法的具体用法?Python simple_server.WSGIRequestHandler怎么用?Python simple_server.WSGIRequestHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wsgiref.simple_server的用法示例。


在下文中一共展示了simple_server.WSGIRequestHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_environ

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def get_environ(self):
        # Strip all headers with underscores in the name before constructing
        # the WSGI environ. This prevents header-spoofing based on ambiguity
        # between underscores and dashes both normalized to underscores in WSGI
        # env vars. Nginx and Apache 2.4+ both do this as well.
        for k, v in self.headers.items():
            if '_' in k:
                del self.headers[k]

        env = super(WSGIRequestHandler, self).get_environ()

        path = self.path
        if '?' in path:
            path = path.partition('?')[0]

        path = uri_to_iri(path).encode(UTF_8)
        # Under Python 3, non-ASCII values in the WSGI environ are arbitrarily
        # decoded with ISO-8859-1. We replicate this behavior here.
        # Refs comment in `get_bytes_from_wsgi()`.
        env['PATH_INFO'] = path.decode(ISO_8859_1) if six.PY3 else path

        return env 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:24,代码来源:basehttp.py

示例2: handle

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def handle(self):
        """Copy of WSGIRequestHandler, but with different ServerHandler"""

        self.raw_requestline = self.rfile.readline(65537)
        if len(self.raw_requestline) > 65536:
            self.requestline = ''
            self.request_version = ''
            self.command = ''
            self.send_error(414)
            return

        if not self.parse_request():  # An error code has been sent, just exit
            return

        handler = ServerHandler(
            self.rfile, self.wfile, self.get_stderr(), self.get_environ()
        )
        handler.request_handler = self      # backpointer for logging
        handler.run(self.server.get_app()) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:21,代码来源:basehttp.py

示例3: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
    server_address = (addr, port)
    if threading:
        httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
    else:
        httpd_cls = WSGIServer
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
    if threading:
        # ThreadingMixIn.daemon_threads indicates how threads will behave on an
        # abrupt shutdown; like quitting the server by the user or restarting
        # by the auto-reloader. True means the server will not wait for thread
        # termination before it quits. This will make auto-reloader faster
        # and will prevent the need to kill the server manually if a thread
        # isn't terminating correctly.
        httpd.daemon_threads = True
    httpd.set_app(wsgi_handler)
    httpd.serve_forever() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:basehttp.py

示例4: __init__

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def __init__(self, *args, **kwargs):
        self.style = color_style()
        super(WSGIRequestHandler, self).__init__(*args, **kwargs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:5,代码来源:basehttp.py

示例5: __init__

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def __init__(self, server_address, app = None, RequestHandlerClass = WSGIRequestHandler):
		_WSGIServer.__init__(self, server_address, RequestHandlerClass)
		self.set_app(app) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:5,代码来源:__init__.py

示例6: __init__

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def __init__(self, server_address, certfile, keyfile = None, ca_certs = None, cert_reqs = NOT_SET, app = None, RequestHandlerClass = WSGIRequestHandler):
		WSGIServer.__init__(self, server_address, app = app, RequestHandlerClass = RequestHandlerClass)
		self.init_https(certfile, keyfile, ca_certs = ca_certs, cert_reqs = cert_reqs) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:5,代码来源:ssl.py

示例7: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def run(self, handler): # pragma: no cover
        from wsgiref.simple_server import make_server, WSGIRequestHandler
        if self.quiet:
            class QuietHandler(WSGIRequestHandler):
                def log_request(*args, **kw): pass
            self.options['handler_class'] = QuietHandler
        srv = make_server(self.host, self.port, handler, **self.options)
        srv.serve_forever() 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:10,代码来源:bottle.py

示例8: webdav_server

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def webdav_server(tmp_root_directory):
    from wsgiref.simple_server import WSGIRequestHandler, make_server
    from wsgidav.wsgidav_app import WsgiDAVApp
    from wsgidav.fs_dav_provider import FilesystemProvider

    class MutedWSGIRequestHandler(WSGIRequestHandler):
        def log_message(self, format, *args):
            pass

    class WebDavServer:
        def __init__(self):
            self.app = WsgiDAVApp({
                'provider_mapping': {
                    '/': FilesystemProvider(tmp_root_directory)
                },
                'simple_dc': {
                    'user_mapping': {"*": True}
                }
            })
            self.server = make_server('', 8080, app=self.app,
                                      handler_class=MutedWSGIRequestHandler)

        def __enter__(self):
            return self

        def __exit__(self, exc_type, exc_val, exc_tb):
            self.server.server_close()

        def run_wsgi(self):
            self.server.serve_forever()

    with WebDavServer() as srv:
        thread = threading.Thread(target=srv.run_wsgi)
        thread.daemon = True
        thread.start()
        yield srv 
开发者ID:marazmiki,项目名称:django-webdav-storage,代码行数:38,代码来源:conftest.py

示例9: handle

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def handle(self):
        try:
            return super(LogbookWSGIRequestHandler, self).handle()
        except socket.timeout as e:
            # Why WSGIRequestHandler doesn't handle this, I have no idea.
            self.log_error("Request timed out: %r", e)
            raise 
开发者ID:quantopian,项目名称:coal-mine,代码行数:9,代码来源:server.py

示例10: __init__

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def __init__(self, *args, **kwargs):
        from django.conf import settings
        self.admin_static_prefix = urljoin(settings.STATIC_URL, 'admin/')
        # We set self.path to avoid crashes in log_message() on unsupported
        # requests (like "OPTIONS").
        self.path = ''
        self.style = color_style()
        super(WSGIRequestHandler, self).__init__(*args, **kwargs) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:10,代码来源:basehttp.py

示例11: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
    server_address = (addr, port)
    if threading:
        httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
    else:
        httpd_cls = WSGIServer
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
    httpd.set_app(wsgi_handler)
    httpd.serve_forever() 
开发者ID:blackye,项目名称:luscan-devel,代码行数:11,代码来源:basehttp.py

示例12: run

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def run(self, handler):
        class QuietHandler(WSGIRequestHandler):
            def log_request(*args, **kw):
                pass

            def log_error(self, format, *args):
                pass
        self.options['handler_class'] = QuietHandler
        srv = make_server(self.host, self.port, handler, **self.options)
        srv.serve_forever() 
开发者ID:mseclab,项目名称:PyJFuzz,代码行数:12,代码来源:pjf_server.py

示例13: wsgiref

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def wsgiref(app, address, **options):  # pragma: no cover
        from wsgiref.simple_server import make_server, WSGIRequestHandler
        options = {}
        class QuietHandler(WSGIRequestHandler):
            def log_request(*args, **kw):
                pass
        options['handler_class'] = QuietHandler
        srv = make_server(address[0], address[1], app, **options)
        srv.serve_forever() 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:11,代码来源:anyserver.py

示例14: test_interrupted_write

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def test_interrupted_write(self):
        # BaseHandler._write() and _flush() have to write all data, even if
        # it takes multiple send() calls.  Test this by interrupting a send()
        # call with a Unix signal.
        threading = support.import_module("threading")
        pthread_kill = support.get_attribute(signal, "pthread_kill")

        def app(environ, start_response):
            start_response("200 OK", [])
            return [bytes(support.SOCK_MAX_SIZE)]

        class WsgiHandler(NoLogRequestHandler, WSGIRequestHandler):
            pass

        server = make_server(support.HOST, 0, app, handler_class=WsgiHandler)
        self.addCleanup(server.server_close)
        interrupted = threading.Event()

        def signal_handler(signum, frame):
            interrupted.set()

        original = signal.signal(signal.SIGUSR1, signal_handler)
        self.addCleanup(signal.signal, signal.SIGUSR1, original)
        received = None
        main_thread = threading.get_ident()

        def run_client():
            http = HTTPConnection(*server.server_address)
            http.request("GET", "/")
            with http.getresponse() as response:
                response.read(100)
                # The main thread should now be blocking in a send() system
                # call.  But in theory, it could get interrupted by other
                # signals, and then retried.  So keep sending the signal in a
                # loop, in case an earlier signal happens to be delivered at
                # an inconvenient moment.
                while True:
                    pthread_kill(main_thread, signal.SIGUSR1)
                    if interrupted.wait(timeout=float(1)):
                        break
                nonlocal received
                received = len(response.read())
            http.close()

        background = threading.Thread(target=run_client)
        background.start()
        server.handle_request()
        background.join()
        self.assertEqual(received, support.SOCK_MAX_SIZE - 100) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:51,代码来源:test_wsgiref.py

示例15: authenticate

# 需要导入模块: from wsgiref import simple_server [as 别名]
# 或者: from wsgiref.simple_server import WSGIRequestHandler [as 别名]
def authenticate(oauth_class=OAuth2):
    class StoppableWSGIServer(bottle.ServerAdapter):
        def __init__(self, *args, **kwargs):
            super(StoppableWSGIServer, self).__init__(*args, **kwargs)
            self._server = None

        def run(self, app):
            server_cls = self.options.get('server_class', WSGIServer)
            handler_cls = self.options.get('handler_class', WSGIRequestHandler)
            self._server = make_server(self.host, self.port, app, server_cls, handler_cls)
            self._server.serve_forever()

        def stop(self):
            self._server.shutdown()

    auth_code = {}
    auth_code_is_available = Event()

    local_oauth_redirect = bottle.Bottle()

    @local_oauth_redirect.get('/')
    def get_token():
        auth_code['auth_code'] = bottle.request.query.code
        auth_code['state'] = bottle.request.query.state
        auth_code_is_available.set()

    local_server = StoppableWSGIServer(host='localhost', port=8080)
    server_thread = Thread(target=lambda: local_oauth_redirect.run(server=local_server))
    server_thread.start()

    oauth = oauth_class(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
    )
    auth_url, csrf_token = oauth.get_authorization_url('http://localhost:8080')
    webbrowser.open(auth_url)

    auth_code_is_available.wait()
    local_server.stop()
    assert auth_code['state'] == csrf_token
    access_token, refresh_token = oauth.authenticate(auth_code['auth_code'])

    print('access_token: ' + access_token)
    print('refresh_token: ' + refresh_token)

    return oauth, access_token, refresh_token 
开发者ID:box,项目名称:box-python-sdk,代码行数:48,代码来源:auth.py


注:本文中的wsgiref.simple_server.WSGIRequestHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。