當前位置: 首頁>>代碼示例>>Python>>正文


Python cookie.SimpleCookie方法代碼示例

本文整理匯總了Python中django.http.cookie.SimpleCookie方法的典型用法代碼示例。如果您正苦於以下問題:Python cookie.SimpleCookie方法的具體用法?Python cookie.SimpleCookie怎麽用?Python cookie.SimpleCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.http.cookie的用法示例。


在下文中一共展示了cookie.SimpleCookie方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def __init__(self, content_type=None, status=None, reason=None, charset=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        self.cookies = SimpleCookie()
        self.closed = False
        if status is not None:
            self.status_code = status
        if reason is not None:
            self.reason_phrase = reason
        elif self.reason_phrase is None:
            self.reason_phrase = REASON_PHRASES.get(self.status_code,
                                                    'UNKNOWN STATUS CODE')
        self._charset = charset
        if content_type is None:
            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                               self.charset)
        self['Content-Type'] = content_type 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:25,代碼來源:response.py

示例2: __init__

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def __init__(self, content_type=None, status=None, reason=None, charset=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        self.cookies = SimpleCookie()
        self.closed = False
        if status is not None:
            try:
                self.status_code = int(status)
            except (ValueError, TypeError):
                raise TypeError('HTTP status code must be an integer.')

            if not 100 <= self.status_code <= 599:
                raise ValueError('HTTP status code must be an integer from 100 to 599.')
        self._reason_phrase = reason
        self._charset = charset
        if content_type is None:
            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                               self.charset)
        self['Content-Type'] = content_type 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:27,代碼來源:response.py

示例3: __init__

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def __init__(self, content_type=None, status=None, mimetype=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._charset = settings.DEFAULT_CHARSET
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        if mimetype:
            warnings.warn("Using mimetype keyword argument is deprecated, use"
                          " content_type instead", PendingDeprecationWarning)
            content_type = mimetype
        if not content_type:
            content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
                    self._charset)
        self.cookies = SimpleCookie()
        if status:
            self.status_code = status

        self['Content-Type'] = content_type 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:24,代碼來源:response.py

示例4: __init__

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def __init__(self, content_type=None, status=None, reason=None, charset=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        self.cookies = SimpleCookie()
        self.closed = False
        if status is not None:
            self.status_code = status
        self._reason_phrase = reason
        self._charset = charset
        if content_type is None:
            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                               self.charset)
        self['Content-Type'] = content_type 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:21,代碼來源:response.py

示例5: request_started_handler

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def request_started_handler(sender, environ, **kwargs):
    if not should_log_url(environ['PATH_INFO']):
        return

    # try and get the user from the request; commented for now, may have a bug in this flow.
    # user = get_current_user()
    user = None
    # get the user from cookies
    if not user and environ.get('HTTP_COOKIE'):
        cookie = SimpleCookie() # python3 compatibility
        cookie.load(environ['HTTP_COOKIE'])

        session_cookie_name = settings.SESSION_COOKIE_NAME
        if session_cookie_name in cookie:
            session_id = cookie[session_cookie_name].value

            try:
                session = Session.objects.get(session_key=session_id)
            except Session.DoesNotExist:
                session = None

            if session:
                user_id = session.get_decoded().get('_auth_user_id')
                try:
                    user = get_user_model().objects.get(id=user_id)
                except:
                    user = None

    request_event = audit_logger.request({
        'url': environ['PATH_INFO'],
        'method': environ['REQUEST_METHOD'],
        'query_string': environ['QUERY_STRING'],
        'user_id': getattr(user, 'id', None),
        'remote_ip': environ[REMOTE_ADDR_HEADER],
        'datetime': timezone.now()
    }) 
開發者ID:soynatan,項目名稱:django-easy-audit,代碼行數:38,代碼來源:request_signals.py

示例6: __getstate__

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def __getstate__(self):
        # SimpleCookie is not pickeable with pickle.HIGHEST_PROTOCOL, so we
        # serialise to a string instead
        state = self.__dict__.copy()
        state['cookies'] = str(state['cookies'])
        return state 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:8,代碼來源:response.py

示例7: __setstate__

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def __setstate__(self, state):
        self.__dict__.update(state)
        self.cookies = SimpleCookie(self.cookies) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:5,代碼來源:response.py

示例8: test_transaction_request_response_data

# 需要導入模塊: from django.http import cookie [as 別名]
# 或者: from django.http.cookie import SimpleCookie [as 別名]
def test_transaction_request_response_data(django_elasticapm_client, client):
    client.cookies = SimpleCookie({"foo": "bar"})
    with override_settings(
        **middleware_setting(django.VERSION, ["elasticapm.contrib.django.middleware.TracingMiddleware"])
    ):
        client.get(reverse("elasticapm-no-error"))
    transactions = django_elasticapm_client.events[TRANSACTION]
    assert len(transactions) == 1
    transaction = transactions[0]
    assert transaction["result"] == "HTTP 2xx"
    assert "request" in transaction["context"]
    request = transaction["context"]["request"]
    assert request["method"] == "GET"
    assert "headers" in request
    headers = request["headers"]
    # cookie serialization in the test client changed in Django 2.2, see
    # https://code.djangoproject.com/ticket/29576
    assert headers["cookie"] in (" foo=bar", "foo=bar")
    env = request["env"]
    assert "SERVER_NAME" in env, env.keys()
    assert env["SERVER_NAME"] == "testserver"
    assert "SERVER_PORT" in env, env.keys()
    assert env["SERVER_PORT"] == "80"

    assert "response" in transaction["context"]
    response = transaction["context"]["response"]
    assert response["status_code"] == 200
    if "my-header" in response["headers"]:
        # Django >= 2
        assert response["headers"]["my-header"] == "foo"
    else:
        assert response["headers"]["My-Header"] == "foo" 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:34,代碼來源:django_tests.py


注:本文中的django.http.cookie.SimpleCookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。