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


Python httputil.format_timestamp方法代码示例

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


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

示例1: _convert_header_value

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def _convert_header_value(self, value):
        if isinstance(value, bytes):
            pass
        elif isinstance(value, unicode_type):
            value = value.encode('utf-8')
        elif isinstance(value, numbers.Integral):
            # return immediately since we know the converted value will be safe
            return str(value)
        elif isinstance(value, datetime.datetime):
            return httputil.format_timestamp(value)
        else:
            raise TypeError("Unsupported header value %r" % value)
        # If \n is allowed into the header, it is possible to inject
        # additional headers or split the request.
        if RequestHandler._INVALID_HEADER_CHAR_RE.search(value):
            raise ValueError("Unsafe header value %r", value)
        return value 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:web.py

示例2: test_static_if_modified_since_time_zone

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def test_static_if_modified_since_time_zone(self):
        # Instead of the value from Last-Modified, make requests with times
        # chosen just before and after the known modification time
        # of the file to ensure that the right time zone is being used
        # when parsing If-Modified-Since.
        stat = os.stat(relpath("static/robots.txt"))

        response = self.get_and_head(
            "/static/robots.txt",
            headers={"If-Modified-Since": format_timestamp(stat.st_mtime - 1)},
        )
        self.assertEqual(response.code, 200)
        response = self.get_and_head(
            "/static/robots.txt",
            headers={"If-Modified-Since": format_timestamp(stat.st_mtime + 1)},
        )
        self.assertEqual(response.code, 304) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:19,代码来源:web_test.py

示例3: clear

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def clear(self):
        """Resets all headers and content for this response."""
        self._headers = httputil.HTTPHeaders({
            "Server": "TornadoServer/%s" % tornado.version,
            "Content-Type": "text/html; charset=UTF-8",
            "Date": httputil.format_timestamp(time.time()),
        })
        self.set_default_headers()
        if (not self.request.supports_http_1_1() and
            getattr(self.request, 'connection', None) and
                not self.request.connection.no_keep_alive):
            conn_header = self.request.headers.get("Connection")
            if conn_header and (conn_header.lower() == "keep-alive"):
                self.set_header("Connection", "Keep-Alive")
        self._write_buffer = []
        self._status_code = 200
        self._reason = httputil.responses[200] 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:19,代码来源:web.py

示例4: _convert_header_value

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def _convert_header_value(self, value):
        if isinstance(value, bytes_type):
            pass
        elif isinstance(value, unicode_type):
            value = value.encode('utf-8')
        elif isinstance(value, numbers.Integral):
            # return immediately since we know the converted value will be safe
            return str(value)
        elif isinstance(value, datetime.datetime):
            return httputil.format_timestamp(value)
        else:
            raise TypeError("Unsupported header value %r" % value)
        # If \n is allowed into the header, it is possible to inject
        # additional headers or split the request. Also cap length to
        # prevent obviously erroneous values.
        if (len(value) > 4000 or
                RequestHandler._INVALID_HEADER_CHAR_RE.search(value)):
            raise ValueError("Unsafe header value %r", value)
        return value 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:21,代码来源:web.py

示例5: clear

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def clear(self):
        """重置这个响应的所有头部和内容."""
        self._headers = httputil.HTTPHeaders({
            "Server": "TornadoServer/%s" % tornado.version,
            "Content-Type": "text/html; charset=UTF-8",
            "Date": httputil.format_timestamp(time.time()),
        })
        self.set_default_headers()
        self._write_buffer = []
        self._status_code = 200
        self._reason = httputil.responses[200] 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:web.py

示例6: set_cookie

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def set_cookie(self, name, value, domain=None, expires=None, path="/",
                   expires_days=None, **kwargs):
        """设置给定的cookie 名称/值还有其他给定的选项.

        另外的关键字参数在Cookie.Morsel直接设置.
        参见 https://docs.python.org/2/library/cookie.html#morsel-objects
        查看可用的属性.
        """
        # The cookie library only accepts type str, in both python 2 and 3
        name = escape.native_str(name)
        value = escape.native_str(value)
        if re.search(r"[\x00-\x20]", name + value):
            # Don't let us accidentally inject bad stuff
            raise ValueError("Invalid cookie %r: %r" % (name, value))
        if not hasattr(self, "_new_cookie"):
            self._new_cookie = Cookie.SimpleCookie()
        if name in self._new_cookie:
            del self._new_cookie[name]
        self._new_cookie[name] = value
        morsel = self._new_cookie[name]
        if domain:
            morsel["domain"] = domain
        if expires_days is not None and not expires:
            expires = datetime.datetime.utcnow() + datetime.timedelta(
                days=expires_days)
        if expires:
            morsel["expires"] = httputil.format_timestamp(expires)
        if path:
            morsel["path"] = path
        for k, v in kwargs.items():
            if k == 'max_age':
                k = 'max-age'

            # skip falsy values for httponly and secure flags because
            # SimpleCookie sets them regardless
            if k in ['httponly', 'secure'] and not v:
                continue

            morsel[k] = v 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:41,代码来源:web.py

示例7: test_if_modified_since

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def test_if_modified_since(self):
        http_date = datetime.datetime.utcnow()
        request = HTTPRequest('http://example.com', if_modified_since=http_date)
        self.assertEqual(request.headers,
                         {'If-Modified-Since': format_timestamp(http_date)}) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:httpclient_test.py

