OwlCyberSecurity - MANAGER
Edit File: response.cpython-37.pyc
B ������`+n������������������@���sX��d�dl�mZ�d�dlZd�dlZd�dlZd�dlmZ�d�dlmZ �d�dlm Z�yd�dlZW�n�e k rl���dZY�nX�ddlmZ�ddlmZmZ�dd lmZmZmZmZmZmZmZmZmZmZ�dd lmZ�ddl m!Z!m"Z"�e�#e$�Z%G�dd ��d e&�Z'G�dd��de&�Z(G�dd��de&�Z)edk �r*G�dd��de&�Z*G�dd��de&�Z+dd��Z,G�dd��dej-�Z.dS�)�����)�absolute_importN)�contextmanager)�error)�timeout����)�HTTPHeaderDict)�BaseSSLError� HTTPException) �BodyNotHttplibCompatible�DecodeError� HTTPError�IncompleteRead�InvalidChunkLength� InvalidHeader� ProtocolError�ReadTimeoutError�ResponseNotChunked�SSLError)�six)�is_fp_closed�is_response_to_headc���������������@���s$���e�Zd�Zdd��Zdd��Zdd��ZdS�)�DeflateDecoderc�������������C���s���d|�_�d|�_t���|�_d�S�)NT�����)� _first_try�_data�zlib� decompressobj�_obj)�self��r����A/opt/alt/python37/lib/python3.7/site-packages/urllib3/response.py�__init__$���s����zDeflateDecoder.__init__c�������������C���s���t�|�j|�S�)N)�getattrr���)r����namer���r���r ����__getattr__)���s����zDeflateDecoder.__getattr__c�������������C���s����|s|S�|�j�s|�j�|�S�|��j|7��_y |�j�|�}|rFd|�_�d�|�_|S��tjk r����d|�_�t�tj��|�_z|��|�j�S�d�|�_X�Y�nX�d�S�)NF)r���r���� decompressr���r���r���r���� MAX_WBITS)r����dataZdecompressedr���r���r ���r%���,���s"����zDeflateDecoder.decompressN)�__name__� __module__�__qualname__r!���r$���r%���r���r���r���r ���r���#���s���r���c���������������@���s���e�Zd�ZdZdZdZdS�)�GzipDecoderStater���r�������N)r(���r)���r*����FIRST_MEMBER� OTHER_MEMBERS�SWALLOW_DATAr���r���r���r ���r+���C���s���r+���c���������������@���s$���e�Zd�Zdd��Zdd��Zdd��ZdS�)�GzipDecoderc�������������C���s���t��dt�j��|�_tj|�_d�S�)N����)r���r���r&���r���r+���r-����_state)r���r���r���r ���r!���K���s����zGzipDecoder.__init__c�������������C���s���t�|�j|�S�)N)r"���r���)r���r#���r���r���r ���r$���O���s����zGzipDecoder.__getattr__c�������������C���s����t���}|�jtjks|st|�S�x�y||�j�|�7�}W�n8�tjk rl���|�j}tj|�_|tj krft|�S���Y�nX�|�jj }|s�t|�S�tj |�_t�dtj��|�_q W�d�S�)Nr1���) � bytearrayr2���r+���r/����bytesr���r%���r���r���r.����unused_datar���r&���)r���r'����retZprevious_stater���r���r ���r%���R���s"���� zGzipDecoder.decompressN)r(���r)���r*���r!���r$���r%���r���r���r���r ���r0���J���s���r0���c���������������@���s���e�Zd�Zdd��Zdd��ZdS�)� BrotliDecoderc�������������C���s0���t����|�_t|�jd�r"|�jj|�_n |�jj|�_d�S�)Nr%���)�brotliZDecompressorr����hasattrr%����process)r���r���r���r ���r!���n���s���� zBrotliDecoder.__init__c�������������C���s���t�|�jd�r|�j���S�dS�)N�flushr���)r9���r���r;���)r���r���r���r ���r;���u���s���� zBrotliDecoder.flushN)r(���r)���r*���r!���r;���r���r���r���r ���r7���j���s���r7���c���������������@���s(���e�Zd�ZdZdd��Zdd��Zdd��ZdS�) �MultiDecodera�� From RFC7231: If one or more encodings have been applied to a representation, the sender that applied the encodings MUST generate a Content-Encoding header field that lists the content codings in the order in which they were applied. c�������������C���s���dd��|��d�D��|�_d�S�)Nc�������������S���s���g�|�]}t�|�����qS�r���)�_get_decoder�strip)�.0�mr���r���r ���� <listcomp>����s����z)MultiDecoder.__init__.<locals>.<listcomp>�,)�split� _decoders)r���Zmodesr���r���r ���r!�������s����zMultiDecoder.__init__c�������������C���s���|�j�d����S�)Nr���)rD���r;���)r���r���r���r ���r;�������s����zMultiDecoder.flushc�������������C���s"���xt�|�j�D�]}|�|�}qW�|S�)N)�reversedrD���r%���)r���r'����dr���r���r ���r%�������s����zMultiDecoder.decompressN)r(���r)���r*����__doc__r!���r;���r%���r���r���r���r ���r<���{���s���r<���c�������������C���s:���d|�krt�|��S�|�dkrt��S�td�k r4|�dkr4t��S�t��S�)NrB����gzip�br)r<���r0���r8���r7���r���)�moder���r���r ���r=�������s����r=���c���������������@���sl��e�Zd�ZdZddgZedk r&edg7�Zdddd d gZdNdd�Zdd��Zdd��Z dd��Z edd���Zedd���Z dd��Zdd��Zdd ��Zd!d"��ZeejfZedk r�eejf7�Zd#d$��Zd%d&��Zed'd(���ZdOd)d*�ZdPd,d-�Zed.d/���Zd0d1��ZdQd2d3�Zd4d5��Z d6d7��Z!ed8d9���Z"d:d;��Z#d<d=��Z$d>d?��Z%d@dA��Z&dBdC��Z'dDdE��Z(dFdG��Z)dRdHdI�Z*dJdK��Z+dLdM��Z,dS�)S�HTTPResponsea��� HTTP Response container. Backwards-compatible with :class:`http.client.HTTPResponse` but the response ``body`` is loaded and decoded on-demand when the ``data`` property is accessed. This class is also compatible with the Python standard library's :mod:`io` module, and can hence be treated as a readable object in the context of that framework. Extra parameters for behaviour not present in :class:`http.client.HTTPResponse`: :param preload_content: If True, the response's body will be preloaded during construction. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. :param original_response: When this HTTPResponse wrapper is generated from an :class:`http.client.HTTPResponse` object, it's convenient to include the original for debug purposes. It's otherwise unused. :param retries: The retries contains the last :class:`~urllib3.util.retry.Retry` that was used during the request. :param enforce_content_length: Enforce content length checking. Body returned by server must match value of Content-Length header, if present. Otherwise, raise error. rH����deflateNrI���i-��i.��i/��i3��i4����r���TFc�������������C���s��t�|t�r||�_n t|�|�_||�_||�_||�_||�_||�_| |�_||�_ ||�_ d�|�_d�|�_d�|�_ | |�_d|�_||�_||�_|r�t�|tjtf�r�||�_| |�_||�_t|d�r�||�_ d|�_d�|�_|�j�dd����}dd��|�d�D��}d |kr�d |�_|��|�|�_|�r|�j�s|�j|d�|�_d�S�)Nr����readFztransfer-encodingrM���c�������������s���s���|�]}|����V��qd�S�)N)r>���)r?����encr���r���r ���� <genexpr>����s����z(HTTPResponse.__init__.<locals>.<genexpr>rB����chunkedT)�decode_content) � isinstancer����headers�status�version�reason�strictrR����retries�enforce_content_length� auto_close�_decoder�_body�_fp�_original_response�_fp_bytes_read�msg�_request_urlr����string_typesr4����_pool�_connectionr9���rQ���� chunk_left�get�lowerrC����_init_length�length_remainingrN���)r����bodyrT���rU���rV���rW���rX���Zpreload_contentrR����original_response�pool� connectionra���rY���rZ����request_methodZrequest_urlr[���Ztr_enc� encodingsr���r���r ���r!�������sB���� zHTTPResponse.__init__c�������������C���s���|�j�|�jkr|�j�d�S�dS�)a�� Should we redirect and where to? :returns: Truthy redirect location string if we got a redirect status code and valid location. ``None`` if redirect status and no location. ``False`` if not a redirect status code. �locationF)rU����REDIRECT_STATUSESrT���rg���)r���r���r���r ����get_redirect_location��s����z"HTTPResponse.get_redirect_locationc�������������C���s(���|�j�r|�jsd�S�|�j��|�j��d�|�_d�S�)N)rd���re���Z _put_conn)r���r���r���r ����release_conn��s����zHTTPResponse.release_connc�������������C���s.���y|������W�n�ttttfk r(���Y�nX�dS�)z� Read and discard any remaining HTTP response data in the response connection. Unread data in the HTTPResponse connection blocks the connection from being released back to the pool. N)rN���r����SocketErrorr���r ���)r���r���r���r ���� drain_conn��s����zHTTPResponse.drain_connc�������������C���s"���|�j�r|�j�S�|�jr|�jdd�S�d�S�)NT)� cache_content)r]���r^���rN���)r���r���r���r ���r'���%��s����zHTTPResponse.datac�������������C���s���|�j�S�)N)re���)r���r���r���r ���rn���.��s����zHTTPResponse.connectionc�������������C���s ���t�|�j�S�)N)r���r^���)r���r���r���r ����isclosed2��s����zHTTPResponse.isclosedc�������������C���s���|�j�S�)z� Obtain the number of bytes pulled over the wire so far. May differ from the amount of content returned by :meth:``urllib3.response.HTTPResponse.read`` if bytes are encoded on the wire (e.g, compressed). )r`���)r���r���r���r ����tell5��s����zHTTPResponse.tellc�������������C���s����|�j��d�}|dk r�|�jr(t�d��dS�y<tdd��|�d�D���}t|�dkrZtd|���|� ��}W�n�t k r|���d}Y�nX�|d k�r�d}yt|�j�}W�n�t k r����d }Y�nX�|d ks�d|��kr�dk�s�n�|d kr�d }|S�)zM Set initial length value for Response content if available. zcontent-lengthNz�Received response with both Content-Length and Transfer-Encoding set. This is expressly forbidden by RFC 7230 sec 3.3.2. Ignoring Content-Length and attempting to process response as Transfer-Encoding: chunked.c�������������S���s���g�|�]}t�|��qS�r���)�int)r?����valr���r���r ���rA���W��s����z-HTTPResponse._init_length.<locals>.<listcomp>rB���r���z8Content-Length contained multiple unmatching values (%s)r���)�����i0���d��������ZHEAD) rT���rg���rQ����log�warning�setrC����lenr����pop� ValueErrorrz���rU���)r���ro����lengthZlengthsrU���r���r���r ���ri���=��s0���� &zHTTPResponse._init_lengthc����������������sh�����j��dd����}��jdkrd|��jkr2t|���_n2d|krd��fdd�|�d�D��}t|�rdt|���_dS�)z= Set-up the _decoder attribute if necessary. zcontent-encodingrM���NrB���c����������������s"���g�|�]}|������jkr|�����qS�r���)r>����CONTENT_DECODERS)r?����e)r���r���r ���rA���}��s���z.HTTPResponse._init_decoder.<locals>.<listcomp>)rT���rg���rh���r\���r����r=���rC���r����)r����content_encodingrp���r���)r���r ���� _init_decoderq��s���� zHTTPResponse._init_decoderc���������� ���C���sx���|s|S�y|�j�r|�j��|�}W�nD�|�jk rb�}�z$|�j�dd����}td|�|��W�dd}~X�Y�nX�|rt||����7�}|S�)zN Decode the data passed in and potentially flush the decoder. zcontent-encodingrM���zEReceived response with content-encoding: %s, but failed to decode it.N)r\���r%����DECODER_ERROR_CLASSESrT���rg���rh���r����_flush_decoder)r���r'���rR���� flush_decoderr����r����r���r���r ����_decode���s����zHTTPResponse._decodec�������������C���s$���|�j�r |�j��d�}||�j�����S�dS�)zk Flushes the decoder. Should only be called if the decoder is actually being used. r���)r\���r%���r;���)r����bufr���r���r ���r�������s����zHTTPResponse._flush_decoderc���������� ���c���s����d}z�y dV��W�n��t�k r2���t|�jdd��Y�nv�tk rt�}�z&dt|�krVt|��t|�jdd��W�dd}~X�Y�n4�ttfk r��}�ztd|�|��W�dd}~X�Y�nX�d}W�d|s�|�j r�|�j � ���|�jr�|�j� ���|�j r�|�j ���r�|�� ���X�dS�)z� Catch low-level python exceptions, instead re-raising urllib3 variants, so that low-level exceptions are not leaked in the high-level api. On exit, release the connection back to the pool. FNzRead timed out.zread operation timed outzConnection broken: %rT)� SocketTimeoutr���rd���r����strr���r ���ru���r���r_����closere���rx���rt���)r���Z clean_exitr����r���r���r ����_error_catcher���s(���� zHTTPResponse._error_catcherc���������� ���C���s��|������|dkr|�j}|�jdkr$dS�d}t|�jdd�}|�����v�|dkr`|sV|�j���nd}d}nPd}|st|�j�|�nd}|dkr�|s�|�j����d}|�jr�|�jdkr�t |�j |�j��W�dQ�R�X�|�r|��j t|�7��_ |�jdk r�|��jt|�8��_|��|||�}|�r||�_ |S�)aT�� Similar to :meth:`http.client.HTTPResponse.read`, but with two additional parameters: ``decode_content`` and ``cache_content``. :param amt: How much of the content to read. If specified, caching is skipped because it doesn't make sense to cache partial content as the full response. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. :param cache_content: If True, will save the returned data such that the same result is returned despite of the state of the underlying file object. This is useful if you want the ``.data`` property to continue working after having ``.read()`` the file object. (Overridden if ``amt`` is set.) NF�closedr���Tr���)r���N)r����rR���r^���r"���r����rN���r����rZ���rj���r ���r`���r����r����r]���)r����amtrR���rw���r����Z fp_closedr'���r���r���r ���rN������s6���� zHTTPResponse.read����c�������������c���sZ���|�j�r.|����r.xF|�j||d�D�] }|V��qW�n(x&t|�j�sT|�j||d�}|r0|V��q0W�dS�)a_�� A generator wrapper for the read() method. A call will block until ``amt`` bytes have been read from the connection or until the connection is closed. :param amt: How much of the content to read. The generator will return up to much data per iteration, but may return less. This is particularly likely when using compressed data. However, the empty string will never be returned. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. )rR���)r����rR���N)rQ����supports_chunked_reads�read_chunkedr���r^���rN���)r���r����rR����liner'���r���r���r ����stream+��s����zHTTPResponse.streamc���������� ���K���sb���|j�}t|t�s.tjr"t�|�}nt|����}t|dd�}|�f�|||j|j |j ||d�|��}|S�)a�� Given an :class:`http.client.HTTPResponse` instance ``r``, return a corresponding :class:`urllib3.response.HTTPResponse` object. Remaining parameters are passed to the HTTPResponse constructor, along with ``original_response=r``. rX���r���)rk���rT���rU���rV���rW���rX���rl���)ra���rS���r���r����PY2�from_httplib�itemsr"���rU���rV���rW���)ZResponseCls�rZresponse_kwrT���rX���Zrespr���r���r ���r����E��s ���� zHTTPResponse.from_httplibc�������������C���s���|�j�S�)N)rT���)r���r���r���r ���� getheadersf��s����zHTTPResponse.getheadersc�������������C���s���|�j��||�S�)N)rT���rg���)r���r#����defaultr���r���r ���� getheaderi��s����zHTTPResponse.getheaderc�������������C���s���|�j�S�)N)rT���)r���r���r���r ����infom��s����zHTTPResponse.infoc�������������C���s6���|�j�s|�j����|�jr |�j����|�js2tj�|���d�S�)N)r����r^���r����re���r[����io�IOBase)r���r���r���r ���r����q��s���� zHTTPResponse.closec�������������C���sT���|�j�stjj�|��S�|�jd�kr"dS�t|�jd�r8|�j���S�t|�jd�rL|�jjS�dS�d�S�)NTrx���r����)r[���r����r����r�����__get__r^���r9���rx���)r���r���r���r ���r����{��s���� zHTTPResponse.closedc�������������C���s6���|�j�d�krtd��nt|�j�d�r*|�j����S�td��d�S�)Nz-HTTPResponse has no file to get a fileno from�filenozOThe file-like object this HTTPResponse is wrapped around has no file descriptor)r^����IOErrorr9���r����)r���r���r���r ���r�������s���� zHTTPResponse.filenoc�������������C���s2���|�j�d�k r.t|�j�d�r.t|�j�dd�s.|�j����S�d�S�)Nr;���r����F)r^���r9���r"���r;���)r���r���r���r ���r;������s���� zHTTPResponse.flushc�������������C���s���dS�)NTr���)r���r���r���r ����readable���s����zHTTPResponse.readablec�������������C���s:���|���t|��}t|�dkrdS�||d�t|��<�t|�S�d�S�)Nr���)rN���r����)r����b�tempr���r���r ����readinto���s ����zHTTPResponse.readintoc�������������C���s���t�|�jd�S�)a�� Checks if the underlying file-like object looks like a :class:`http.client.HTTPResponse` object. We do this by testing for the fp attribute. If it is present we assume it returns raw chunks as processed by read_chunked(). �fp)r9���r^���)r���r���r���r ���r�������s����z#HTTPResponse.supports_chunked_readsc�������������C���sf���|�j�d�k rd�S�|�jj���}|�dd�d�}yt|d�|�_�W�n&�tk r`���|�����t|�|��Y�nX�d�S�)N����;r���r���r1���) rf���r^���r�����readlinerC���rz���r����r����r���)r���r����r���r���r ����_update_chunk_length���s���� z!HTTPResponse._update_chunk_lengthc�������������C���s����d�}|d�kr2|�j��|�j�}|}|�j��d��d�|�_nv||�jk�rZ|�j��|�}|�j|�|�_|}nN||�jkr�|�j��|�}|�j��d��d�|�_|}n |�j��|�j�}|�j��d��d�|�_|S�)Nr,���)r^���Z _safe_readrf���)r���r����Zreturned_chunk�chunk�valuer���r���r ���� _handle_chunk���s&���� zHTTPResponse._handle_chunkc���������� ���c���s����|������|�jstd��|����s&td��|�������|�jrNt|�j�rN|�j����dS�|�j j dkr^dS�x<|�����|�jdkrtP�|�� |�}|�j||dd�}|r`|V��q`W�|r�|����}|r�|V��x |�j j ���}|s�P�|dkr�P�q�W�|�jr�|�j����W�dQ�R�X�dS�)a��� Similar to :meth:`HTTPResponse.read`, but with an additional parameter: ``decode_content``. :param amt: How much of the content to read. If specified, caching is skipped because it doesn't make sense to cache partial content as the full response. :param decode_content: If True, will attempt to decode the body based on the 'content-encoding' header. zHResponse is not chunked. Header 'transfer-encoding: chunked' is missing.zkBody should be http.client.HTTPResponse like. It should have have an fp attribute which returns raw chunks.Nr���F)rR���r����s��� )r����rQ���r���r����r ���r����r_���r���r����r^���r����r����rf���r����r����r����r����)r���r����rR���r�����decodedr����r���r���r ���r�������sD���� zHTTPResponse.read_chunkedc�������������C���s.���|�j�dk r$t|�j�j�r$|�j�jd�jS�|�jS�dS�)z� Returns the URL that was the source of this response. If the request that generated this response redirected, this method will return the final redirect location. N���)rY���r�����historyZredirect_locationrb���)r���r���r���r ����geturl��s����zHTTPResponse.geturlc�������������c���s����g�}x�|�j�dd�D�]r}d|krz|�d�}d�|�|d��d�V��x|dd��D�]}|d�V��qNW�|d�rt|d�g}q�g�}q|�|��qW�|r�d�|�V��d�S�)NT)rR������� r���r���r���r����)r����rC����join�append)r����bufferr�����xr���r���r ����__iter__&��s���� zHTTPResponse.__iter__)rM���Nr���r���Nr���TTNNNNNFNNT)NNF)r����N)N)NN)-r(���r)���r*���rG���r����r8���rr���r!���rs���rt���rv����propertyr'���rn���rx���ry���ri���r����r����r���r���r����r����r����r���r����rN���r�����classmethodr����r����r����r����r����r����r����r;���r����r����r����r����r����r����r����r����r���r���r���r ���rK�������sn��� ���������������� 1 4 8 J ! FrK���)/� __future__r���r�����loggingr���� contextlibr����socketr���ru���r���r����r8����ImportError�_collectionsr���rn���r���r ���� exceptionsr ���r���r���r ���r���r���r���r���r���r����packagesr���Z util.responser���r���� getLoggerr(���r����objectr���r+���r0���r7���r<���r=���r����rK���r���r���r���r ����<module>���s0��� 0