def resolve_value_of_cookies(element):
""" This function evaluates user input for cookies. If a file path is given,
then a cookiejar object is created and the contents of the file are loaded
into the object. This object is then returned.
Else, a dictionary would be created out of the string given
input = "foo=foo1; bar=bar1; ; =foobar; barfoo="
return value = {'foo': 'foo1', 'bar': 'bar1'}
If the dictionary is empty at the end of the function, None is retuened.
"""
if element is not None and element is not False and element != "":
abs_path = file_Utils.getAbsPath(element, sys.path[0])
if os.path.exists(abs_path):
element = cookielib.LWPCookieJar(element)
try:
element.load()
except cookielib.LoadError:
pNote("Cookies could not be loaded from {}.".format(element),
"error")
element = None
except Exception as e:
pNote("An Error Occurred: {0}".format(e), "error")
else:
element = convert_string_to_dict(element)
else:
element = None
return element
评论列表
文章目录