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


Python wsgi.ClosingIterator方法代码示例

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


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

示例1: __call__

# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import ClosingIterator [as 别名]
def __call__(self, environ, start_response):
        cookie = parse_cookie(environ.get('HTTP_COOKIE', ''))
        sid = cookie.get(self.cookie_name, None)
        if sid is None:
            session = self.store.new()
        else:
            session = self.store.get(sid)
        environ[self.environ_key] = session

        def injecting_start_response(status, headers, exc_info=None):
            if session.should_save:
                self.store.save(session)
                headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
                                                          session.sid, self.cookie_age,
                                                          self.cookie_expires, self.cookie_path,
                                                          self.cookie_domain, self.cookie_secure,
                                                          self.cookie_httponly)))
            return start_response(status, headers, exc_info)
        return ClosingIterator(self.app(environ, injecting_start_response),
                               lambda: self.store.save_if_modified(session)) 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:sessions.py

示例2: __call__

# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import ClosingIterator [as 别名]
def __call__(self, environ, start_response):
        cookie = parse_cookie(environ.get('HTTP_COOKIE', ''))
        sid = cookie.get(self.cookie_name, None)
        if sid is None:
            session = self.store.new()
        else:
            session = self.store.get(sid)
        environ[self.environ_key] = session

        def injecting_start_response(status, headers, exc_info=None):
            if session.should_save:
                self.store.save(session)
                headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
                                session.sid, self.cookie_age,
                                self.cookie_expires, self.cookie_path,
                                self.cookie_domain, self.cookie_secure,
                                self.cookie_httponly)))
            return start_response(status, headers, exc_info)
        return ClosingIterator(self.app(environ, injecting_start_response),
                               lambda: self.store.save_if_modified(session)) 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:22,代码来源:sessions.py

示例3: make_middleware

# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import ClosingIterator [as 别名]
def make_middleware(self, app):
        """Wrap a WSGI application so that cleaning up happens after
        request end.
        """
        def application(environ, start_response):
            return ClosingIterator(app(environ, start_response), self.cleanup)
        return application 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:local.py

示例4: __call__

# 需要导入模块: from werkzeug import wsgi [as 别名]
# 或者: from werkzeug.wsgi import ClosingIterator [as 别名]
def __call__(self, environ, start_response):
        """
        We must case-mangle the Set-Cookie header name or AWS will use only a
        single one of these headers.
        """

        def encode_response(status, headers, exc_info=None):
            """
            This makes the 'set-cookie' headers name lowercase,
            all the non-cookie headers should be sent unharmed.
            Related: https://github.com/Miserlou/Zappa/issues/1965
            """

            new_headers = [header for header in headers
                           if ((type(header[0]) != str) or (header[0].lower() != 'set-cookie'))]
            cookie_headers = [(header[0].lower(), header[1]) for header in headers
                              if ((type(header[0]) == str) and (header[0].lower() == "set-cookie"))]
            new_headers = new_headers + cookie_headers

            return start_response(status, new_headers, exc_info)

        # Call the application with our modifier
        response = self.application(environ, encode_response)

        # Return the response as a WSGI-safe iterator
        return ClosingIterator(response) 
开发者ID:Miserlou,项目名称:Zappa,代码行数:28,代码来源:middleware.py


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