Viewing File: /opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyc


t_c@s{dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#dd
l$m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,dCZ-ej.Z/idd6dd6Z0ej1dkrdZ2dZndZ3dZ4e5dZ6dZ7dZ8dZ9dZ:dZ;dZ<e5dZ=d Z>d!Z?d"Z@d#ZAd$ZBd%ZCd&ZDd'ZEeFd(d)ZGd*ZHd+ZId,ZJd-ZKd.ZLd/ZMejNd0ZOd1ZPdd2ZRd3ZSd4d5ZTd6ZUd7ZVd8jWd9ZXeXd:ZYeXd;ZZd<Z[d=Z\d>Z]ej^d?Z_ej^d?Z`d@ZadAZbdBZcdS(Ds
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.
iN(tOrderedDicti(t__version__(tcerts(tto_native_string(tparse_http_list(tquoteturlparsetbyteststrtunquotet
getproxiestproxy_bypasst
urlunparset
basestringt
integer_typestis_py3tproxy_bypass_environmenttgetproxies_environmenttMapping(tcookiejar_from_dict(tCaseInsensitiveDict(t
InvalidURLt
InvalidHeadertFileModeWarningtUnrewindableBodyErrors.netrct_netrciPthttpithttpstwin32cCsAy%trddl}nddl}Wntk
r9tSXyK|j|jd}t|j|dd}|j|dd}Wnt	k
rtSX|s|rtS|j
d}x|D]w}|dkrd|krtSn|jdd	}|jd
d}|jdd}t
j||t
jrtSqWtS(
Nis;Software\Microsoft\Windows\CurrentVersion\Internet SettingstProxyEnableit
ProxyOverridet;s<local>t.s\.t*s.*t?(Rtwinregt_winregtImportErrortFalsetOpenKeytHKEY_CURRENT_USERtinttQueryValueExtOSErrortsplittTruetreplacetretmatchtI(thostR#tinternetSettingstproxyEnablet
proxyOverridettest((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytproxy_bypass_registry0s8
		

cCs!trt|St|SdS(sReturn True, if the host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.
        N(RRR7(R2((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyRWs	
cCs"t|dr|j}n|S(s/Returns an internal sequence dictionary update.titems(thasattrR8(td((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytdict_to_sequencecscCsd}d}t|dr*t|}nt|drE|j}nmt|dry|j}Wntjk
rzqXtj|j}d|j	krt
jdtqnt|drty|j
}Wn,ttfk
r|dk	rq|}qqqtXt|drt|dkrty3|jdd	|j
}|j|pIdWqqttfk
rmd}qqXqtn|dkrd}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(tNoneR9R=R>tiotUnsupportedOperationtostfstattst_sizetmodetwarningstwarnRR@R+tIOErrorRAtmax(tottotal_lengthtcurrent_positionR>((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyt	super_lenls@

	cCseyGddlm}m}d}x^tD]V}ytjjdj|}Wntk
r_dSXtjj	|r&|}Pq&q&W|dkrdSt
|}d}t|tr|j
d}n|jj|d}	yG||j|	}
|
r|
drdnd}|
||
d	fSWn#|tfk
rE|rFqFnXWnttfk
r`nXdS(
s;Returns the Requests tuple auth for a given url from netrc.i(tnetrctNetrcParseErrors~/{}Nt:tasciiiii(RQRRRBtNETRC_FILESREtpatht
expandusertformattKeyErrortexistsRt
isinstanceRtdecodetnetlocR,tauthenticatorsRKR%tAttributeError(turltraise_errorsRQRRt
netrc_pathtftloctritsplitstrR2Rtlogin_i((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytget_netrc_auths8

cCs[t|dd}|rWt|trW|ddkrW|ddkrWtjj|SdS(s0Tries to guess the filename of the given object.tnameit<it>N(tgetattrRBR[R
RERVtbasename(tobjRi((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytguess_filenames%cCstjj|r|Stjj|\}}xJ|rztjj|rztjj|\}}dj||g}q1Wtj|s|Stj|}||jkr|St	j
}tjj||jd}tjj|s|j|d|}n|S(sReplace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
    t/RV(RERVRZR,tjointzipfilet
is_zipfiletZipFiletnamelistttempfilet
gettempdirtextract(RVtarchivetmembertprefixtzip_filettmptextracted_path((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytextract_zipped_pathss cCsD|dkrdSt|ttttfr:tdnt|S(sTake 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')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples
        >>> from_key_val_list({'key': 'val'})
        OrderedDict([('key', 'val')])

    :rtype: OrderedDict
    s+cannot encode objects that are not 2-tuplesN(RBR[RRtboolR)t
ValueErrorR(tvalue((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytfrom_key_val_lists
cCsb|dkrdSt|ttttfr:tdnt|trX|j}nt	|S(sTake 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')
        Traceback (most recent call last):
        ...
        ValueError: cannot encode objects that are not 2-tuples

    :rtype: list
    s+cannot encode objects that are not 2-tuplesN(
RBR[RRRR)RRR8tlist(R((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytto_key_val_lists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
    iit"(t_parse_list_headertunquote_header_valuetappend(Rtresulttitem((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytparse_list_header=s$cCsi}xt|D]~}d|kr5d||<qn|jdd\}}|d |dkoldknrt|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=iiRN(RRBR,R(RRRRi((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytparse_dict_header]s
$cCsq|rm|d|dko%dknrm|dd!}|sN|d dkrm|jddjddSn|S(	sUnquotes 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
    iiRiis\\s\s\"(R.(Rtis_filename((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyRs
*
cCs+i}x|D]}|j||j<q
W|S(sReturns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    :rtype: dict
    (RRi(tcjtcookie_dicttcookie((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytdict_from_cookiejars
cCs
t||S(sReturns 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((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytadd_dict_to_cookiejarscCsvtjdttjddtj}tjddtj}tjd}|j||j||j|S(slReturns encodings from given content string.

    :param content: bytestring to extract encodings from.
    sIn 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=["\']*(.+?)["\'>](RIRJtDeprecationWarningR/tcompileR1tfindall(tcontentt
charset_ret	pragma_retxml_re((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytget_encodings_from_contentsc
Cs|jd}|dj|d}}i}d}x|D]}|j}|r=|t}}|jd}	|	dkr||	 j|}||	dj|}n|||j<q=q=W||fS(sReturns content type and parameters from given header

    :param header: string
    :return: tuple containing content type and dictionary of
         parameters
    Riis"' Ri(R,tstripR-tfindtlower(
theaderttokenstcontent_typetparamstparams_dicttitems_to_striptparamtkeyRtindex_of_equals((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyt_parse_content_type_headers

cCs\|jd}|sdSt|\}}d|krH|djdSd|krXdSdS(s}Returns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    :rtype: str
    scontent-typetcharsets'"ttexts
ISO-8859-1N(tgetRBRR(theadersRR((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytget_encoding_from_headerssccs|jdkr)x|D]}|VqWdStj|jdd}x+|D]#}|j|}|rK|VqKqKW|jddt}|r|VndS(sStream decodes a iterator.NterrorsR.ttfinal(tencodingRBtcodecstgetincrementaldecoderR\R-(titeratortrRtdecodertchunktrv((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytstream_decode_response_unicodes
	
ccsdd}|dks|dkr-t|}nx0|t|kr_||||!V||7}q0WdS(s Iterate over slices of a string.iN(RBR=(tstringtslice_lengthtpos((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytiter_slicesscCstjdtg}t|j}|rcyt|j|SWqctk
r_|j|qcXnyt|j|ddSWnt	k
r|jSXdS(sReturns 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
    sIn 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.)RR.N(
RIRJRRRRRtUnicodeErrorRt	TypeError(Rttried_encodingsR((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytget_unicode_from_responses

t4ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzs0123456789-._~cCs|jd}xtdt|D]}||dd!}t|dkr|jrytt|d}Wn!tk
rtd|nX|tkr|||d||<qd||||<q%d||||<q%Wdj	|S(sUn-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,trangeR=tisalnumtchrR)RRtUNRESERVED_SETRq(turitpartstithtc((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytunquote_unreserved:s
cCsKd}d}ytt|d|SWntk
rFt|d|SXdS(sRe-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(RRR(Rtsafe_with_percenttsafe_without_percent((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytrequote_uriRs
cCstjdtj|d}|jd\}}tjdtjtt|d}tjdtj|d|@}||@||@kS(sThis 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=LiRp(tstructtunpacktsockett	inet_atonR,tdotted_netmaskR)(tiptnettipaddrtnetaddrtbitstnetmasktnetwork((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytaddress_in_networkhs
+#cCs/ddd|>dA}tjtjd|S(sConverts mask from /xx format to xxx.xxx.xxx.xxx

    Example: if mask is 24 function returns 255.255.255.0

    :rtype: str
    Iii s>I(Rt	inet_ntoaRtpack(tmaskR((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyRwscCs-ytj|Wntjk
r(tSXtS(s
    :rtype: bool
    (RRterrorR&R-(t	string_ip((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytis_ipv4_addresss
cCs|jddkryt|jdd}Wntk
rFtSX|dks_|dkrctSytj|jddWqtjk
rtSXntStS(sV
    Very simple check of the cidr format in no_proxy variable.

    :rtype: bool
    Rpii i(	tcountR)R,RR&RRRR-(tstring_networkR((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyt
is_valid_cidrs
ccst|dk	}|r4tjj|}|tj|<nz	dVWd|ro|dkr_tj|=qo|tj|<nXdS(sSet 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(RBREtenvironR(tenv_nameRt
value_changedt	old_value((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytset_environs	
c	
Csd}|}|dkr*|d}nt|}|jdkrItS|r3d|jddjdD}t|jrx|D]>}t|rt|j|rtSq|j|krtSqWq3|j}|j	r|dj
|j	7}nx6|D]+}|jj|s(|j|rtSqWntd|;yt
|j}Wn ttjfk
rxt}nXWdQX|rtStS(	sL
    Returns whether we should bypass proxies or not.

    :rtype: bool
    cSs(tjj|p'tjj|jS(N(RERRtupper(tk((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyt<lambda>stno_proxycss|]}|r|VqdS(N((t.0R2((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pys	<genexpr>st Rt,s:{}N(RBRthostnameR-R.R,RRRtportRXtendswithRRRRtgaierrorR&(	R`Rt	get_proxytno_proxy_argtparsedtproxy_ipthost_with_portR2tbypass((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytshould_bypass_proxiess<	%
		
!cCs!t|d|riStSdS(sA
    Return a dict of environment proxies.

    :rtype: dict
    RN(RR
(R`R((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytget_environ_proxiesscCs|p	i}t|}|jdkrC|j|j|jdS|jd|j|jd|jdg}d}x(|D] }||krz||}PqzqzW|S(sSelect 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(RRRBRtscheme(R`tproxiesturlpartst
proxy_keystproxyt	proxy_key((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytselect_proxys
	

spython-requestscCsd|tfS(sO
    Return a string representing the default user agent.

    :rtype: str
    s%s/%s(R(Ri((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytdefault_user_agentscCs2titd6djd
d6dd6dd	6S(s9
    :rtype: requests.structures.CaseInsensitiveDict
    s
User-Agents, tgziptdeflatesAccept-Encodings*/*tAccepts
keep-alivet
Connection(RR(RR
Rq(((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytdefault_headers's

c	Cs
g}d}|j|}|s%|Sxtjd|D]}y|jdd\}}Wntk
rz|d}}nXi|jdd6}xa|jdD]P}y|jd\}}Wntk
rPnX|j|||j|<qW|j|q8W|S(	sReturn a list 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, *<RiRs<> '"R`R(RR/R,RR(	Rtlinkst
replace_charstvalR`RtlinkRR((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytparse_header_links3s&

 tRTiicCs|d }|tjtjfkr&dS|d tjkr=dS|d tjtjfkr]dS|jt}|dkr|dS|dkr|d	d	dtkrd
S|dd	dtkrdSn|dkr|d t	krd
S|dt	krdSnd	S(s
    :rtype: str
    isutf-32is	utf-8-sigisutf-16isutf-8Ns	utf-16-beis	utf-16-les	utf-32-bes	utf-32-le(RtBOM_UTF32_LEtBOM_UTF32_BEtBOM_UTF8tBOM_UTF16_LEtBOM_UTF16_BERt_nullt_null2t_null3RB(tdatatsamplet	nullcount((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytguess_json_utf^s*
cCsSt||\}}}}}}|s7||}}nt||||||fS(sGiven 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_schemeRR]RVRtquerytfragment((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytprepend_scheme_if_needed~s!cCsRt|}y"t|jt|jf}Wnttfk
rMd}nX|S(s{Given a url with authentication components, extract them into a tuple of
    username,password.

    :rtype: (str,str)
    R(RR(RR	tusernametpasswordR_R(R`Rtauth((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytget_auth_from_urls"
s^\S[^\r\n]*$|^$cCs|\}}t|tr$t}nt}y&|j|sOtd|nWn0tk
rtd||t|fnXdS(sVerifies 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: %ss>Value for header {%s: %s} must be of type str or bytes, not %sN(R[Rt_CLEAN_HEADER_REGEX_BYTEt_CLEAN_HEADER_REGEX_STRR0RRttype(RRiRtpat((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytcheck_header_validitys	
cCsft|\}}}}}}|s4||}}n|jddd}t|||||dfS(sW
    Given a url remove the fragment and the authentication part.

    :rtype: str
    t@iiR(RtrsplitR(R`RR]RVRR#R$((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyt
urldefragauths
cCs}t|jdd}|dk	rmt|jtrmy||jWqyttfk
ritdqyXntddS(sfMove file pointer back to its recorded starting position
    so it can be read again on redirect.
    RAs;An error occurred when rewinding request body for redirect.s+Unable to rewind request body for redirect.N(	RltbodyRBR[t_body_positionRRKR+R(tprepared_requestt	body_seek((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pytrewind_bodys(s.netrcs_netrc(dt__doc__Rt
contextlibRCRER/RRtsysRvRIRrtcollectionsRRRRt_internal_utilsRtcompatRRRRRRR	R
RRR
RRRRRtcookiesRt
structuresRt
exceptionsRRRRRUtwheretDEFAULT_CA_BUNDLE_PATHt
DEFAULT_PORTStplatformR7R;RPR&RhRoRRRRRRRRRRRRRRt	frozensetRRRRRRRtcontextmanagerRRRBRR	R
RRtencodeRRRR!R%R)RR*R+R.R1R6(((sK/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/requests/utils.pyt<module>	s^"	'			=3		 			 	#							
	%
							=				&

	 				
Back to Directory File Manager