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


Python WSGIContainer.environ方法代码示例

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


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

示例1: get

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def get(self, *args, **kwargs):
        # type: (*Any, **Any) -> None
        environ = WSGIContainer.environ(self.request)
        environ['PATH_INFO'] = urllib.parse.unquote(environ['PATH_INFO'])
        request = WSGIRequest(environ)
        request._tornado_handler = self

        set_script_prefix(get_script_name(environ))
        signals.request_started.send(sender=self.__class__)
        try:
            response = self.get_response(request)

            if not response:
                return
        finally:
            signals.request_finished.send(sender=self.__class__)

        self.set_status(response.status_code)
        for h in response.items():
            self.set_header(h[0], h[1])

        if not hasattr(self, "_new_cookies"):
            self._new_cookies = []  # type: List[http.cookie.SimpleCookie]
        self._new_cookies.append(response.cookies)

        self.write(response.content)
        self.finish()
开发者ID:yhl-python,项目名称:zulip,代码行数:29,代码来源:handlers.py

示例2: get

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def get(self):
        from tornado.wsgi import WSGIContainer
        from django.core.handlers.wsgi import WSGIRequest, get_script_name
        import urllib

        environ  = WSGIContainer.environ(self.request)
        environ['PATH_INFO'] = urllib.unquote(environ['PATH_INFO'])
        request  = WSGIRequest(environ)
        request._tornado_handler     = self

        set_script_prefix(get_script_name(environ))
        signals.request_started.send(sender=self.__class__)
        try:
            response = self.get_response(request)

            if not response:
                return
        finally:
            signals.request_finished.send(sender=self.__class__)

        self.set_status(response.status_code)
        for h in response.items():
            self.set_header(h[0], h[1])

        if not hasattr(self, "_new_cookies"):
            self._new_cookies = []
        self._new_cookies.append(response.cookies)

        self.write(response.content)
        self.finish()
开发者ID:Gabriel0402,项目名称:zulip,代码行数:32,代码来源:runtornado.py

示例3: __init__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def __init__(self, tornado_req, site_conf):
        super(TornadoRequest, self).__init__(
                WSGIContainer.environ(tornado_req)
                )
        self._native_request = tornado_req

        self.site = site_conf
开发者ID:soulfere,项目名称:weiyu,代码行数:9,代码来源:tornado_.py

示例4: get_django_request

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def get_django_request(self):
        request = \
            WSGIRequest(WSGIContainer.environ(self.request))
        request.session = self.get_django_session()

        if self.current_user:
            request.user = self.current_user
        else:
            request.user = auth.models.AnonymousUser()
        return request
开发者ID:AndreasZitek,项目名称:fiduswriter,代码行数:12,代码来源:base_redis.py

示例5: __call__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def __call__(self, request):
        data = {}
        response = []

        def start_response(status, response_headers, exc_info=None):
            data["status"] = status
            data["headers"] = response_headers
            return response.append

        app_response = self.wsgi_app(
            WSGIContainer.environ(request), start_response)
        try:
            response.extend(app_response)
            body = b"".join(response)
        finally:
            if hasattr(app_response, "close"):
                app_response.close()
        if not data:
            raise Exception("WSGI app did not call start_response")

        status_code, reason = data["status"].split(' ', 1)
        status_code = int(status_code)
        headers = data["headers"]
        header_set = set(k.lower() for (k, v) in headers)
        body = escape.utf8(body)

        if HEAD_END in body:
            body = body.replace(HEAD_END, self.script + HEAD_END)

        if status_code != 304:
            if "content-type" not in header_set:
                headers.append((
                    "Content-Type",
                    "application/octet-stream; charset=UTF-8"
                ))
            if "content-length" not in header_set:
                headers.append(("Content-Length", str(len(body))))

        if "server" not in header_set:
            headers.append(("Server", "LiveServer"))

        start_line = httputil.ResponseStartLine(
            "HTTP/1.1", status_code, reason
        )
        header_obj = httputil.HTTPHeaders()
        for key, value in headers:
            if key.lower() == 'content-length':
                value = str(len(body))
            header_obj.add(key, value)
        request.connection.write_headers(start_line, header_obj, chunk=body)
        request.connection.finish()
        self._log(status_code, request)
开发者ID:lepture,项目名称:python-livereload,代码行数:54,代码来源:server.py

