
    3 df$                         d Z ddlZddlmZmZmZmZmZmZm	Z	 ddl
mZ ddl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  edd          Zd Z G d de          Zd ZdS )z
This module implements the Request class which is used to represent HTTP
requests in Scrapy.

See documentation in docs/topics/request-response.rst
    N)CallableListOptionalTupleTypeTypeVarUnion)safe_url_string)obsolete_setter)Headers)curl_to_request_kwargs)to_bytes)
object_ref)escape_ajaxRequestTypeVarRequest)boundc                       t          d          )an  When assigned to the ``callback`` parameter of
    :class:`~scrapy.http.Request`, it indicates that the request is not meant
    to have a spider callback at all.

    For example:

    .. code-block:: python

       Request("https://example.com", callback=NO_CALLBACK)

    This value should be used by :ref:`components <topics-components>` that
    create and handle their own requests, e.g. through
    :meth:`scrapy.core.engine.ExecutionEngine.download`, so that downloader
    middlewares handling such requests can treat them differently from requests
    intended for the :meth:`~scrapy.Spider.parse` callback.
    zThe NO_CALLBACK callback has been called. This is a special callback value intended for requests whose callback is never meant to be called.)RuntimeError)argskwargss     <lib/python3.11/site-packages/scrapy/http/request/__init__.pyNO_CALLBACKr      s    " 	      c                      e Zd ZU dZdZeedf         ed<   	 	 	 	 	 	 	 	 	 	 	 	 	 d,d
edee	         dedee
         deeeef                  deee
ee
         f                  dee
         dedededee	         deee                  dee
         ddfdZede
fd            Zede
fd            ZdefdZd
eddfdZ ee eed
                    ZdefdZdeeeef                  ddfdZ ee eed                    Zedefd            Zdefd Zd-d!Zd-d"Ze	 d.d$e e!         d%ed&ede!fd'            Z"dd(d)ed*         de
fd+Z#dS )/r   zRepresents an HTTP request, which is usually generated in a Spider and
    executed by the Downloader, thus generating a :class:`Response`.
    )urlcallbackmethodheadersbodycookiesmetaencodingprioritydont_filtererrbackflags	cb_kwargs.
attributesNGETutf-8r   Fr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   returnc                    || _         t          |                                          | _        |                     |           |                     |           t          |	t                    st          d|	          |	| _	        t          |          s&|$t          dt          |          j                   t          |          s&|$t          dt          |          j                   || _        || _        |pi | _        t!          |pi |          | _        |
| _        |rt'          |          nd | _        |rt'          |          nd | _        |g nt-          |          | _        d S )Nz!Request priority not an integer: z!callback must be a callable, got z errback must be a callable, got )r#   )	_encodingstrupperr   _set_url	_set_body
isinstanceint	TypeErrorr$   callabletype__name__r   r&   r!   r   r   r%   dict_meta
_cb_kwargslistr'   )selfr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   s                 r   __init__zRequest.__init__K   sp     "&kk''))ct(C(( 	NLLLMMM "" 	h 	MDNN4KMM   !! 	YW 	YWtG}}?UWWXXX }"w}"x@@@&#'1T$ZZZT
-6@$y///D 9RRd5kk


r   c                 ,    | j         i | _         | j         S N)r;   r=   s    r   r(   zRequest.cb_kwargst   s    ? 	! DOr   c                 ,    | j         i | _         | j         S r@   )r:   rA   s    r   r"   zRequest.metaz   s    : 	DJzr   c                     | j         S r@   )_urlrA   s    r   _get_urlzRequest._get_url   s
    yr   c                 z   t          |t                    s$t          dt          |          j                   t          || j                  }t          |          | _        d| j        vrK| j        	                    d          s3| j        	                    d          st          d| j                   d S d S d S )NzRequest url must be str, got z://zabout:zdata:zMissing scheme in request url: )r3   r/   r5   r7   r8   r
   r#   r   rD   
startswith
ValueError)r=   r   ss      r   r1   zRequest._set_url   s    #s## 	RPDII<NPPQQQC//NN	 "	LI((22	L I((11	L
 JtyJJKKK	L 	L 	L 	L 	L 	Lr   c                     | j         S r@   )_bodyrA   s    r   	_get_bodyzRequest._get_body   s
    zr   c                 B    |dnt          || j                  | _        d S )Nr   )r   r#   rK   )r=   r    s     r   r2   zRequest._set_body   s"     KSShtT].K.K


r   c                     | j         S r@   )r.   rA   s    r   r#   zRequest.encoding   s
    ~r   c                 (    d| j          d| j         dS )N< >)r   r   rA   s    r   __repr__zRequest.__repr__   s    ,4;,,,,,,r   c                 *    |                                  S r@   )replacerA   s    r   copyzRequest.copy   s    ||~~r   c                     | j         D ]&}|                    |t          | |                     '|                    d| j                  } ||i |S )zOCreate a new Request with the same attributes except for those given new valuescls)r)   
