%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/requests/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/requests/__pycache__/utils.cpython-35.pyc



~�VUU�@s2dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZm Z dd	l!m"Z"dd
l#m$Z$m%Z%efZ&dWZ'ej(�Z)d
d�Z*dd�Z+ddd�Z,dd�Z-dd�Z.dd�Z/dd�Z0dd�Z1ddd�Z2d d!�Z3d"d#�Z4d$d%�Z5d&d'�Z6d(d)�Z7d*d+�Z8d,d-�Z9e:d.d/�Z;d0d1�Z<d2d3�Z=d4d5�Z>d6d7�Z?d8d9�Z@d:d;�ZAd<d=�ZBd>d?�ZCd@dA�ZDdBdCdD�ZEdEdF�ZFdGdH�ZGdIjHdJ�ZIeIdKZJeIdLZKdMdN�ZLdOdP�ZMdQdR�ZNdJdSdT�ZOdUdV�ZPdS)Xz�
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
that are also useful for external consumption.

�N�)�__version__)�certs)�parse_http_list)�quote�urlparse�bytes�str�OrderedDict�unquote�is_py2�builtin_str�
getproxies�proxy_bypass�
urlunparse�
basestring)�RequestsCookieJar�cookiejar_from_dict)�CaseInsensitiveDict)�
InvalidURL�FileModeWarning�.netrc�_netrccCst|d�r|j�}|S)z/Returns an internal sequence dictionary update.�items)�hasattrr)�d�r�0/usr/lib/python3/dist-packages/requests/utils.py�dict_to_sequence)srcCs�d}d}t|d�r*t|�}n�t|d�rE|j}n�t|d�rit|j��}nht|d�r�y|j�}Wntjk
r�Yn2Xtj|�j}d|j	kr�t
jdt�t|d�r�|j
�}td||�S)	Nr�__len__�len�getvalue�fileno�ba%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.�tell)rr r!r"�io�UnsupportedOperation�os�fstat�st_size�mode�warnings�warnrr$�max)�oZtotal_lengthZcurrent_positionr"rrr�	super_len2s*r/FcCsbyCddlm}m}d}x_tD]W}ytjjdj|��}Wntk
rcdSYnXtjj|�r&|}Pq&W|dkr�dSt	|�}d}t
|t�r�|jd�}|j
j|�d}	yG||�j|	�}
|
r|
drdnd}|
||
dfSWn!|tfk
rA|r=�YnXWnttfk
r]YnXdS)	z;Returns the Requests tuple auth for a given url from netrc.r)�netrc�NetrcParseErrorNz~/{0}�:�asciir�)r0r1�NETRC_FILESr'�path�
expanduser�format�KeyError�existsr�
isinstancer	�decode�netloc�splitZauthenticators�IOError�ImportError�AttributeError)�urlZraise_errorsr0r1Z
netrc_path�f�locZriZsplitstr�hostrZlogin_irrr�get_netrc_auth[s8

	rFcCs[t|dd�}|rWt|t�rW|ddkrW|ddkrWtjj|�SdS)z0Tries to guess the filename of the given object.�nameNr�<r�>���)�getattrr;rr'r6�basename)�objrGrrr�guess_filename�s%rNcCsA|dkrdSt|ttttf�r7td��t|�S)a�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')])
    Nz+cannot encode objects that are not 2-tuples)r;r	r�bool�int�
ValueErrorr
)�valuerrr�from_key_val_list�s
rScCs_|dkrdSt|ttttf�r7td��t|tj�rU|j�}t	|�S)azTake 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.
    Nz+cannot encode objects that are not 2-tuples)
r;r	rrOrPrQ�collections�Mappingr�list)rRrrr�to_key_val_list�s
rWcCstg}xgt|�D]Y}|dd�|dd�koDdknr_t|dd��}|j|�qW|S)a�Parse 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`
    Nr�"rJrJ)�_parse_list_header�unquote_header_value�append)rR�result�itemrrr�parse_list_header�s0r^cCs�i}x�t|�D]�}d|kr2d||<q|jdd�\}}|dd�|dd�koudknr�t|dd��}|||<qW|S)aMParse 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`
    �=NrrXrJrJ)rYr>rZ)rRr\r]rGrrr�parse_dict_header�s
