<s> WEB_DRIVER_COOKIE_KEYS_MAP = { <EOL> '<STR_LIT:name>' : '<STR_LIT:name>' , <EOL> '<STR_LIT:value>' : '<STR_LIT:value>' , <EOL> '<STR_LIT:path>' : '<STR_LIT:path>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> def _to_unicode_if_str ( s ) : <EOL> if isinstance ( s , str ) : <EOL> try : <EOL> return s . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError : <EOL> return s . decode ( '<STR_LIT>' ) <EOL> else : <EOL> return s <EOL> def convert_cookie_to_dict ( cookie , keys_map = WEB_DRIVER_COOKIE_KEYS_MAP ) : <EOL> """<STR_LIT>""" <EOL> cookie_dict = dict ( ) <EOL> for k in keys_map . keys ( ) : <EOL> key = _to_unicode_if_str ( keys_map [ k ] ) <EOL> value = _to_unicode_if_str ( getattr ( cookie , k ) ) <EOL> cookie_dict [ key ] = value <EOL> return cookie_dict <EOL> def add_cookies_to_web_driver ( driver , cookies ) : <EOL> """<STR_LIT>""" <EOL> for cookie in cookies : <EOL> driver . add_cookie ( convert_cookie_to_dict ( cookie ) ) <EOL> return driver </s>
