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


Python wsgi.base_environ方法代码示例

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


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

示例1: environ_from_request

# 需要导入模块: from gunicorn.http import wsgi [as 别名]
# 或者: from gunicorn.http.wsgi import base_environ [as 别名]
def environ_from_request(cfg, req, sockname, body):
    target = req.target
    fragment = None
    query = None
    target = urllib.parse.unquote_to_bytes(target)
    if b'#' in target:
        target, fragment = target.split(b'#', 1)
    if b'?' in target:
        print(repr(target))
        target, query = target.split(b'?', 1)

    environ = base_environ(cfg)
    environ.update({
        'PATH_INFO': target.decode('utf8'),
        'QUERY_STRING': query.decode('utf8') if query else '',
        'REQUEST_METHOD': req.method.decode('ascii'),
        'SCRIPT_NAME': os.environ.get('SCRIPT_NAME', ''),
        'SERVER_NAME': sockname[0],
        'SERVER_PORT': str(sockname[1]),
        'SERVER_PROTOCOL': 'HTTP/%s' % req.http_version.decode('ascii'),

        'wsgi.input': io.BytesIO(body),
        'wsgi.url_scheme': 'https' if cfg.is_ssl else 'http',
    })

    for k, v in req.headers:
        print(repr(k), repr(v))
        if k == b'host':
            environ['HOST'] = v.decode('ascii')

        key = 'HTTP_' + k.decode('ascii').upper().replace('-', '_')
        if key in environ:
            v = "%s,%s" % (environ[key], v.decode('ascii'))
        environ[key] = v.decode('ascii')

    return environ 
开发者ID:jeamland,项目名称:guvnor,代码行数:38,代码来源:asyncio_worker.py

示例2: run

# 需要导入模块: from gunicorn.http import wsgi [as 别名]
# 或者: from gunicorn.http.wsgi import base_environ [as 别名]
def run(self):
        servers = []
        ssl_args = {}

        if self.cfg.is_ssl:
            ssl_args = dict(server_side=True, **self.cfg.ssl_options)

        for s in self.sockets:
            s.setblocking(1)
            pool = Pool(self.worker_connections)
            if self.server_class is not None:
                environ = base_environ(self.cfg)
                environ.update({
                    "wsgi.multithread": True,
                    "SERVER_SOFTWARE": VERSION,
                })
                server = self.server_class(
                    s, application=self.wsgi, spawn=pool, log=self.log,
                    handler_class=self.wsgi_handler, environ=environ,
                    **ssl_args)
            else:
                hfun = partial(self.handle, s)
                server = StreamServer(s, handle=hfun, spawn=pool, **ssl_args)

            server.start()
            servers.append(server)

        while self.alive:
            self.notify()
            gevent.sleep(1.0)

        try:
            # Stop accepting requests
            for server in servers:
                if hasattr(server, 'close'):  # gevent 1.0
                    server.close()
                if hasattr(server, 'kill'):  # gevent < 1.0
                    server.kill()

            # Handle current requests until graceful_timeout
            ts = time.time()
            while time.time() - ts <= self.cfg.graceful_timeout:
                accepting = 0
                for server in servers:
                    if server.pool.free_count() != server.pool.size:
                        accepting += 1

                # if no server is accepting a connection, we can exit
                if not accepting:
                    return

                self.notify()
                gevent.sleep(1.0)

            # Force kill all active the handlers
            self.log.warning("Worker graceful timeout (pid:%s)" % self.pid)
            [server.stop(timeout=1) for server in servers]
        except:
            pass 
开发者ID:yelongyu,项目名称:chihu,代码行数:61,代码来源:ggevent.py


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