当前位置: 首页>>代码示例>>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;未经允许,请勿转载。