示例6: __call__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def __call__(self, request):
        data = {}
        response = []

        def start_response(status, response_headers, exc_info=None):
            data["status"] = status
            data["headers"] = response_headers
            return response.append
        app_response = self.wsgi_application(
            WSGIContainer.environ(request), start_response)
        try:
            response.extend(app_response)
            body = b"".join(response)
        finally:
            if hasattr(app_response, "close"):
                app_response.close()
        if not data:
            raise Exception("WSGI app did not call start_response")

        status_code = int(data["status"].split()[0])
        headers = data["headers"]
        header_set = set(k.lower() for (k, v) in headers)
        body = escape.utf8(body)
        body = body.replace(
            b'</head>',
            b'<script src="/livereload.js"></script></head>'
        )

        if status_code != 304:
            if "content-length" not in header_set:
                headers.append(("Content-Length", str(len(body))))
            if "content-type" not in header_set:
                headers.append(("Content-Type", "text/html; charset=UTF-8"))
        if "server" not in header_set:
            headers.append(("Server", "livereload-tornado"))

        parts = [escape.utf8("HTTP/1.1 " + data["status"] + "\r\n")]
        for key, value in headers:
            if key.lower() == 'content-length':
                value = str(len(body))
            parts.append(
                escape.utf8(key) + b": " + escape.utf8(value) + b"\r\n"
            )
        parts.append(b"\r\n")
        parts.append(body)
        request.write(b"".join(parts))
        request.finish()
        self._log(status_code, request)
开发者ID:ssddi456,项目名称:python-livereload,代码行数:50,代码来源:server.py

示例7: get

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def get(self):
        from tornado.wsgi import HTTPRequest, WSGIContainer
        from django.core.handlers.wsgi import WSGIRequest, STATUS_CODE_TEXT
        import urllib

        environ = WSGIContainer.environ(self.request)
        environ["PATH_INFO"] = urllib.unquote(environ["PATH_INFO"])
        request = WSGIRequest(environ)

        request._tornado_handler = self

        set_script_prefix(base.get_script_name(environ))
        signals.request_started.send(sender=self.__class__)
        try:
            response = self.get_response(request)

            if not response:
                return

            # Apply response middleware
            for middleware_method in self._response_middleware:
                response = middleware_method(request, response)
            response = self.apply_response_fixes(request, response)
        finally:
            signals.request_finished.send(sender=self.__class__)

        try:
            status_text = STATUS_CODE_TEXT[response.status_code]
        except KeyError:
            status_text = "UNKNOWN STATUS CODE"
        status = "%s %s" % (response.status_code, status_text)

        self.set_status(response.status_code)
        for h in response.items():
            self.set_header(h[0], h[1])

        """
        if not hasattr(self, "_new_cookies"):
            self._new_cookies = []
        self._new_cookies.append(response.cookies)
        """
        # Tornado 2.3 has changed the _new_cookies methods. Its not an array.
        # revert back to old method
        for c in response.cookies.values():
            self.set_header("Set-Cookie", str(c.output(header="")))

        self.write(response.content)
        self.finish()
开发者ID:pombredanne,项目名称:django-on-tornado,代码行数:50,代码来源:runtornado.py

示例8: get

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def get(self) :
        from tornado.wsgi import HTTPRequest, WSGIContainer
        from django.core.handlers.wsgi import WSGIRequest, STATUS_CODE_TEXT
        import urllib

        environ  = WSGIContainer.environ(self.request)
        environ['PATH_INFO'] = urllib.unquote(environ['PATH_INFO'])
        request  = WSGIRequest(environ)

        request._tornado_handler     = self

        set_script_prefix(base.get_script_name(environ))
        signals.request_started.send(sender=self.__class__)
        try:
            response = self.get_response(request)

            if not response :
                return 

            # Apply response middleware
            for middleware_method in self._response_middleware:
                response = middleware_method(request, response)
            response = self.apply_response_fixes(request, response)
        finally:
            signals.request_finished.send(sender=self.__class__)

        try:
            status_text = STATUS_CODE_TEXT[response.status_code]
        except KeyError:
            status_text = 'UNKNOWN STATUS CODE'
        status = '%s %s' % (response.status_code, status_text)

        self.set_status(response.status_code)
        for h in response.items() :
            self.set_header(h[0], h[1])

        for c in response.cookies.values():
            self.set_header('Set-Cookie', str(c.output(header='')))

        """
        if  hasattr(self, "_new_cookies"):
            print self._new_cookies
        self._new_cookies = response.cookies
        """

        self.write(response.content)
        self.finish()
开发者ID:tvpavan,项目名称:django-on-tornado,代码行数:49,代码来源:runtornado.py