setdefaultgetattrpop	__class__)r=   r   r   xrX   s        r   rU   zRequest.replace   s`     	3 	3Aaq!1!12222jj//sD#F###r   TrX   curl_commandignore_unknown_optionsc                 \    t          ||          }|                    |            | di |S )a	  Create a Request object from a string containing a `cURL
        <https://curl.haxx.se/>`_ command. It populates the HTTP method, the
        URL, the headers, the cookies and the body. It accepts the same
        arguments as the :class:`Request` class, taking preference and
        overriding the values of the same arguments contained in the cURL
        command.

        Unrecognized options are ignored by default. To raise an error when
        finding unknown options call this method by passing
        ``ignore_unknown_options=False``.

        .. caution:: Using :meth:`from_curl` from :class:`~scrapy.http.Request`
                     subclasses, such as :class:`~scrapy.http.JSONRequest`, or
                     :class:`~scrapy.http.XmlRpcRequest`, as well as having
                     :ref:`downloader middlewares <topics-downloader-middleware>`
                     and
                     :ref:`spider middlewares <topics-spider-middleware>`
                     enabled, such as
                     :class:`~scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware`,
                     :class:`~scrapy.downloadermiddlewares.useragent.UserAgentMiddleware`,
                     or
                     :class:`~scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware`,
                     may modify the :class:`~scrapy.http.Request` object.

        To translate a cURL command into a Scrapy request,
        you may use `curl2scrapy <https://michael-shub.github.io/curl2scrapy/>`_.
         )r   update)rX   r^   r_   r   request_kwargss        r   	from_curlzRequest.from_curl   s?    D 0>TUUf%%%s$$^$$$r   )spiderre   zscrapy.Spiderc                   | j         t          | j                  rt          || j                  n| j        t          | j                  rt          || j                  n| j        t          | j                  d}| j        D ]&}|                    |t          | |                     't          |           t          ur| j        dz   | j        j        z   |d<   |S )a  Return a dictionary containing the Request's data.

        Use :func:`~scrapy.utils.request.request_from_dict` to convert back into a :class:`~scrapy.Request` object.

        If a spider is given, this method will try to find out the name of the spider methods used as callback
        and errback and include them in the output dict, raising an exception if they cannot be found.
        )r   r   r&   r   ._class)r   r6   r   _find_methodr&   r9   r   r)   rY   rZ   r7   r   
__module__r\   r8   )r=   re   dattrs       r   to_dictzRequest.to_dict   s     8&&VT];;;%%|FDL999DL))	
 	
 O 	4 	4DLLwtT223333::W$ 	J/C/$.2IIAhKr   )Nr*   NNNNr+   r   FNNN)r,   r   )T)$r8   rj   __qualname____doc__r)   r   r/   __annotations__r   r   r9   r	   bytesr   r4   boolr>   propertyr(   r"   rE   r1   r   r   rL   r2   r    r#   rS   rV   rU   classmethodr   r   rd   rm   ra   r   r   r   r   /   sb         #Jc3h    (,"&,059#!&*%)$(': ':': 8$': 	':
 $': uUCZ()': %d4j 012': tn': ': ': ': (#': S	"': D>': 
': ': ': ':R 4    X
 d    X
#    LC LD L L L L (8__Xu==
>
>C5    LhuS%Z'89 Ld L L L L 8Iy&AABBD#    X-# - - - -   $ $ $ $  (,#% #%.!#%#% !%#%
 
#% #% #% [#%J >B   /!: d      r   c                     | rJt          |d          r:t          j        | t          j                  }|D ]\  }}|j        |j        u r|c S t          d| d|            )z#Helper function for Request.to_dict__func__)	predicatez	Function z is not an instance method in: )hasattrinspect
getmembersismethodrv   rH   )objfuncmembersnameobj_funcs        r   ri   ri      s      	wtZ(( 	$SG4DEEE% 	 	ND(  DM1 
KKKcKK
L
LLr   )ro   ry   typingr   r   r   r   r   r   r	   	w3lib.urlr
   scrapyscrapy.http.commonr   scrapy.http.headersr   scrapy.utils.curlr   scrapy.utils.pythonr   scrapy.utils.trackrefr   scrapy.utils.urlr   r   r   r   ri   ra   r   r   <module>r      sL     H H H H H H H H H H H H H H H H H H % % % % % %  . . . . . . ' ' ' ' ' ' 4 4 4 4 4 4 ( ( ( ( ( ( , , , , , , ( ( ( ( ( ();;;  0y y y y yj y y yxM M M M Mr   