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


Python Response.date方法代码示例

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


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

示例1: index

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import date [as 别名]
    def index(self, req):
        """ Handle GET and HEAD requests for static files. Directory requests are not allowed"""
        static_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '../static/'))

        # filter out ..
        try:
            static_path = req.urlvars['path'].replace('/..', '')
        except:
            return HTTPForbidden()

        path = os.path.join(static_dir, static_path) 
        if os.path.isdir(path):
            return HTTPForbidden()

        if req.method == 'GET' or req.method == 'HEAD':
            if os.path.isfile(path):
                etag, modified, mime_type, size = self._get_stat(path)

                res = Response()
                res.headers['content-type'] = mime_type
                res.date = rfc822.formatdate(time.time())
                res.last_modified = modified
                res.etag = etag

                if_modified_since = req.headers.get('HTTP_IF_MODIFIED_SINCE')
                if if_modified_since:
                    if rfc822.parsedate(if_modified_since) >= rfc822.parsedate(last_modified):
                        return HTTPNotModified()

                if_none_match = req.headers.get('HTTP_IF_NONE_MATCH')
                if if_none_match:
                    if if_none_match == '*' or etag in if_none_match:
                        return HTTPNotModified()

                # set the response body
                if req.method == 'GET':
                    fd = open(path, 'rb')
                    if 'wsgi.file_wrapper' in req.environ:
                        res.app_iter = req.environ['wsgi.file_wrapper'](fd)
                        res.content_length = size
                    else:
                        res.app_iter = iter(lambda: fd.read(8192), '')
                        res.content_length = size
                else:
                    res.body = ''

                return res
            else:
                return None
        else:
            return None
开发者ID:sizzlelab,项目名称:pysmsd,代码行数:53,代码来源:static.py

示例2: __after__

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import date [as 别名]
 def __after__(self, result, *args, **kw):
     """Generate the JSON response and sign."""
     
     key = SigningKey.from_string(unhexlify(request.service.key.private), curve=NIST256p, hashfunc=sha256)
     
     response = Response(status=200, charset='utf-8')
     response.date = datetime.utcnow()
     response.last_modified = result.pop('updated', None)
     
     ct, body = render('json:', result)
     response.headers[b'Content-Type'] = str(ct)  # protect against lack of conversion in Flup
     response.body = body
     
     canon = "{req.service.id}\n{resp.headers[Date]}\n{req.url}\n{resp.body}".format(
                 req = request,
                 resp = response
开发者ID:Acidity,项目名称:api,代码行数:18,代码来源:controller.py

示例3: hdr_cache_forever

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import date [as 别名]
 def hdr_cache_forever(self):
     res = Response()
     res.date = datetime.now().isoformat()
     res.expires = 0
     res.cache_control = "public, max-age=31536000"
     return res
开发者ID:llacroix,项目名称:Git-Python-Http,代码行数:8,代码来源:__init__.py


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