cubicweb/web/request.py
changeset 12542 85194bd49119
parent 12503 b01dd0ef43aa
child 12567 26744ad37953
equal deleted inserted replaced
12541:bbbccb0b3a66 12542:85194bd49119
    21 import random
    21 import random
    22 import base64
    22 import base64
    23 from hashlib import sha1  # pylint: disable=E0611
    23 from hashlib import sha1  # pylint: disable=E0611
    24 from calendar import timegm
    24 from calendar import timegm
    25 from datetime import date, datetime
    25 from datetime import date, datetime
    26 from warnings import warn
       
    27 from io import BytesIO
    26 from io import BytesIO
    28 
    27 
    29 from six import PY2, text_type, string_types
    28 from six import PY2, text_type, string_types
    30 from six.moves import http_client
    29 from six.moves import http_client
    31 from six.moves.urllib.parse import urlsplit, quote as urlquote
    30 from six.moves.urllib.parse import urlsplit, quote as urlquote
   459 
   458 
   460         by default, cookie will be available for the next 5 minutes.
   459         by default, cookie will be available for the next 5 minutes.
   461         Give maxage = None to have a "session" cookie expiring when the
   460         Give maxage = None to have a "session" cookie expiring when the
   462         client close its browser
   461         client close its browser
   463         """
   462         """
   464         if isinstance(name, SimpleCookie):
       
   465             warn('[3.13] set_cookie now takes name and value as two first '
       
   466                  'argument, not anymore cookie object and name',
       
   467                  DeprecationWarning, stacklevel=2)
       
   468             secure = name[value]['secure']
       
   469             name, value = value, name[value].value
       
   470         if maxage: # don't check is None, 0 may be specified
   463         if maxage: # don't check is None, 0 may be specified
   471             assert expires is None, 'both max age and expires cant be specified'
   464             assert expires is None, 'both max age and expires cant be specified'
   472             expires = maxage + time.time()
   465             expires = maxage + time.time()
   473         elif expires:
   466         elif expires:
   474             # we don't want to handle times before the EPOCH (cause bug on
   467             # we don't want to handle times before the EPOCH (cause bug on
   481         # make sure cookie is set on the correct path
   474         # make sure cookie is set on the correct path
   482         cookie = Cookie(str(name), str(value), self.base_url_path(),
   475         cookie = Cookie(str(name), str(value), self.base_url_path(),
   483                         expires=expires, secure=secure, httponly=httponly)
   476                         expires=expires, secure=secure, httponly=httponly)
   484         self.headers_out.addHeader('Set-cookie', cookie)
   477         self.headers_out.addHeader('Set-cookie', cookie)
   485 
   478 
   486     def remove_cookie(self, name, bwcompat=None):
   479     def remove_cookie(self, name):
   487         """remove a cookie by expiring it"""
   480         """remove a cookie by expiring it"""
   488         if bwcompat is not None:
       
   489             warn('[3.13] remove_cookie now take only a name as argument',
       
   490                  DeprecationWarning, stacklevel=2)
       
   491             name = bwcompat
       
   492         self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
   481         self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
   493 
   482 
   494     def set_content_type(self, content_type, filename=None, encoding=None,
   483     def set_content_type(self, content_type, filename=None, encoding=None,
   495                          disposition='inline'):
   484                          disposition='inline'):
   496         """set output content type for this request. An optional filename
   485         """set output content type for this request. An optional filename