0r`cCsw|rs|d|d	ko%dknrs|dd
�}|sW|dd�dkrs|jdd�jdd�S|S)z�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.
    rrrXNr4z\\�\z\"rJrJ)�replace)rRZis_filenamerrrrZs
*rZcCs+i}x|D]}|j||j<q
W|S)zoReturns a key/value dictionary from a CookieJar.

    :param cj: CookieJar object to extract cookies from.
    )rRrG)�cj�cookie_dictZcookierrr�dict_from_cookiejar s
recCst|�}|j|�|S)z�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.
    )r�update)rcrdZcj2rrr�add_dict_to_cookiejar.s
rgcCsvtjdt�tjddtj�}tjddtj�}tjd�}|j|�|j|�|j|�S)zlReturns encodings from given content string.

    :param content: bytestring to extract encodings from.
    z�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.)z!<meta.*?charset=["\']*(.+?)["\'>]�flagsz+<meta.*?content=["\']*;?charset=(.+?)["\'>]z$^<\?xml.*?encoding=["\']*(.+?)["\'>])r+r,�DeprecationWarning�re�compile�I�findall)�contentZ
charset_reZ	pragma_reZxml_rerrr�get_encodings_from_content:srocCs_|jd�}|sdStj|�\}}d|krK|djd�Sd|kr[dSdS)zmReturns encodings from given HTTP Header Dict.

    :param headers: dictionary to extract encoding from.
    zcontent-typeN�charsetz'"�textz
ISO-8859-1)�get�cgiZparse_header�strip)�headersZcontent_type�paramsrrr�get_encoding_from_headersNsrwccs�|jdkr)x|D]}|VqWdStj|j�dd�}x(|D] }|j|�}|rK|VqKW|jddd�}|r�|VdS)zStream decodes a iterator.N�errorsrb��finalT)�encoding�codecs�getincrementaldecoderr<)�iterator�rr]�decoder�chunk�rvrrr�stream_decode_response_unicodebs
	
	r�ccs@d}x3|t|�kr;||||�V||7}q	WdS)z Iterate over slices of a string.rN)r )�stringZslice_length�posrrr�iter_slicestsr�cCs�tjdt�g}t|j�}|rayt|j|�SWntk
r`|j|�YnXyt|j|dd�SWnt	k
r�|jSYnXdS)z�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

    z�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.)rxrbN)
r+r,rirwrur	rn�UnicodeErrorr[�	TypeError)rZtried_encodingsr{rrr�get_unicode_from_response|s

r�Z4ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzz0123456789-._~c
Cs�|jd�}x�tdt|��D]�}||dd�}t|�dkr�|j�r�ytt|d��}Wn"tk
r�td|��YnX|tkr�|||dd�||<q�d||||<q%d||||<q%Wdj	|�S)	z�Un-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
    �%rrr4�z%Invalid percent-escape sequence: '%s'N�)
r>�ranger �isalnum�chrrPrQr�UNRESERVED_SET�join)�uri�parts�i�h�crrr�unquote_unreserved�s
r�cCsOd}d}ytt|�d|�SWn"tk
rJt|d|�SYnXdS)z�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.
    z!#$%&'()*+,/:;=?@[]~z!#$&'()*+,/:;=?@[]~ZsafeN)rr�r)r�Zsafe_with_percentZsafe_without_percentrrr�requote_uri�s
r�cCs�tjdtj|��d}|jd�\}}tjdtjtt|����d}tjdtj|��d|@}||@||@kS)z�
    This function allows you to check if on 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
    z=Lr�/)�structZunpack�socket�	inet_atonr>�dotted_netmaskrP)�ipZnetZipaddrZnetaddr�bitsZnetmaskZnetworkrrr�address_in_network�s
+#r�cCs/ddd|>dA}tjtjd|��S)zt
    Converts mask from /xx format to xxx.xxx.xxx.xxx
    Example: if mask is 24 function returns 255.255.255.0
    l��r� z>I)r�Z	inet_ntoar�Zpack)�maskr�rrrr��sr�cCs1ytj|�Wntjk
r,dSYnXdS)NFT)r�r��error)Z	string_iprrr�is_ipv4_address�s
	r�cCs�|jd�dkr�yt|jd�d�}Wntk
