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


Python http.http_date方法代码示例

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


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

示例1: default

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def default(self, o):
        """Implement this method in a subclass such that it returns a
        serializable object for ``o``, or calls the base implementation (to
        raise a :exc:`TypeError`).

        For example, to support arbitrary iterators, you could implement
        default like this::

            def default(self, o):
                try:
                    iterable = iter(o)
                except TypeError:
                    pass
                else:
                    return list(iterable)
                return JSONEncoder.default(self, o)
        """
        if isinstance(o, date):
            return http_date(o.timetuple())
        if isinstance(o, uuid.UUID):
            return str(o)
        if hasattr(o, '__html__'):
            return text_type(o.__html__())
        return _json.JSONEncoder.default(self, o) 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:json.py

示例2: _tag

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def _tag(value):
    if isinstance(value, tuple):
        return {' t': [_tag(x) for x in value]}
    elif isinstance(value, uuid.UUID):
        return {' u': value.hex}
    elif isinstance(value, bytes):
        return {' b': b64encode(value).decode('ascii')}
    elif callable(getattr(value, '__html__', None)):
        return {' m': text_type(value.__html__())}
    elif isinstance(value, list):
        return [_tag(x) for x in value]
    elif isinstance(value, datetime):
        return {' d': http_date(value)}
    elif isinstance(value, dict):
        return dict((k, _tag(v)) for k, v in iteritems(value))
    elif isinstance(value, str):
        try:
            return text_type(value)
        except UnicodeError:
            from flask.debughelpers import UnexpectedUnicodeError
            raise UnexpectedUnicodeError(u'A byte string with '
                u'non-ASCII data was passed to the session system '
                u'which can only store unicode strings.  Consider '
                u'base64 encoding your string (String was %r)' % value)
    return value 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:sessions.py

示例3: sign_headers

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def sign_headers(u, headers):
    """
    """
    key_id = u['publicKey']['@id']
    secret = u['privateKey']

    hs = HeaderSigner(key_id, secret, algorithm='rsa-sha256')
    auth = hs.sign({"Date": http_date()})

    # thanks to https://github.com/snarfed for the authorization -> signature headers hack
    # this is necessary because httpsig.HeaderSigner returns an Authorization header instead of Signature
    auth['Signature'] = auth.pop('authorization')
    assert auth['Signature'].startswith('Signature ')
    auth['Signature'] = auth['Signature'][len('Signature '):]

    auth.update(headers)
    auth.update(DEFAULT_HEADERS)

    return auth 
开发者ID:rowanlupton,项目名称:pylodon,代码行数:21,代码来源:utilities.py

示例4: default

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def default(self, o):
        """Implement this method in a subclass such that it returns a
        serializable object for ``o``, or calls the base implementation (to
        raise a ``TypeError``).

        For example, to support arbitrary iterators, you could implement
        default like this::

            def default(self, o):
                try:
                    iterable = iter(o)
                except TypeError:
                    pass
                else:
                    return list(iterable)
                return JSONEncoder.default(self, o)
        """
        if isinstance(o, datetime):
            return http_date(o)
        if isinstance(o, uuid.UUID):
            return str(o)
        if hasattr(o, '__html__'):
            return text_type(o.__html__())
        return _json.JSONEncoder.default(self, o) 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:26,代码来源:json.py

示例5: test_list_tokens

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def test_list_tokens(client, auth, test_admin):
    uid, uname, upass = test_admin
    # Log in first
    response, csrf_cookie = auth.login(uname, upass)
    response = client.get("/tokens/tokens", headers={"X-CSRF-Token": csrf_cookie})
    assert 200 == response.status_code  # Should get an OK
    result = response.get_json()

    assert [
        {
            "id": 1,
            "name": "DUMMY_TOKEN",
            "token": "DUMMY_TOKEN_STRING",
            "expires": http_date(
                (
                    datetime.datetime.now().date() + datetime.timedelta(days=1)
                ).timetuple()
            ),
            "server_name": "DUMMY_SERVER_B",
            "username": "TEST_ADMIN",
        }
    ] == result 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:24,代码来源:test_user_views.py

示例6: test_group_server_time_limits

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def test_group_server_time_limits(client, auth, test_admin, test_group):
    uid, uname, upass = test_admin
    response, csrf_cookie = auth.login(uname, upass)
    response = client.get(
        f"/admin/groups/{test_group.id}/servers/1/time_limits",
        headers={"X-CSRF-Token": csrf_cookie},
    )

    assert 200 == response.status_code
    json = response.get_json()
    assert 2 == json["longest_token_life"]
    assert (
        http_date(
            (datetime.datetime.now().date() + datetime.timedelta(days=365)).timetuple()
        )
        == json["latest_token_expiry"]
    ) 
开发者ID:Flowminder,项目名称:FlowKit,代码行数:19,代码来源:test_server_admin.py

示例7: dumps

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def dumps(self, value):
        def _tag(value):
            if isinstance(value, tuple):
                return {' t': [_tag(x) for x in value]}
            elif isinstance(value, uuid.UUID):
                return {' u': value.hex}
            elif callable(getattr(value, '__html__', None)):
                return {' m': text_type(value.__html__())}
            elif isinstance(value, list):
                return [_tag(x) for x in value]
            elif isinstance(value, datetime):
                return {' d': http_date(value)}
            elif isinstance(value, dict):
                return dict((k, _tag(v)) for k, v in iteritems(value))
            elif isinstance(value, str):
                try:
                    return text_type(value)
                except UnicodeError:
                    raise UnexpectedUnicodeError(u'A byte string with '
                        u'non-ASCII data was passed to the session system '
                        u'which can only store unicode strings.  Consider '
                        u'base64 encoding your string (String was %r)' % value)
            return value
        return json.dumps(_tag(value), separators=(',', ':')) 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:26,代码来源:sessions.py

示例8: test_info

# 需要导入模块: from werkzeug import http [as 别名]
# 或者: from werkzeug.http import http_date [as 别名]
def test_info(self):
        resp = self.client.get("/user-info")
        self.assertEqual(resp.json, {
            "user": None,
        })

        # With logged in user
        self.temporary_login(self.test_user_id)
        resp = self.client.get("/user-info")
        self.assertEqual(resp.json, {
            "user": {
                "id": self.test_user["id"],
                "created": http_date(self.test_user["created"]),
                "musicbrainz_id": self.test_user["musicbrainz_id"],
            },
        }) 
开发者ID:metabrainz,项目名称:acousticbrainz-server,代码行数:18,代码来源:test_user.py


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