示例9: __call__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def __call__(self, request):
        parts = []
        parts_append = parts.append

        base_header = strftime('\r\nDate: %a, %d %b %Y %H:%M:%S GMT', gmtime()) + '\r\nServer: tornado\r\n'
        if not request.supports_http_1_1():
            if request.headers.get('Connection', '').lower() == 'keep-alive':
                base_header += 'Connection: Keep-Alive\r\n'

        def start_response(status, response_headers, exc_info=None):
            parts_append(utf8('HTTP/1.1 ' + status + base_header))
            for key, value in response_headers:
                parts_append(utf8(key + ': ' + value + '\r\n'))
            parts_append(self.new_line)
            return None

        environ = WSGIContainer.environ(request)
        environ['wsgi.multiprocess'] = False # Some EvalException middleware fails if set to True

        app_response = self.wsgi_application(environ, start_response)
        if not parts:
            raise Exception('WSGI app did not call start_response')

        if request.method != 'HEAD':
            parts.extend(app_response)

        if hasattr(app_response, 'close'):
            app_response.close()
        app_response = None

        if hasattr(request, "connection"):
            # Now that the request is finished, clear the callback we
            # set on the IOStream (which would otherwise prevent the
            # garbage collection of the RequestHandler when there
            # are keepalive connections)
            request.connection.stream.set_close_callback(None)

        request.write(self.empty_string.join(parts))
        try:
            request.finish()
        except IOError as e:
            self.logger.error('Exception when writing response: %s', str(e))
开发者ID:DaneTheory,项目名称:turbulenz_local,代码行数:44,代码来源:paste_factory.py

示例10: wrapper

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
 def wrapper(request, response):
     req = yield request.read()
     for data in application(WSGIContainer.environ(req), functools.partial(start_response, response)):
         response.write(data)
     response.close()
开发者ID:Alukardd,项目名称:cocaine-framework-python,代码行数:7,代码来源:wsgi.py

示例11: wrapper

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
 def wrapper(request, response):
     req = yield request.read()
     datas = yield application(WSGIContainer.environ(req), partial(start_response, response))
     for data in datas:
         response.write(data)
     response.close()
开发者ID:nexusriot,项目名称:cocaine-framework-python,代码行数:8,代码来源:wsgi.py

示例12: __init__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
 def __init__(self, tornado_request_type, cookies=None):
     self._tornado_request = tornado_request_type
     self._cookies = cookies
     environ = WSGIContainer.environ(tornado_request_type)
     super(DjangoRequest,self).__init__(environ)
     self.tornado_to_django()
开发者ID:daqing15,项目名称:django-tornado,代码行数:8,代码来源:handlers.py

示例13: __call__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def __call__(self, request):

        data = {}
        response = []

        def start_response(status, response_headers, exc_info=None):
            data["status"] = status
            data["headers"] = response_headers
            return response.append

        app_response = self.wsgi_application(WSGIContainer.environ(request), start_response)

        try:
            response.extend(app_response)
            body = b"".join(response)
        finally:
            if hasattr(app_response, "close"):
                app_response.close()
        if not data:
            raise Exception("WSGI app did not call start_response")

        status_code = int(data["status"].split()[0])
        headers = data["headers"]
        header_set = set(k.lower() for (k, v) in headers)
        body = escape.utf8(body)

        if status_code != 304:
            if "content-length" not in header_set:
                headers.append(("Content-Length", str(len(body))))
            if "content-type" not in header_set:
                headers.append(("Content-Type", "text/html; charset=UTF-8"))
        if "server" not in header_set:
            headers.append(("Server", "TornadoServer/%s" % tornado.version))

        # try:

            # if request.method.lower() != GET:

            # _cookies = Cookie.SimpleCookie()

            # Django session cookies are set at the django level, but
            # tornado-specific cookies are appended here.

            # token = request.cookies[djsettings.CSRF_COOKIE_NAME]
            # if token:
            #     _cookies[settings.XSRF_TOKEN] = token.value

            # TODO Change when we add more contexts
            # _cookies[settings.CONTEXT_COOKIE] = settings.DEFAULT_CONTEXT

            # for c in _cookies.output(sep='\t').split('\t'):
            #     k, v = c.split(': ')
            #     headers.append((k, v + '; Path=/'))

        # except ValueError as e:
        #     logging.getLogger("ef5").error("A Value is either missing or invalid: {0}".format(e))
        # except Exception as e:
        #     logging.getLogger("ef5").error("An unknown error occurred: {0} with stacktrace {1}".format(e, traceback.format_exc()))

        parts = [escape.utf8("HTTP/1.1 " + data["status"] + "\r\n")]
        for key, value in headers:
            parts.append(escape.utf8(key) + b": " + escape.utf8(value) + b"\r\n")

        parts.append(b"\r\n")
        parts.append(body)

        request.write(b"".join(parts))
        request.finish()
        self._log(status_code, request)
开发者ID:HankeyEngineering,项目名称:Zeus,代码行数:71,代码来源:wsgi.py

示例14: __init__

# 需要导入模块: from tornado.wsgi import WSGIContainer [as 别名]
# 或者: from tornado.wsgi.WSGIContainer import environ [as 别名]
    def __init__(self, *args, **kwargs):
        _RequestHandler.__init__(self, *args, **kwargs)

        self.environ = WSGIContainer.environ(self.request)
开发者ID:extramental,项目名称:neuron,代码行数:6,代码来源:rest.py


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