
    3 d~                         d dl 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	  e j
        de j                  Z G d d          Zd	 Z G d
 d          Z G d d          Z G d d          ZdS )    N)	CookieJar)DefaultCookiePolicy)urlparse_cached
to_unicodez\.\d+$c                   j    e Zd ZddZd Zd Zed             Zd ZddZ	d	 Z
d
 Zd Zd Zd Zd ZdS )r   N'  c                     |pt                      | _        t          | j                  | _        t	                      | j        _        || _        d| _        d S )Nr   )r   policy
_CookieJarjar
_DummyLock_cookies_lockcheck_expired_frequency	processed)selfr   r   s      3lib/python3.11/site-packages/scrapy/http/cookies.py__init__zCookieJar.__init__   sG    5 3 5 5dk**!+'>$    c                 t    t          |          }t          |          }| j                            ||          S N)WrappedRequestWrappedResponser   extract_cookiesr   responserequestwreqwrsps        r   r   zCookieJar.extract_cookies   s4    g&&x((x''d333r   c                    t          |          }t          t          j                              x| j        _        | j        _        t          |          j        }|sd S t          	                    |          st          |          }d|vr	||dz   gz  }n|g}g }|D ].}|| j        j        v r|| j                            ||          z  }/| j                            |          }|r>|                    d          s)|                    dd                    |                     | xj        dz  c_        | j        | j        z  dk    r| j                                         d S d S )N.z.localCookiez;    r   )r   inttimer   _nowr   r   hostnameIPV4_REsearchpotential_domain_matches_cookies_cookies_for_domain_cookie_attrs
has_headeradd_unredirected_headerjoinr   r   clear_expired_cookies)r   r   r   req_hosthostscookieshostattrss           r   add_cookie_headerzCookieJar.add_cookie_header   s}   g&&+.ty{{+;+;;48= #7++4 	F~~h'' 	,X66E(" /(X-..JE 	D 	DDtx(( D4877dCCC&&w// 	I??8,, I,,Xtyy7G7GHHH!>D88A= 	-H**,,,,,	- 	-r   c                     | j         j        S r   )r   r+   r   s    r   r+   zCookieJar._cookies;   s    x  r   c                 &     | j         j        |i |S r   )r   clear_session_cookies)r   argskwargss      r   r;   zCookieJar.clear_session_cookies?   s    -tx-t>v>>>r   c                 :    | j                             |||          S r   )r   clear)r   domainpathnames       r   r?   zCookieJar.clearB   s    x~~fdD111r   c                 *    t          | j                  S r   )iterr   r9   s    r   __iter__zCookieJar.__iter__E   s    DH~~r   c                 *    t          | j                  S r   )lenr   r9   s    r   __len__zCookieJar.__len__H   s    48}}r   c                 6    | j                             |          S r   )r   
set_policy)r   pols     r   rJ   zCookieJar.set_policyK   s    x""3'''r   c                 t    t          |          }t          |          }| j                            ||          S r   )r   r   r   make_cookiesr   s        r   rM   zCookieJar.make_cookiesN   s4    g&&x((x$$T4000r   c                 :    | j                             |           d S r   )r   
set_cookie)r   cookies     r   rO   zCookieJar.set_cookieS   s    F#####r   c                 V    | j                             |t          |                     d S r   )r   set_cookie_if_okr   )r   rP   r   s      r   rR   zCookieJar.set_cookie_if_okV   s(    !!&.*A*ABBBBBr   )Nr	   )NNN)__name__
__module____qualname__r   r   r7   propertyr+   r;   r?   rE   rH   rJ   rM   rO   rR    r   r   r   r      s           4 4 4
- - -@ ! ! X!? ? ?2 2 2 2    ( ( (1 1 1
$ $ $C C C C Cr   r   c                 (   | g}	 |                      d          dz   }|                     d          }||k     r<|                    | |d                    |                      d|          dz   }||k     <n# t          $ r Y nw xY w|d |D             z   S )zPotential domain matches for a cookie

    >>> potential_domain_matches('www.example.com')
    ['www.example.com', 'example.com', '.www.example.com', '.example.com']

    r!   r#   Nc                     g | ]}d |z   S )r!   rW   ).0ds     r   
<listcomp>z,potential_domain_matches.<locals>.<listcomp>j   s    ///!cAg///r   )indexrindexappend
ValueError)r@   matchesstartends       r   r*   r*   Z   s     hGS!!A%mmC  ck 	1NN6%&&>***LLe,,q0E ck 	1    //w/////s   A/A5 5
BBc                       e Zd Zd Zd ZdS )r   c                     d S r   rW   r9   s    r   acquirez_DummyLock.acquiren       r   c                     d S r   rW   r9   s    r   releasez_DummyLock.releaseq   rg   r   N)rS   rT   rU   rf   ri   rW   r   r   r   r   m   s2              r   r   c                       e Zd ZdZd Zd Zd Zd Zd Ze	d             Z
e	d             Ze	d	             Ze	d
             Ze	d             Zd ZddZd Zd ZdS )r   zWraps a scrapy Request class with methods defined by urllib2.Request class to interact with CookieJar class

    see http://docs.python.org/library/urllib2.html#urllib2.Request
    c                     || _         d S r   )r   )r   r   s     r   r   zWrappedRequest.__init__{   s    r   c                     | j         j        S r   )r   urlr9   s    r   get_full_urlzWrappedRequest.get_full_url~   s    |r   c                 4    t          | j                  j        S r   )r   r   netlocr9   s    r   get_hostzWrappedRequest.get_host       t|,,33r   c                 4    t          | j                  j        S r   )r   r   schemer9   s    r   get_typezWrappedRequest.get_type   rr   r   c                 B    | j         j                            dd          S )a  Unverifiable should indicate whether the request is unverifiable, as defined by RFC 2965.

        It defaults to False. An unverifiable request is one whose URL the user did not have the
        option to approve. For example, if the request is for an image in an
        HTML document, and the user had no option to approve the automatic
        fetching of the image, this should be true.
        is_unverifiableF)r   metagetr9   s    r   rw   zWrappedRequest.is_unverifiable   s      | $$%6>>>r   c                 *    |                                  S r   )rn   r9   s    r   full_urlzWrappedRequest.full_url   s      """r   c                 *    |                                  S r   )rq   r9   s    r   r5   zWrappedRequest.host       }}r   c                 *    |                                  S r   )ru   r9   s    r   typezWrappedRequest.type   r}   r   c                 *    |                                  S r   )rw   r9   s    r   unverifiablezWrappedRequest.unverifiable   s    ##%%%r   c                 4    t          | j                  j        S r   )r   r   r'   r9   s    r   origin_req_hostzWrappedRequest.origin_req_host   s    t|,,55r   c                     || j         j        v S r   )r   headers)r   rB   s     r   r.   zWrappedRequest.has_header   s    t|+++r   Nc                 `    t          | j        j                            ||          d          S )Nreplaceerrors)r   r   r   ry   r   rB   defaults      r   
get_headerzWrappedRequest.get_header   s*    $,.224AA)TTTTr   c                 R    d | j         j                                        D             S )Nc                 N    g | ]"\  }}t          |d           d |D             f#S )r   r   c                 0    g | ]}t          |d           S r   r   r   )rZ   xs     r   r\   z:WrappedRequest.header_items.<locals>.<listcomp>.<listcomp>   s%    <<<QAi000<<<r   r   )rZ   kvs      r   r\   z/WrappedRequest.header_items.<locals>.<listcomp>   sQ     
 
 

 1 1Y///<<!<<<
 
 
r   )r   r   itemsr9   s    r   header_itemszWrappedRequest.header_items   s6    
 

 ,2244
 
 
 	
r   c                 F    | j         j                            ||           d S r   )r   r   
appendlist)r   rB   values      r   r/   z&WrappedRequest.add_unredirected_header   s#    ''e44444r   r   )rS   rT   rU   __doc__r   rn   rq   ru   rw   rV   r{   r5   r   r   r   r.   r   r   r/   rW   r   r   r   r   u   s5        
       4 4 44 4 4? ? ? # # X#   X   X & & X& 6 6 X6, , ,U U U U
 
 
5 5 5 5 5r   r   c                   "    e Zd Zd Zd ZddZdS )r   c                     || _         d S r   )r   )r   r   s     r   r   zWrappedResponse.__init__   s     r   c                     | S r   rW   r9   s    r   infozWrappedResponse.info   s    r   Nc                 T    d | j         j                            |          D             S )Nc                 0    g | ]}t          |d           S r   r   )rZ   r   s     r   r\   z+WrappedResponse.get_all.<locals>.<listcomp>   s2     
 
 
01Jq+++
 
 
r   )r   r   getlistr   s      r   get_allzWrappedResponse.get_all   s7    
 
59]5J5R5RSW5X5X
 
 
 	
r   r   )rS   rT   rU   r   r   r   rW   r   r   r   r      sF        ! ! !  
 
 
 
 
 
r   r   )rer%   http.cookiejarr   r   r   scrapy.utils.httpobjr   scrapy.utils.pythonr   compileASCIIr(   r*   r   r   r   rW   r   r   <module>r      sI   				  2 2 2 2 2 2 . . . . . . 0 0 0 0 0 0 * * * * * * "*Y
)
)IC IC IC IC IC IC IC ICX0 0 0&       @5 @5 @5 @5 @5 @5 @5 @5F

 

 

 

 

 

 

 

 

 

r   