Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
ó
¸EYc@sHdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZddl
mZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!dd	l"m#Z#dd
l$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*d<Z+ej,ƒZ-ej.ƒdkr£d„Z/d„Znd„Z0d„Z1e2d„Z3d„Z4d„Z5d„Z6d„Z7d„Z8e2d„Z9d„Z:d„Z;d„Z<d„Z=d„Z>d„Z?d „Z@eAd!d"ƒZBd#„ZCd$„ZDd%„ZEd&„ZFd'„ZGd(„ZHejId)„ƒZJd*„ZKdd+„ZMd,„ZNd-d.„ZOd/„ZPd0„ZQd1jRd2ƒZSeSd3ZTeSd4ZUd5„ZVd6„ZWd7„ZXejYd8ƒZZejYd8ƒZ[d9„Z\d:„Z]d;„Z^dS(=s”
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
iÿÿÿÿNi(t__version__(tcerts(tto_native_string(tparse_http_list(tquoteturlparsetbyteststrtOrderedDicttunquotet
getproxiestproxy_bypasst
urlunparset
basestringt
integer_typestis_py3tproxy_bypass_environmenttgetproxies_environment(tcookiejar_from_dict(tCaseInsensitiveDict(t
InvalidURLt
InvalidHeadertFileModeWarningtUnrewindableBodyErrors.netrct_netrctWindowscCs"trddl}nddl}yE|j|jdƒ}|j|dƒd}|j|dƒd}Wntk
rztSX|s‰|rtS|jdƒ}x|D]w}|dkrÈd|krÈt	Sn|j
dd	ƒ}|j
d
dƒ}|j
ddƒ}tj||tj
ƒr£t	Sq£WtS(
Niÿÿÿÿs;Software\Microsoft\Windows\CurrentVersion\Internet SettingstProxyEnableit
ProxyOverridet;s<local>t.s\.t*s.*t?(Rtwinregt_winregtOpenKeytHKEY_CURRENT_USERtQueryValueExtOSErrortFalsetsplittTruetreplacetretmatchtI(thostR tinternetSettingstproxyEnablet
proxyOverridettest((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytproxy_bypass_registry-s2		
	

cCs!tƒrt|ƒSt|ƒSdS(sšReturn True, if the host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.
        N(RRR2(R-((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyRNs	
cCs"t|dƒr|jƒ}n|S(s/Returns an internal sequence dictionary update.titems(thasattrR3(td((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytdict_to_sequenceZscCsšd}d}t|dƒr*t|ƒ}nˆt|dƒrE|j}nmt|dƒr²y|jƒ}Wntjk
rzq²Xtj|ƒj}d|j	kr²t
jdtƒq²nt|dƒrty|j
ƒ}Wn,ttfk
rÿ|dk	rq|}qqqtXt|dƒrt|dkrty3|jdd	ƒ|j
ƒ}|j|pIdƒWqqttfk
rmd}qqXqtn|dkr‰d}ntd||ƒS(
Nit__len__tlentfilenotbs%Requests has determined the content-length for this request using the binary size of the file: however, the file has been opened in text mode (i.e. without the 'b' flag in the mode). This may lead to an incorrect content-length. In Requests 3.0, support will be removed for files in text mode.ttelltseeki(tNoneR4R8R9tiotUnsupportedOperationtostfstattst_sizetmodetwarningstwarnRR;R%tIOErrorR<tmax(tottotal_lengthtcurrent_positionR9((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyt	super_lencs@

	cCseyGddlm}m}d}x^tD]V}ytjjdj|ƒƒ}Wntk
r_dSXtjj	|ƒr&|}Pq&q&W|dkrdSt
|ƒ}d}t|tƒrÃ|j
dƒ}n|jj|ƒd}	yG||ƒj|	ƒ}
|
r|
drdnd}|
||
d	fSWn#|tfk
rE|rF‚qFnXWnttfk
r`nXdS(
s;Returns the Requests tuple auth for a given url from netrc.iÿÿÿÿ(tnetrctNetrcParseErrors~/{0}Nt:tasciiiii(RLRMR=tNETRC_FILESR@tpatht
expandusertformattKeyErrortexistsRt
isinstanceRtdecodetnetlocR'tauthenticatorsRFtImportErrortAttributeError(turltraise_errorsRLRMt
netrc_pathtftloctritsplitstrR-Rtlogin_i((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytget_netrc_auth s8

cCs[t|ddƒ}|rWt|tƒrW|ddkrW|ddkrWtjj|ƒSdS(s0Tries to guess the filename of the given object.tnameit<iÿÿÿÿt>N(tgetattrR=RVR
R@RQtbasename(tobjRe((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytguess_filenameÓs%cCsD|dkrdSt|ttttfƒr:tdƒ‚nt|ƒS(sÅTake an object and test to see if it can be represented as a
    dictionary. Unless it can not be represented as such, return an
    OrderedDict, e.g.,

    ::

        >>> from_key_val_list([('key', 'val')])
        OrderedDict([('key', 'val')])
        >>> from_key_val_list('string')
        ValueError: need more than 1 value to unpack
        >>> from_key_val_list({'key': 'val'})
        OrderedDict([('key', 'val')])

    :rtype: OrderedDict
    s+cannot encode objects that are not 2-tuplesN(R=RVRRtbooltintt
ValueErrorR(tvalue((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytfrom_key_val_listÛs
cCse|dkrdSt|ttttfƒr:tdƒ‚nt|tjƒr[|j	ƒ}nt
|ƒS(sŒTake an object and test to see if it can be represented as a
    dictionary. If it can be, return a list of tuples, e.g.,

    ::

        >>> to_key_val_list([('key', 'val')])
        [('key', 'val')]
        >>> to_key_val_list({'key': 'val'})
        [('key', 'val')]
        >>> to_key_val_list('string')
        ValueError: cannot encode objects that are not 2-tuples.

    :rtype: list
    s+cannot encode objects that are not 2-tuplesN(R=RVRRRlRmRntcollectionstMappingR3tlist(Ro((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytto_key_val_listôscCshg}x[t|ƒD]M}|d |dko8dknrSt|dd!ƒ}n|j|ƒqW|S(sParse lists as described by RFC 2068 Section 2.

    In particular, parse comma-separated lists where the elements of
    the list may include quoted-strings.  A quoted-string could
    contain a comma.  A non-quoted string could have quotes in the
    middle.  Quotes are removed automatically after parsing.

    It basically works like :func:`parse_set_header` just that items
    may appear multiple times and case sensitivity is preserved.

    The return value is a standard :class:`list`:

    >>> parse_list_header('token, "quoted value"')
    ['token', 'quoted value']

    To create a header from the :class:`list` again, use the
    :func:`dump_header` function.

    :param value: a string with a list header.
    :return: :class:`list`
    :rtype: list
    iiÿÿÿÿt"(t_parse_list_headertunquote_header_valuetappend(Rotresulttitem((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytparse_list_headers$cCs™i}xŒt|ƒD]~}d|kr5d||<qn|jddƒ\}}|d |dkoldknr‡t|dd!ƒ}n|||<qW|S(s^Parse lists of key, value pairs as described by RFC 2068 Section 2 and
    convert them into a python dict:

    >>> d = parse_dict_header('foo="is a fish", bar="as well"')
    >>> type(d) is dict
    True
    >>> sorted(d.items())
    [('bar', 'as well'), ('foo', 'is a fish')]

    If there is no value for a key it will be `None`:

    >>> parse_dict_header('key_without_value')
    {'key_without_value': None}

    To create a header from the :class:`dict` again, use the
    :func:`dump_header` function.

    :param value: a string with a dict header.
    :return: :class:`dict`
    :rtype: dict
    t=iiÿÿÿÿRuN(RvR=R'Rw(RoRyRzRe((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytparse_dict_header0s
$cCsq|rm|d|dko%dknrm|dd!}|sN|d dkrm|jddƒjddƒSn|S(	sçUnquotes a header value.  (Reversal of :func:`quote_header_value`).
    This does not use the real unquoting but what browsers are actually
    using for quoting.

    :param value: the header value to unquote.
    :rtype: str
    iiÿÿÿÿRuiis\\s\s\"(R)(Rotis_filename((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyRwSs
*
cCs+i}x|D]}|j||j<q
W|S(s€Returns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    (RoRe(tcjtcookie_dicttcookie((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytdict_from_cookiejarls
cCs
t||ƒS(sÂ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.
    :rtype: CookieJar
    (R(RR€((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytadd_dict_to_cookiejar{scCsvtjdtƒtjddtjƒ}tjddtjƒ}tjdƒ}|j|ƒ|j|ƒ|j|ƒS(slReturns encodings from given content string.

    :param content: bytestring to extract encodings from.
    s¤In requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)s!<meta.*?charset=["\']*(.+?)["\'>]tflagss+<meta.*?content=["\']*;?charset=(.+?)["\'>]s$^<\?xml.*?encoding=["\']*(.+?)["\'>](RDREtDeprecationWarningR*tcompileR,tfindall(tcontentt
charset_ret	pragma_retxml_re((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytget_encodings_from_content†scCs_|jdƒ}|sdStj|ƒ\}}d|krK|djdƒSd|kr[dSdS(s}Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    scontent-typetcharsets'"ttexts
ISO-8859-1N(tgetR=tcgitparse_headertstrip(theaderstcontent_typetparams((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytget_encoding_from_headersšsccs™|jdkr)x|D]}|VqWdStj|jƒddƒ}x+|D]#}|j|ƒ}|rK|VqKqKW|jddtƒ}|r•|VndS(sStream decodes a iterator.NterrorsR)ttfinal(tencodingR=tcodecstgetincrementaldecoderRWR((titeratortrRztdecodertchunktrv((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytstream_decode_response_unicode¯s
	
ccsdd}|dks|dkr-t|ƒ}nx0|t|ƒkr_||||!V||7}q0WdS(s Iterate over slices of a string.iN(R=R8(tstringtslice_lengthtpos((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytiter_slicesÁscCs™tjdtƒg}t|jƒ}|rcyt|j|ƒSWqctk
r_|j|ƒqcXnyt|j|ddƒSWnt	k
r”|jSXdS(sâReturns the requested content back in unicode.

    :param r: Response object to get unicode content from.

    Tried:

    1. charset from content-type
    2. fall back and replace all unicode characters

    :rtype: str
    s£In requests 3.0, get_unicode_from_response will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.)R—R)N(
RDRER…R–R“RRˆtUnicodeErrorRxt	TypeError(Ržttried_encodingsRš((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytget_unicode_from_responseËs

t4ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzs0123456789-._~cCsô|jdƒ}xÕtdt|ƒƒD]¾}||dd!}t|ƒdkrÑ|jƒrÑytt|dƒƒ}Wn!tk
r–td|ƒ‚nX|tkr¼|||d||<qãd||||<q%d||||<q%Wdj	|ƒS(s¨Un-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.

    :rtype: str
    t%iiiis%Invalid percent-escape sequence: '%s'R˜(
R'trangeR8tisalnumtchrRmRnRtUNRESERVED_SETtjoin(turitpartstithtc((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytunquote_unreservedôs
cCsKd}d}ytt|ƒd|ƒSWntk
rFt|d|ƒSXdS(s¬Re-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.

    :rtype: str
    s!#$%&'()*+,/:;=?@[]~s!#$&'()*+,/:;=?@[]~tsafeN(RR·R(R²tsafe_with_percenttsafe_without_percent((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytrequote_uris
cCs”tjdtj|ƒƒd}|jdƒ\}}tjdtjtt|ƒƒƒƒd}tjdtj|ƒƒd|@}||@||@kS(sïThis function allows you to check if an IP belongs to a network subnet

    Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
             returns False if ip = 192.168.1.1 and net = 192.168.100.0/24

    :rtype: bool
    s=Lit/(tstructtunpacktsockett	inet_atonR'tdotted_netmaskRm(tiptnettipaddrtnetaddrtbitstnetmasktnetwork((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytaddress_in_network"s
+#cCs/ddd|>dA}tjtjd|ƒƒS(sConverts mask from /xx format to xxx.xxx.xxx.xxx

    Example: if mask is 24 function returns 255.255.255.0

    :rtype: str
    Iÿÿÿÿii s>I(R¿t	inet_ntoaR½tpack(tmaskRÆ((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyRÁ1scCs-ytj|ƒWntjk
r(tSXtS(s
    :rtype: bool
    (R¿RÀterrorR&R((t	string_ip((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytis_ipv4_address<s
cCs¤|jdƒdkrœyt|jdƒdƒ}Wntk
rFtSX|dks_|dkrctSytj|jdƒdƒWq tjk
r˜tSXntStS(sV
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    R¼ii i(	tcountRmR'RnR&R¿RÀRÍR((tstring_networkRÌ((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyt
is_valid_cidrGs
ccst|dk	}|r4tjj|ƒ}|tj|<nz	dVWd|ro|dkr_tj|=qo|tj|<nXdS(sÎSet the environment variable 'env_name' to 'value'

    Save previous value, yield, and then restore the previous value stored in
    the environment variable 'env_name'.

    If 'value' is None, do nothingN(R=R@tenvironR(tenv_nameRot
value_changedt	old_value((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytset_environ_s	
c	
Cscd„}|}|d	kr*|dƒ}nt|ƒj}|rd„|jddƒjdƒDƒ}|jdƒd}t|ƒrÉxƒ|D]8}t|ƒr²t||ƒrÂtSqŠ||krŠtSqŠWqx@|D]5}|j	|ƒs|jdƒdj	|ƒrÐtSqÐWnt
d|ƒ8yt|ƒ}Wn tt
jfk
rNt}nXWd	QX|r_tStS(
sL
    Returns whether we should bypass proxies or not.

    :rtype: bool
    cSs(tjj|ƒp'tjj|jƒƒS(N(R@RÓRtupper(tk((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyt<lambda>{stno_proxycss|]}|r|VqdS(N((t.0R-((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pys	<genexpr>ˆst R˜t,RNiN(R=RRXR)R'RÏRÒRÉR(tendswithR×RR¨R¿tgaierrorR&(	R\RÛt	get_proxytno_proxy_argRXRÂtproxy_ipR-tbypass((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytshould_bypass_proxiesus4	%

+cCs!t|d|ƒriStƒSdS(sA
    Return a dict of environment proxies.

    :rtype: dict
    RÛN(RåR
(R\RÛ((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytget_environ_proxies®scCs¢|p	i}t|ƒ}|jdkrC|j|j|jdƒƒS|jd|j|jd|jdg}d}x(|D] }||krz||}PqzqzW|S(s­Select a proxy for the url, if applicable.

    :param url: The url being for the request
    :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
    talls://sall://N(RthostnameR=Rtscheme(R\tproxiesturlpartst
proxy_keystproxyt	proxy_key((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytselect_proxyºs
	

spython-requestscCsd|tfS(sO
    Return a string representing the default user agent.

    :rtype: str
    s%s/%s(R(Re((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytdefault_user_agentÔscCs2titƒd6djd
ƒd6dd6dd	6ƒS(s9
    :rtype: requests.structures.CaseInsensitiveDict
    s
User-Agents, tgziptdeflatesAccept-Encodings*/*tAccepts
keep-alivet
Connection(sgzipsdeflate(RRðR±(((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytdefault_headersÝs

c	Csñg}d}xÞtjd|ƒD]Ê}y|jddƒ\}}Wntk
ra|d}}nXi|jdƒd6}xa|jdƒD]P}y|jdƒ\}}Wntk
r»PnX|j|ƒ||j|ƒ<qˆW|j|ƒqW|S(	s¼Return a dict of parsed link headers proxies.

    i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"

    :rtype: list
    s '"s, *<RiR˜s<> '"R\R|(R*R'RnR’Rx(	Rotlinkst
replace_charstvalR\R•tlinktparamtkey((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytparse_header_linksés 

 tROiicCs|d }|tjtjfkr&dS|d tjkr=dS|d tjtjfkr]dS|jtƒ}|dkr|dS|dkrÅ|d	d	d…tkr¥d
S|dd	d…tkrÅdSn|dkrü|d t	kråd
S|dt	krüdSnd	S(s
    :rtype: str
    isutf-32is	utf-8-sigisutf-16isutf-8Ns	utf-16-beis	utf-16-les	utf-32-bes	utf-32-le(R›tBOM_UTF32_LEtBOM_UTF32_BEtBOM_UTF8tBOM_UTF16_LEtBOM_UTF16_BERÐt_nullt_null2t_null3R=(tdatatsamplet	nullcount((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytguess_json_utfs*
cCsSt||ƒ\}}}}}}|s7||}}nt||||||fƒS(sªGiven a URL that may or may not have a scheme, prepend the given scheme.
    Does not replace a present scheme with the one provided as an argument.

    :rtype: str
    (RR(R\t
new_schemeRéRXRQR•tquerytfragment((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytprepend_scheme_if_needed0s!cCsRt|ƒ}y"t|jƒt|jƒf}Wnttfk
rMd}nX|S(s{Given a url with authentication components, extract them into a tuple of
    username,password.

    :rtype: (str,str)
    R˜(R˜R˜(RR	tusernametpasswordR[R¨(R\tparsedtauth((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytget_auth_from_urlAs"
s^\S[^\r\n]*$|^$cCs„|\}}t|tƒr$t}nt}y&|j|ƒsOtd|ƒ‚nWn-tk
rtd|t|ƒfƒ‚nXdS(sÕVerifies that header value is a string which doesn't contain
    leading whitespace or return characters. This prevents unintended
    header injection.

    :param header: tuple, in the format (name, value).
    s7Invalid return character or leading space in header: %ss4Header value %s must be of type str or bytes, not %sN(RVRt_CLEAN_HEADER_REGEX_BYTEt_CLEAN_HEADER_REGEX_STRR+RR¨ttype(theaderReRotpat((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytcheck_header_validityVs	
cCsft|ƒ\}}}}}}|s4||}}n|jddƒd}t|||||dfƒS(sW
    Given a url remove the fragment and the authentication part.

    :rtype: str
    t@iiÿÿÿÿR˜(RtrsplitR(R\RéRXRQR•RR((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyt
urldefragauthks
cCs}t|jddƒ}|dk	rmt|jtƒrmy||jƒWqyttfk
ritdƒ‚qyXntdƒ‚dS(sfMove file pointer back to its recorded starting position
    so it can be read again on redirect.
    R<s;An error occurred when rewinding request body for redirect.s+Unable to rewind request body for redirect.N(	RhtbodyR=RVt_body_positionRRFR%R(tprepared_requestt	body_seek((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pytrewind_body|s(s.netrcs_netrc(_t__doc__RR›Rqt
contextlibR>R@tplatformR*R¿R½RDRR˜Rt_internal_utilsRtcompatRRvRRRRRR	R
RRR
RRRRtcookiesRt
structuresRt
exceptionsRRRRRPtwheretDEFAULT_CA_BUNDLE_PATHtsystemR2R6RKR&RdRkRpRtR{R}RwR‚RƒRŒR–R¢R¦Rªt	frozensetR°R·R»RÉRÁRÏRÒtcontextmanagerR×RåR=RæRïRðRõRütencodeRRRR	R
RR†RRRRR (((sC/home/tvault/.virtenv/lib/python2.7/site-packages/requests/utils.pyt<module>	s„^"	!			=3				 	#						
	%
							9				"