本文整理匯總了Python中django.http.SimpleCookie方法的典型用法代碼示例。如果您正苦於以下問題:Python http.SimpleCookie方法的具體用法?Python http.SimpleCookie怎麽用?Python http.SimpleCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.http
的用法示例。
在下文中一共展示了http.SimpleCookie方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: logout
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def logout(self):
"""
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
"""
from django.contrib.auth import get_user, logout
request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
if self.session:
request.session = self.session
request.user = get_user(request)
else:
request.session = engine.SessionStore()
logout(request)
self.cookies = SimpleCookie()
示例2: __init__
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def __init__(self, **defaults):
self.defaults = defaults
self.cookies = SimpleCookie()
self.errors = BytesIO()
示例3: _store
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
"""
Stores the messages to a cookie, returning a list of any messages which
could not be stored.
If the encoded data is larger than ``max_cookie_size``, removes
messages until the data fits (these are the messages which are
returned), and add the not_finished sentinel value to indicate as much.
"""
unstored_messages = []
encoded_data = self._encode(messages)
if self.max_cookie_size:
# data is going to be stored eventually by SimpleCookie, which
# adds its own overhead, which we must account for.
cookie = SimpleCookie() # create outside the loop
def stored_length(val):
return len(cookie.value_encode(val)[1])
while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
if remove_oldest:
unstored_messages.append(messages.pop(0))
else:
unstored_messages.insert(0, messages.pop())
encoded_data = self._encode(messages + [self.not_finished],
encode_empty=unstored_messages)
self._update_cookie(encoded_data, response)
return unstored_messages
示例4: logout
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def logout(self):
"""Log out the user by removing the cookies and session object."""
from django.contrib.auth import get_user, logout
request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
if self.session:
request.session = self.session
request.user = get_user(request)
else:
request.session = engine.SessionStore()
logout(request)
self.cookies = SimpleCookie()
示例5: _store
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def _store(self, messages, response, remove_oldest=True, *args, **kwargs):
"""
Store the messages to a cookie and return a list of any messages which
could not be stored.
If the encoded data is larger than ``max_cookie_size``, remove
messages until the data fits (these are the messages which are
returned), and add the not_finished sentinel value to indicate as much.
"""
unstored_messages = []
encoded_data = self._encode(messages)
if self.max_cookie_size:
# data is going to be stored eventually by SimpleCookie, which
# adds its own overhead, which we must account for.
cookie = SimpleCookie() # create outside the loop
def stored_length(val):
return len(cookie.value_encode(val)[1])
while encoded_data and stored_length(encoded_data) > self.max_cookie_size:
if remove_oldest:
unstored_messages.append(messages.pop(0))
else:
unstored_messages.insert(0, messages.pop())
encoded_data = self._encode(messages + [self.not_finished],
encode_empty=unstored_messages)
self._update_cookie(encoded_data, response)
return unstored_messages
示例6: __init__
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def __init__(self, *, json_encoder=DjangoJSONEncoder, **defaults):
self.json_encoder = json_encoder
self.defaults = defaults
self.cookies = SimpleCookie()
self.errors = BytesIO()
示例7: logout
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def logout(self):
"""
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
"""
session = import_module(settings.SESSION_ENGINE).SessionStore()
session_cookie = self.cookies.get(settings.SESSION_COOKIE_NAME)
if session_cookie:
session.delete(session_key=session_cookie.value)
self.cookies = SimpleCookie()
示例8: simulate_simple_authentication
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def simulate_simple_authentication(factory, client, email, password, path, add_messages_middleware, views):
auth_request = factory.post('/sessions/')
add_messages_middleware(auth_request)
auth_response = views.sessions_index(auth_request,
email=email,
password=password,
path=path)
# Add auth token cookie to request
auth_token = auth_response.cookies['auth_token'].value
client.cookies = SimpleCookie({'auth_token': auth_token})
示例9: setUp
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def setUp(self):
self.factory = RequestFactory()
self.client = Client()
self.route_name = 'app:update_dd_info'
self.route = '/users/55/pay/update_dd_info'
self.view = pay.update_dd_info
self.responses = {
'exists': 200,
'GET': 405,
'POST': 200,
'PUT': 405,
'PATCH': 405,
'DELETE': 405,
'HEAD': 405,
'OPTIONS': 405,
'TRACE': 405
}
self.kwargs = {'user_id': 55}
self.expected_response_content = 'Update dd info for user 55'
AuthRouteTestingWithKwargs.__init__(self)
input_iv = binascii.hexlify(Random.new().read(8))
km_input_create_date = timezone.now()
km_input_update_date = timezone.now()
self.key_model = KeyManagement.objects.create(
iv=input_iv, user=self.mixin_model,
created_at=km_input_create_date,
updated_at=km_input_update_date
)
self.client.cookies = SimpleCookie({'auth_token': self.mixin_model.auth_token})
# Override
示例10: setUp
# 需要導入模塊: from django import http [as 別名]
# 或者: from django.http import SimpleCookie [as 別名]
def setUp(self):
# Create User Model
input_email = "ryan.dens@example.com"
input_password = "12345"
input_admin = False
input_first_name = "Ryan"
input_last_name = "Dens"
u_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 1, 0, 0))
u_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 3, 0, 0))
self.user = User.objects.create(
email=input_email, password=input_password,
is_admin=input_admin, first_name=input_first_name,
last_name=input_last_name, created_at=u_input_create_date,
updated_at=u_input_update_date
)
self.route = "/users/" + str(self.user.id) + "/work_info"
# Create WorkInfo Model
input_income = "fun"
input_bonuses = "birthday"
input_years_worked = 10
input_ssn = "111-22-3333"
input_encrypted_ssn = "random_chars".encode("utf-8")
input_dob = datetime.date(1996, 7, 31)
perf_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 4, 0, 0))
perf_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 5, 0, 0))
self.model = WorkInfo.objects.create(
income=input_income,
bonuses=input_bonuses,
years_worked=input_years_worked,
SSN=input_ssn,
encrypted_ssn=input_encrypted_ssn,
DoB=input_dob,
created_at=perf_input_create_date,
updated_at=perf_input_update_date,
user=self.user,
)
input_iv = binascii.hexlify(Random.new().read(8))
km_input_create_date = pytz.utc.localize(datetime.datetime(2017, 6, 4, 0, 0))
km_input_update_date = pytz.utc.localize(datetime.datetime(2017, 6, 5, 0, 0))
self.key_model = KeyManagement.objects.create(
iv=input_iv, user=self.user,
created_at=km_input_create_date,
updated_at=km_input_update_date
)
self.client = Client()
self.client.cookies = SimpleCookie({'auth_token': self.user.auth_token})