#NEWLINE# def set_cookie( self , name , value , expires = None , max_age = None , domain = None , path = None , secure = True , http_only = True ) : #NEWLINE# #INDENT# 'Set a response cookie.\n\n        Note:\n            This method can be called multiple times to add one or\n            more cookies to the response.\n\n        See Also:\n            To learn more about setting cookies, see\n            :ref:`Setting Cookies <setting-cookies>`. The parameters listed\n            below correspond to those defined in `RFC 6265`_.\n\n        Args:\n            name (str):\n                Cookie name\n            value (str):\n                Cookie value\n            expires (datetime): Specifies when the cookie should expire. By\n                default, cookies expire when the user agent exits.\n            max_age (int): Defines the lifetime of the cookie in seconds.\n                After the specified number of seconds elapse, the client\n                should discard the cookie. Coercion to `int` is attempted\n                if provided with `float` or `str`.\n            domain (str): Specifies the domain for which the cookie is valid.\n                An explicitly specified domain must always start with a dot.\n                A value of 0 means the cookie should be discarded immediately.\n            path (str): Specifies the subset of URLs to\n                which this cookie applies.\n            secure (bool): Direct the client to only return the cookie in\n                subsequent requests if they are made over HTTPS\n                (default: ``True``). This prevents attackers from reading\n                sensitive cookie data. Note that for the `secure` cookie\n                attribute to be effective, your application will need to\n                enforce HTTPS. See also: `RFC 6265, Section 4.1.2.5`_.\n            http_only (bool): Direct the client to only transfer the cookie\n                with unscripted HTTP requests (default: ``True``). This is\n                intended to mitigate some forms of cross-site scripting.\n\n        Raises:\n            KeyError: `name` is not a valid cookie name.\n            ValueError: `value` is not a valid cookie value.\n\n        .. _RFC 6265:\n            http://tools.ietf.org/html/rfc6265\n\n        .. _RFC 6265, Section 4.1.2.5:\n            https://tools.ietf.org/html/rfc6265#section-4.1.2.5\n\n        ' #NEWLINE# if ( not is_ascii_encodable ( name ) ) : #NEWLINE# #INDENT# raise KeyError ( '"name" is not ascii encodable' ) #NEWLINE# #UNINDENT# if ( not is_ascii_encodable ( value ) ) : #NEWLINE# #INDENT# raise ValueError ( '"value" is not ascii encodable' ) #NEWLINE# #UNINDENT# if PY2 : #NEWLINE# #INDENT# name = str ( name ) #NEWLINE# value = str ( value ) #NEWLINE# #UNINDENT# if ( self . _cookies is None ) : #NEWLINE# #INDENT# self . _cookies = SimpleCookie ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . _cookies [ name ] = value #NEWLINE# #UNINDENT# except CookieError as e : #NEWLINE# #INDENT# raise KeyError ( str ( e ) ) #NEWLINE# #UNINDENT# if expires : #NEWLINE# #INDENT# fmt = '%a, %d %b %Y %H:%M:%S GMT' #NEWLINE# if ( expires . tzinfo is None ) : #NEWLINE# #INDENT# self . _cookies [ name ] [ 'expires' ] = expires . strftime ( fmt ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# gmt_expires = expires . astimezone ( GMT_TIMEZONE ) #NEWLINE# self . _cookies [ name ] [ 'expires' ] = gmt_expires . strftime ( value ) #NEWLINE# #UNINDENT# #UNINDENT# if max_age : #NEWLINE# #INDENT# self . _cookies [ name ] [ 'max-age' ] = int ( max_age ) #NEWLINE# #UNINDENT# if domain : #NEWLINE# #INDENT# self . _cookies [ name ] [ 'domain' ] = domain #NEWLINE# #UNINDENT# if path : #NEWLINE# #INDENT# self . _cookies [ name ] [ 'path' ] = path #NEWLINE# #UNINDENT# if secure : #NEWLINE# #INDENT# self . _cookies [ name ] [ 'secure' ] = secure #NEWLINE# #UNINDENT# if http_only : #NEWLINE# #INDENT# self . _cookies [ name ] [ 'httponly' ] = http_only