From: Kenneth Reitz Date: Sat, 20 Aug 2011 23:58:00 +0000 (-0400) Subject: docstrings for utils module X-Git-Tag: v0.8.0~94^2~144 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=873d128c5a75bb862a6a857c9a72aa7c916659af;p=services%2Fpython-requests.git docstrings for utils module --- diff --git a/requests/utils.py b/requests/utils.py index beed3c1..0f6e842 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -15,12 +15,15 @@ import re import zlib -def dict_from_cookiejar(cookiejar): - """Returns a key/value dictionary from a CookieJar.""" +def dict_from_cookiejar(cj): + """Returns a key/value dictionary from a CookieJar. + + :param cj: CookieJar object to extract cookies from. + """ cookie_dict = {} - for _, cookies in cookiejar._cookies.items(): + for _, cookies in cj._cookies.items(): for _, cookies in cookies.items(): for cookie in cookies.values(): # print cookie @@ -30,7 +33,10 @@ def dict_from_cookiejar(cookiejar): def cookiejar_from_dict(cookie_dict): - """Returns a CookieJar from a key/value dictionary.""" + """Returns a CookieJar from a key/value dictionary. + + :param cookie_dict: Dict of key/values to insert into CookieJar. + """ # return cookiejar if one was passed in if isinstance(cookie_dict, cookielib.CookieJar): @@ -45,7 +51,11 @@ def cookiejar_from_dict(cookie_dict): def add_dict_to_cookiejar(cj, cookie_dict): - """Returns a CookieJar from a key/value dictionary.""" + """Returns a CookieJar from a key/value dictionary. + + :param cj: CookieJar to insert cookies into. + :param cookie_dict: Dict of key/values to insert into CookieJar. + """ for k, v in cookie_dict.items(): @@ -76,7 +86,10 @@ def add_dict_to_cookiejar(cj, cookie_dict): def get_encodings_from_content(content): - """Returns encodings from given content string.""" + """Returns encodings from given content string. + + :param content: bytestring to extract encodings from. + """ charset_re = re.compile(r']', flags=re.I) @@ -85,7 +98,10 @@ def get_encodings_from_content(content): def get_encoding_from_headers(headers): - """Returns encodings from given HTTP Header Dict.""" + """Returns encodings from given HTTP Header Dict. + + :param headers: dictionary to extract encoding from. + """ content_type = headers.get('content-type') content_type, params = cgi.parse_header(content_type) @@ -97,6 +113,8 @@ def get_encoding_from_headers(headers): def get_unicode_from_response(r): """Returns the requested content back in unicode. + :param r: Reponse object to get unicode content from. + Tried: 1. charset from content-type 2. every encodings from @@ -135,6 +153,9 @@ def get_unicode_from_response(r): def decode_gzip(content): - """Return gzip-decoded string.""" + """Return gzip-decoded string. + + :param content: bytestring to gzip-decode. + """ return zlib.decompress(content, 16+zlib.MAX_WBITS) \ No newline at end of file