rJdSYnX|dksc|dkrgdSytj|jd�d�Wq�tjk
r�dSYq�XndSdS)z9Very simple check of the cidr format in no_proxy variabler�rFr�rT)�countrPr>rQr�r�r�)Zstring_networkr�rrr�
is_valid_cidr�s
	r�cCs)dd�}|d�}t|�j}|r�dd�|jdd�jd�D�}|jd	�d
}t|�r�xp|D]%}t|�r{t||�r{dSq{Wn@x=|D]5}|j|�s�|jd	�d
j|�r�dSq�Wyt|�}Wn!t	t
jfk
rd}YnX|r%dSdS)
z:
    Returns whether we should bypass proxies or not.
    cSs(tjj|�p'tjj|j��S)N)r'�environrr�upper)�krrr�<lambda>sz'should_bypass_proxies.<locals>.<lambda>�no_proxycss|]}|r|VqdS)Nr)�.0rErrr�	<genexpr>sz(should_bypass_proxies.<locals>.<genexpr>� r��,�:rTF)rr=rbr>r�r�r��endswithrr�r�Zgaierror)rBZ	get_proxyr�r=r�Zproxy_iprEZbypassrrr�should_bypass_proxiess*(

+r�cCst|�riSt�SdS)z%Return a dict of environment proxies.N)r�r)rBrrr�get_environ_proxies0sr�cCsW|p	i}t|�}|j|jd|j�}|dkrS|j|j�}|S)z�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
    z://N)rrr�schemeZhostname)rBZproxiesZurlparts�proxyrrr�select_proxy7sr�zpython-requestscCsd|tfS)z4Return a string representing the default user agent.z%s/%s)r)rGrrr�default_user_agentDsr�c	Cs.tdt�ddjd
�dddd	i�S)Nz
User-AgentzAccept-Encodingz, �gzip�deflateZAcceptz*/*Z
Connectionz
keep-alive)r�r�)rr�r�rrrr�default_headersIs
	r�c	Cs�g}d}x�tjd|�D]�}y|jdd�\}}Wntk
rb|d}}YnXi}|jd�|d<xb|jd�D]Q}y|jd�\}}Wntk
r�PYnX|j|�||j|�<q�W|j|�qW|S)	z�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"

    z '"z, *<�;rr�z<> '"rBr_)rjr>rQrtr[)	rRZlinksZ
replace_chars�valrBrv�linkZparam�keyrrr�parse_header_linksRs"

 r��r3r4�cCs|dd�}|tjtjfkr,dS|dd�tjkrIdS|dd�tjtjfkrodS|jt�}|dkr�dS|dkr�|ddd�tkr�d	S|d
dd�tkr�dS|dkr|dd�t	kr�dS|d
d�t	krd
SdS)N�zutf-32r�z	utf-8-sigr4zutf-16rzutf-8z	utf-16-berz	utf-16-lez	utf-32-bez	utf-32-le)
r|�BOM_UTF32_LE�BOM32_BE�BOM_UTF8�BOM_UTF16_LE�BOM_UTF16_BEr��_null�_null2�_null3)�dataZsampleZ	nullcountrrr�guess_json_utfzs*"r�cCsPt||�\}}}}}}|s4||}}t||||||f�S)z�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.)rr)rBZ
new_schemer�r=r6rv�query�fragmentrrr�prepend_scheme_if_needed�s!
r�cCsSt|�}y"t|j�t|j�f}Wnttfk
rNd}YnX|S)z_Given a url with authentication components, extract them into a tuple of
    username,password.r�)r�r�)rrZusernameZpasswordrAr�)rBZparsedZauthrrr�get_auth_from_url�s"r�cCsId}t|t�r|}n'tr6|j|�}n|j|�}|S)z�
    Given a string object, regardless of type, returns a representation of that
    string in the native string type, encoding and decoding where necessary.
    This assumes ASCII unless told otherwise.
    N)r;r
r�encoder<)r�r{�outrrr�to_native_string�s	r�cCsct|�\}}}}}}|s1||}}|jdd�d}t|||||df�S)zE
    Given a url remove the fragment and the authentication part
    �@rr�rJ)r�rsplitr)rBr�r=r6rvr�r�rrr�
urldefragauth�s

r�)rz_netrc)Q�__doc__rsr|rTr%r'�platformrj�sysr�r�r+r�rr�compatrrYrrrr	r
rrr
rrrrZcookiesrrZ
structuresr�
exceptionsrrZ_hush_pyflakesr5ZwhereZDEFAULT_CA_BUNDLE_PATHrr/rFrNrSrWr^r`rZrergrorwr�r�r��	frozensetr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>
sxR		)3"$

	/
	#




Zerion Mini Shell 1.0