<s> import Cookie <EOL> import logging <EOL> import os <EOL> def get_cookie_value ( key ) : <EOL> cookies = None <EOL> try : <EOL> cookies = Cookie . BaseCookie ( os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> except Cookie . CookieError , error : <EOL> logging . debug ( "<STR_LIT>" % error ) <EOL> if not cookies : <EOL> return None <EOL> cookie = cookies . get ( key ) <EOL> if not cookie : <EOL> return None <EOL> return cookie . value <EOL> def set_cookie_value ( key , value = '<STR_LIT>' , max_age = None , <EOL> path = '<STR_LIT:/>' , domain = None , secure = None , httponly = False , <EOL> version = None , comment = None ) : <EOL> cookies = Cookie . BaseCookie ( ) <EOL> cookies [ key ] = value <EOL> for var_name , var_value in [ <EOL> ( '<STR_LIT>' , max_age ) , <EOL> ( '<STR_LIT:path>' , path ) , <EOL> ( '<STR_LIT>' , domain ) , <EOL> ( '<STR_LIT>' , secure ) , <EOL> ( '<STR_LIT:version>' , version ) , <EOL> ( '<STR_LIT>' , comment ) , <EOL> ] : <EOL> if var_value is not None and var_value is not False : <EOL> cookies [ key ] [ var_name ] = str ( var_value ) <EOL> if max_age is not None : <EOL> cookies [ key ] [ '<STR_LIT>' ] = max_age <EOL> cookies_header = cookies [ key ] . output ( header = '<STR_LIT>' ) . lstrip ( ) <EOL> if httponly : <EOL> cookies_header += "<STR_LIT>" <EOL> return cookies_header </s>
