當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。