
    3 db                         d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ  G d
 de          ZdS )z
This module implements the Response class which is used to represent HTTP
responses in Scrapy.

See documentation in docs/topics/request-response.rst
    )	GeneratorTuple)urljoinNotSupported)obsolete_setter)Headers)Request)Link)
object_refc                      e Zd ZU dZdZeedf         ed<   	 	 	 	 	 	 	 	 	 ddefd	Ze	d
             Z
e	d             Zd ZdefdZ e	e eed                    Zd Zd Z e	e eed                    Zd Zd Zd Zd Ze	d             Zd Zd Z	 	 	 	 	 	 	 	 	 	 	 	 d defdZ	 	 	 	 	 	 	 	 	 	 	 	 d deeddf         fdZdS )!ResponsezAn object that represents an HTTP response, which is usually
    downloaded (by the Downloader) and fed to the Spiders for processing.
    )	urlstatusheadersbodyflagsrequestcertificate
ip_addressprotocol.
attributes   N    r   c
                    t          |pi           | _        t          |          | _        |                     |           |                     |           || _        |g nt          |          | _        || _	        || _
        |	| _        d S N)r	   r   intr   	_set_body_set_urlr   listr   r   r   r   )
selfr   r   r   r   r   r   r   r   r   s
             =lib/python3.11/site-packages/scrapy/http/response/__init__.py__init__zResponse.__init__)   s     w}"--&kktc 9RRd5kk
&$ r   c                 V    	 | j         j        S # t          $ r t          d          w xY w)NzJResponse.cb_kwargs not available, this response is not tied to any request)r   	cb_kwargsAttributeErrorr!   s    r"   r%   zResponse.cb_kwargs?   sD    	<)) 	 	 	 -  	    (c                 V    	 | j         j        S # t          $ r t          d          w xY w)NzEResponse.meta not available, this response is not tied to any request)r   metar&   r'   s    r"   r*   zResponse.metaI   sD    	<$$ 	 	 	 -  	r(   c                     | j         S r   )_urlr'   s    r"   _get_urlzResponse._get_urlS   s
    yr   c                     t          |t                    r	|| _        d S t          t	          |           j         dt	          |          j                   )Nz url must be str, got )
isinstancestrr,   	TypeErrortype__name__r!   r   s     r"   r   zResponse._set_urlV   sT    c3 	DIII::&VV$s))BTVV  r   c                     | j         S r   )_bodyr'   s    r"   	_get_bodyzResponse._get_body`   s
    zr   c                 r    |	d| _         d S t          |t                    st          d          || _         d S )Nr   z_Response body must be bytes. If you want to pass unicode body use TextResponse or HtmlResponse.)r6   r/   bytesr1   )r!   r   s     r"   r   zResponse._set_bodyc   sK     		DJJJD%(( 	#   DJJJr   r   c                 (    d| j          d| j         dS )N< >)r   r   r'   s    r"   __repr__zResponse.__repr__q   s    ,4;,,,,,,r   c                 *    |                                  S )zReturn a copy of this Response)replacer'   s    r"   copyzResponse.copyt   s    ||~~r   c                     | j         D ]&}|                    |t          | |                     '|                    d| j                  } ||i |S )zPCreate a new Response with the same attributes except for those given new valuescls)r   
setdefaultgetattrpop	__class__)r!   argskwargsxrC   s        r"   r@   zResponse.replacex   s`     	3 	3Aaq!1!12222jj//sD#F###r   c                 ,    t          | j        |          S )zoJoin this Response's url with a possible relative url to form an
        absolute interpretation of the latter.)r   r   r4   s     r"   r   zResponse.urljoin   s     tx%%%r   c                      t          d          )zQFor subclasses of TextResponse, this will return the body
        as str
        Response content isn't text)r&   r'   s    r"   textzResponse.text   s    
 :;;;r   c                      t          d          zrShortcut method implemented only by responses whose content
        is text (subclasses of TextResponse).
        rM   r   r!   akws      r"   csszResponse.css        8999r   c                      t          d          rP   r   rQ   s      r"   xpathzResponse.xpath   rU   r   GETutf-8r   Freturnc                     t          |t                    r|j        }n|t          d          |                     |          }t          |||||||||	|
|||          S )a  
        Return a :class:`~.Request` instance to follow a link ``url``.
        It accepts the same arguments as ``Request.__init__`` method,
        but ``url`` can be a relative URL or a ``scrapy.link.Link`` object,
        not only an absolute URL.

        :class:`~.TextResponse` provides a :meth:`~.TextResponse.follow`
        method which supports selectors in addition to absolute/relative URLs
        and Link objects.

        .. versionadded:: 2.0
           The *flags* parameter.
        Nzurl can't be Noner   callbackmethodr   r   cookiesr*   encodingprioritydont_filtererrbackr%   r   )r/   r   r   
ValueErrorr   r
   )r!   r   r]   r^   r   r   r_   r*   r`   ra   rb   rc   r%   r   s                 r"   followzResponse.follow   s    : c4   	2'CC 	20111ll3#
 
 
 	
r   c                     	
 t          |d          st          d          
	 fd|D             S )a  
        .. versionadded:: 2.0

        Return an iterable of :class:`~.Request` instances to follow all links
        in ``urls``. It accepts the same arguments as ``Request.__init__`` method,
        but elements of ``urls`` can be relative URLs or :class:`~scrapy.link.Link` objects,
        not only absolute URLs.

        :class:`~.TextResponse` provides a :meth:`~.TextResponse.follow_all`
        method which supports selectors in addition to absolute/relative URLs
        and Link objects.
        __iter__z#'urls' argument must be an iterablec              3   \   K   | ]&}                     |
	           V  'dS )r\   N)re   ).0r   r   r]   r%   r_   rb   r`   rc   r   r   r*   r^   ra   r!   s     r"   	<genexpr>z&Response.follow_all.<locals>.<genexpr>   ss       
 
   KK!!!'#   
 
 
 
 
 
r   )hasattrr1   )r!   urlsr]   r^   r   r   r_   r*   r`   ra   rb   rc   r%   r   s   ` ````````````r"   
follow_allzResponse.follow_all   s    8 tZ(( 	CABBB
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  !
 
 
 	
r   )r   Nr   NNNNN)NrX   NNNNrY   r   FNNN)r3   
__module____qualname____doc__r   r   r0   __annotations__r#   propertyr%   r*   r-   r   r   r   r7   r   r   r>   rA   r@   r   rN   rT   rW   r
   re   r   rm    r   r"   r   r      sP         
#Jc3h 
 
 
 ! !! ! ! !,   X   X  C     (8__Xu==
>
>C  
 
 
 8Iy&AABBD- - -  $ $ $& & &
 < < X<: : :: : : 1
 1
 
1
 1
 1
 1
l /
 /
 
7D$&	'/
 /
 /
 /
 /
 /
r   r   N)rp   typingr   r   urllib.parser   scrapy.exceptionsr   scrapy.http.commonr   scrapy.http.headersr	   scrapy.http.requestr
   scrapy.linkr   scrapy.utils.trackrefr   r   rs   r   r"   <module>r|      s     $ # # # # # # #             * * * * * * . . . . . . ' ' ' ' ' ' ' ' ' ' ' '       , , , , , ,g
 g
 g
 g
 g
z g
 g
 g
 g
 g
r   