示例8: test_static_if_modified_since_time_zone

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def test_static_if_modified_since_time_zone(self):
        # Instead of the value from Last-Modified, make requests with times
        # chosen just before and after the known modification time
        # of the file to ensure that the right time zone is being used
        # when parsing If-Modified-Since.
        stat = os.stat(relpath('static/robots.txt'))

        response = self.get_and_head('/static/robots.txt', headers={
            'If-Modified-Since': format_timestamp(stat.st_mtime - 1)})
        self.assertEqual(response.code, 200)
        response = self.get_and_head('/static/robots.txt', headers={
            'If-Modified-Since': format_timestamp(stat.st_mtime + 1)})
        self.assertEqual(response.code, 304) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:web_test.py

示例9: clear

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def clear(self) -> None:
        """Resets all headers and content for this response."""
        self._headers = httputil.HTTPHeaders(
            {
                "Server": "TornadoServer/%s" % tornado.version,
                "Content-Type": "text/html; charset=UTF-8",
                "Date": httputil.format_timestamp(time.time()),
            }
        )
        self.set_default_headers()
        self._write_buffer = []  # type: List[bytes]
        self._status_code = 200
        self._reason = httputil.responses[200] 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:15,代码来源:web.py

示例10: _convert_header_value

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def _convert_header_value(self, value: _HeaderTypes) -> str:
        # Convert the input value to a str. This type check is a bit
        # subtle: The bytes case only executes on python 3, and the
        # unicode case only executes on python 2, because the other
        # cases are covered by the first match for str.
        if isinstance(value, str):
            retval = value
        elif isinstance(value, bytes):  # py3
            # Non-ascii characters in headers are not well supported,
            # but if you pass bytes, use latin1 so they pass through as-is.
            retval = value.decode("latin1")
        elif isinstance(value, unicode_type):  # py2
            # TODO: This is inconsistent with the use of latin1 above,
            # but it's been that way for a long time. Should it change?
            retval = escape.utf8(value)
        elif isinstance(value, numbers.Integral):
            # return immediately since we know the converted value will be safe
            return str(value)
        elif isinstance(value, datetime.datetime):
            return httputil.format_timestamp(value)
        else:
            raise TypeError("Unsupported header value %r" % value)
        # If \n is allowed into the header, it is possible to inject
        # additional headers or split the request.
        if RequestHandler._INVALID_HEADER_CHAR_RE.search(retval):
            raise ValueError("Unsafe header value %r", retval)
        return retval 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:29,代码来源:web.py

示例11: test_if_modified_since

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def test_if_modified_since(self):
        http_date = datetime.datetime.utcnow()
        request = HTTPRequest("http://example.com", if_modified_since=http_date)
        self.assertEqual(
            request.headers, {"If-Modified-Since": format_timestamp(http_date)}
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:8,代码来源:httpclient_test.py

示例12: set_cookie

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def set_cookie(self, name, value, domain=None, expires=None, path="/",
                   expires_days=None, **kwargs):
        """Sets the given cookie name/value with the given options.

        Additional keyword arguments are set on the Cookie.Morsel
        directly.
        See http://docs.python.org/library/cookie.html#morsel-objects
        for available attributes.
        """
        # The cookie library only accepts type str, in both python 2 and 3
        name = escape.native_str(name)
        value = escape.native_str(value)
        if re.search(r"[\x00-\x20]", name + value):
            # Don't let us accidentally inject bad stuff
            raise ValueError("Invalid cookie %r: %r" % (name, value))
        if not hasattr(self, "_new_cookie"):
            self._new_cookie = Cookie.SimpleCookie()
        if name in self._new_cookie:
            del self._new_cookie[name]
        self._new_cookie[name] = value
        morsel = self._new_cookie[name]
        if domain:
            morsel["domain"] = domain
        if expires_days is not None and not expires:
            expires = datetime.datetime.utcnow() + datetime.timedelta(
                days=expires_days)
        if expires:
            morsel["expires"] = httputil.format_timestamp(expires)
        if path:
            morsel["path"] = path
        for k, v in kwargs.items():
            if k == 'max_age':
                k = 'max-age'
            morsel[k] = v 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:36,代码来源:web.py

示例13: test_static_if_modified_since_time_zone

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def test_static_if_modified_since_time_zone(self):
        # Instead of the value from Last-Modified, make requests with times
        # chosen just before and after the known modification time
        # of the file to ensure that the right time zone is being used
        # when parsing If-Modified-Since.
        stat = os.stat(relpath('static/robots.txt'))

        response = self.fetch('/static/robots.txt', headers={
            'If-Modified-Since': format_timestamp(stat.st_mtime - 1)})
        self.assertEqual(response.code, 200)
        response = self.fetch('/static/robots.txt', headers={
            'If-Modified-Since': format_timestamp(stat.st_mtime + 1)})
        self.assertEqual(response.code, 304) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:15,代码来源:web_test.py

示例14: check

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def check(self, value):
        self.assertEqual(format_timestamp(value), self.EXPECTED) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:4,代码来源:httputil_test.py

示例15: clear

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import format_timestamp [as 别名]
def clear(self):
        """Resets all headers and content for this response."""
        self._headers = httputil.HTTPHeaders({
            "Server": "TornadoServer/%s" % tornado.version,
            "Content-Type": "text/html; charset=UTF-8",
            "Date": httputil.format_timestamp(time.time()),
        })
        self.set_default_headers()
        self._write_buffer = []
        self._status_code = 200
        self._reason = httputil.responses[200] 
开发者ID:tp4a,项目名称:teleport,代码行数:13,代码来源:web.py


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