
    !h:              	      |   % S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
  SSKJrJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSKJr  \(       a  SSKJr  SSKJr  SSKJ r   Sr!S\"S'   Sr#Sr$Sr%Sr&Sr'Sr(Sr)Sr*Sr+ " S S5      r, " S S \,5      r- " S! S"\,5      r. " S# S$\,5      r/ " S% S&\,5      r0 " S' S(\,5      r1 " S) S*\,5      r2 " S+ S,\,5      r3 " S- S.\,5      r4 " S/ S0\.5      r5\-\.\/\0\1\2\3\4\54	 V s0 s H  n U Rl                  U _M     sn r7S1\"S2'   \.\7S3'    S7     S8S4 jjr8 " S5 S6\5      r9gs  sn f )9z`
RefererMiddleware: populates Request referer field, based on the Response which
originated it.
    )annotationsN)TYPE_CHECKINGcast)urlparse)safe_url_string)Spidersignals)NotConfigured)RequestResponse)BaseSpiderMiddleware)load_object)
to_unicode	strip_url)Self)Crawler)BaseSettings)aboutblobdata
filesystemtuple[str, ...]LOCAL_SCHEMESzno-referrerzno-referrer-when-downgradezsame-originoriginzstrict-originzorigin-when-cross-originzstrict-origin-when-cross-originz
unsafe-urlzscrapy-defaultc                  x    \ rS rSr% \rS\S'   S\S'   SS jrSS jrSS jr	SSS	 jjr
SS
 jrSS jrSS jrSrg)ReferrerPolicy0   r   NOREFERRER_SCHEMESstrnamec                    [         eN)NotImplementedErrorselfresponse_urlrequest_urls      g/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/spidermiddlewares/referer.pyreferrerReferrerPolicy.referrer4   s    !!    c                l    [        U5      R                  U R                  ;  a  U R                  U5      $ g r#   )r   schemer   r   r&   urls     r)   stripped_referrer ReferrerPolicy.stripped_referrer7   s,    C=t'>'>>>>#&&r,   c                l    [        U5      R                  U R                  ;  a  U R                  U5      $ g r#   )r   r.   r   r   r/   s     r)   origin_referrerReferrerPolicy.origin_referrer<   s,    C=t'>'>>;;s##r,   c                ,    U(       d  g[        USSSUS9$ )a_  
https://www.w3.org/TR/referrer-policy/#strip-url

If url is null, return no referrer.
If url's scheme is a local scheme, then return no referrer.
Set url's username to the empty string.
Set url's password to null.
Set url's fragment to null.
If the origin-only flag is true, then:
    Set url's path to null.
    Set url's query to null.
Return url.
NT)strip_credentialsstrip_fragmentstrip_default_portorigin_onlyr   )r&   r0   r:   s      r)   r   ReferrerPolicy.strip_urlA   s&     "##
 	
r,   c                "    U R                  USS9$ )zLReturn serialized origin (scheme, host, path) for a request or response URL.T)r:   r   r/   s     r)   r   ReferrerPolicy.originY   s    ~~ct~44r,   c                \    [        U5      nUR                  S;   a  gU R                  U5      $ )N)r   F)r   r.   tls_protected)r&   r0   
parsed_urls      r)   potentially_trustworthy&ReferrerPolicy.potentially_trustworthy]   s-    c]
	)!!#&&r,   c                2    [        U5      R                  S;   $ )N)httpsftps)r   r.   r/   s     r)   r?   ReferrerPolicy.tls_protectedd   s    }##'888r,    Nr'   r    r(   r    return
str | None)r0   r    rI   rJ   F)r0   r    r:   boolrI   rJ   )r0   r    rI   rL   )__name__
__module____qualname____firstlineno__r   r   __annotations__r*   r1   r4   r   r   rA   r?   __static_attributes__rG   r,   r)   r   r   0   s5    *77
I"


05'9r,   r   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	NoReferrerPolicyh   a  
https://www.w3.org/TR/referrer-policy/#referrer-policy-no-referrer

The simplest policy is "no-referrer", which specifies that no referrer information
is to be sent along with requests made from a particular request client to any origin.
The header will be omitted entirely.
r    r!   c                    g r#   rG   r%   s      r)   r*   NoReferrerPolicy.referrers   s    r,   rG   NrH   )
rM   rN   rO   rP   __doc__POLICY_NO_REFERRERr!   rQ   r*   rR   rG   r,   r)   rT   rT   h   s     #D#"r,   rT   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	NoReferrerWhenDowngradePolicyw   a3  
https://www.w3.org/TR/referrer-policy/#referrer-policy-no-referrer-when-downgrade

The "no-referrer-when-downgrade" policy sends a full URL along with requests
from a TLS-protected environment settings object to a potentially trustworthy URL,
and requests from clients which are not TLS-protected to any origin.

Requests from TLS-protected clients to non-potentially trustworthy URLs,
on the other hand, will contain no referrer information.
A Referer HTTP header will not be sent.

This is a user agent's default behavior, if no policy is otherwise specified.
r    r!   c                ~    U R                  U5      (       a  U R                  U5      (       a  U R                  U5      $ g r#   )r?   r1   r%   s      r)   r*   &NoReferrerWhenDowngradePolicy.referrer   s7    !!,//43E3Ek3R3R)),77r,   rG   NrH   )
rM   rN   rO   rP   rX   !POLICY_NO_REFERRER_WHEN_DOWNGRADEr!   rQ   r*   rR   rG   r,   r)   r[   r[   w   s     2D#1r,   r[   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	SameOriginPolicy   au  
https://www.w3.org/TR/referrer-policy/#referrer-policy-same-origin

The "same-origin" policy specifies that a full URL, stripped for use as a referrer,
is sent as referrer information when making same-origin requests from a particular request client.

Cross-origin requests, on the other hand, will contain no referrer information.
A Referer HTTP header will not be sent.
r    r!   c                n    U R                  U5      U R                  U5      :X  a  U R                  U5      $ g r#   r   r1   r%   s      r)   r*   SameOriginPolicy.referrer   s0    ;;|$K(@@)),77r,   rG   NrH   )
rM   rN   rO   rP   rX   POLICY_SAME_ORIGINr!   rQ   r*   rR   rG   r,   r)   ra   ra      s     #D#"r,   ra   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	OriginPolicy   a&  
https://www.w3.org/TR/referrer-policy/#referrer-policy-origin

The "origin" policy specifies that only the ASCII serialization
of the origin of the request client is sent as referrer information
when making both same-origin requests and cross-origin requests
from a particular request client.
r    r!   c                $    U R                  U5      $ r#   )r4   r%   s      r)   r*   OriginPolicy.referrer   s    ##L11r,   rG   NrH   )
rM   rN   rO   rP   rX   POLICY_ORIGINr!   rQ   r*   rR   rG   r,   r)   rh   rh      s     D#2r,   rh   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	StrictOriginPolicy   a  
https://www.w3.org/TR/referrer-policy/#referrer-policy-strict-origin

The "strict-origin" policy sends the ASCII serialization
of the origin of the request client when making requests:
- from a TLS-protected environment settings object to a potentially trustworthy URL, and
- from non-TLS-protected environment settings objects to any origin.

Requests from TLS-protected request clients to non- potentially trustworthy URLs,
on the other hand, will contain no referrer information.
A Referer HTTP header will not be sent.
r    r!   c                    U R                  U5      (       a  U R                  U5      (       d  U R                  U5      (       d  U R                  U5      $ g r#   )r?   rA   r4   r%   s      r)   r*   StrictOriginPolicy.referrer   sI    |,,,,[99##L11''55r,   rG   NrH   )
rM   rN   rO   rP   rX   POLICY_STRICT_ORIGINr!   rQ   r*   rR   rG   r,   r)   rn   rn      s     %D#$r,   rn   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	OriginWhenCrossOriginPolicy   a  
https://www.w3.org/TR/referrer-policy/#referrer-policy-origin-when-cross-origin

The "origin-when-cross-origin" policy specifies that a full URL,
stripped for use as a referrer, is sent as referrer information
when making same-origin requests from a particular request client,
and only the ASCII serialization of the origin of the request client
is sent as referrer information when making cross-origin requests
from a particular request client.
r    r!   c                r    U R                  U5      nX0R                  U5      :X  a  U R                  U5      $ U$ r#   rd   r&   r'   r(   r   s       r)   r*   $OriginWhenCrossOriginPolicy.referrer   s5    \*[[--)),77r,   rG   NrH   )
rM   rN   rO   rP   rX   POLICY_ORIGIN_WHEN_CROSS_ORIGINr!   rQ   r*   rR   rG   r,   r)   rt   rt      s    	 0D#/r,   rt   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	!StrictOriginWhenCrossOriginPolicy   a  
https://www.w3.org/TR/referrer-policy/#referrer-policy-strict-origin-when-cross-origin

The "strict-origin-when-cross-origin" policy specifies that a full URL,
stripped for use as a referrer, is sent as referrer information
when making same-origin requests from a particular request client,
and only the ASCII serialization of the origin of the request client
when making cross-origin requests:

- from a TLS-protected environment settings object to a potentially trustworthy URL, and
- from non-TLS-protected environment settings objects to any origin.

Requests from TLS-protected clients to non- potentially trustworthy URLs,
on the other hand, will contain no referrer information.
A Referer HTTP header will not be sent.
r    r!   c                   U R                  U5      nX0R                  U5      :X  a  U R                  U5      $ U R                  U5      (       a  U R                  U5      (       d  U R                  U5      (       d  U R	                  U5      $ g r#   )r   r1   r?   rA   r4   rw   s       r)   r*   *StrictOriginWhenCrossOriginPolicy.referrer   sw    \*[[--)),77|,,,,[99##L11''55r,   rG   NrH   )
rM   rN   rO   rP   rX   &POLICY_STRICT_ORIGIN_WHEN_CROSS_ORIGINr!   rQ   r*   rR   rG   r,   r)   r{   r{      s    " 7D#6	r,   r{   c                  2    \ rS rSr% Sr\rS\S'   SS jrSr	g)	UnsafeUrlPolicy   a  
https://www.w3.org/TR/referrer-policy/#referrer-policy-unsafe-url

The "unsafe-url" policy specifies that a full URL, stripped for use as a referrer,
is sent along with both cross-origin requests
and same-origin requests made from a particular request client.

Note: The policy's name doesn't lie; it is unsafe.
This policy will leak origins and paths from TLS-protected resources
to insecure origins.
Carefully consider the impact of setting such a policy for potentially sensitive documents.
r    r!   c                $    U R                  U5      $ r#   )r1   r%   s      r)   r*   UnsafeUrlPolicy.referrer  s    %%l33r,   rG   NrH   )
rM   rN   rO   rP   rX   POLICY_UNSAFE_URLr!   rQ   r*   rR   rG   r,   r)   r   r      s     "D#!4r,   r   c                  D    \ rS rSr% Sr/ \QSPSP7rS\S'   \r	S\S'   S	r
g
)DefaultReferrerPolicyi  z
A variant of "no-referrer-when-downgrade",
with the addition that "Referer" is not sent if the parent request was
using ``file://`` or ``s3://`` scheme.
files3r   r   r    r!   rG   N)rM   rN   rO   rP   rX   r   r   rQ   POLICY_SCRAPY_DEFAULTr!   rR   rG   r,   r)   r   r     s.     +IM*H6*H4*HH%D#%r,   r   zdict[str, type[ReferrerPolicy]]_policy_classes c                    [        [        [           [        U 5      5      $ ! [         a    U R                  5       R                  S5       Vs/ s H  o"R                  5       PM     Os  snf nnUSSS2    H  nU[        ;   d  M  [        U   s  s $    SU < 3nU(       d  [        U5      e[        R                  " U[        5         gf = f)z
Expect a string for the path to the policy class,
otherwise try to interpret the string as a standard value
from https://www.w3.org/TR/referrer-policy/#referrer-policies
,NzCould not load referrer policy )r   typer   r   
ValueErrorlowersplitstripr   RuntimeErrorwarningswarnRuntimeWarning)policywarning_onlytokentokensmsgs        r)   _load_policy_classr   1  s    D(+f*=>> -3\\^-A-A#-FG-FE++--FGGDbD\E'&u-- " 0z:s##c>*s'   " +C
A'&C
C
5C
	C
c                  `    \ rS rSrS	S
S jjr\SS j5       rSS jr      SS jrSS jr	Sr
g)RefererMiddlewareiI  Nc                t    [         U l        Ub*  [        UR                  S5      5      nU(       d   eX l        g g )NREFERRER_POLICY)r   default_policyr   get)r&   settingssettings_policys      r)   __init__RefererMiddleware.__init__J  s7    4I0>O1PQO""?"1  r,   c                    UR                   R                  S5      (       d  [        eU " UR                   5      nUR                  R	                  UR
                  [        R
                  S9  U$ )NREFERER_ENABLED)signal)r   getboolr
   r	   connectrequest_scheduled)clscrawlermws      r)   from_crawlerRefererMiddleware.from_crawlerQ  sZ    ''(9::!!" 	 4 4W=V=VW	r,   c                N   UR                   R                  S5      nUcM  [        U[        5      (       a8  UR                  R                  S5      nUb  [        UR                  S5      5      nUc  U R                  5       $ [        USS9nU(       a  U" 5       $ U R                  5       $ )a  
Determine Referrer-Policy to use from a parent Response (or URL),
and a Request to be sent.

- if a valid policy is set in Request meta, it is used.
- if the policy is set in meta but is wrong (e.g. a typo error),
  the policy from settings is used
- if the policy is not set in Request meta,
  but there is a Referrer-policy header in the parent response,
  it is used if valid
- otherwise, the policy from settings is used.
referrer_policyzReferrer-Policylatin1T)r   )	metar   
isinstancer   headersr   decoder   r   )r&   resp_or_urlrequestpolicy_namepolicy_headerr   s         r)   r   RefererMiddleware.policy\  s     ll&&'89:k8#D#D'//334EFM(()=)=h)GH&&(( 4@su6!4!4!66r,   c                    Uc  U$ U R                  X!5      R                  UR                  UR                  5      nUb  UR                  R	                  SU5        U$ )NReferer)r   r*   r0   r   
setdefault)r&   r   responser*   s       r)   get_processed_request'RefererMiddleware.get_processed_requestt  sQ     N;;x1::8<<UOO&&y(;r,   c                x   UR                   R                  S/ 5      nU(       a  UR                  R                  S5      nUbx  [        U5      nU R	                  XQ5      R                  XQR                  5      nXdR                  S5      :w  a.  Uc  UR                  R                  S5        g XaR                  S'   g g g g )Nredirect_urlsr   r   )	r   r   r   r   r   r*   r0   r   pop)r&   r   spiderredirected_urlsrequest_referrer
parent_urlpolicy_referrers          r)   r   #RefererMiddleware.request_scheduled  s    !,,**?B?&229=+ --=>
"&++j"B"K"K# #&=&=h&GG&.++I65D	2	 H , r,   )r   r#   )r   zBaseSettings | None)r   r   rI   r   )r   zResponse | strr   r   rI   r   )r   r   r   zResponse | NonerI   zRequest | None)r   r   r   r   rI   None)rM   rN   rO   rP   r   classmethodr   r   r   r   rR   rG   r,   r)   r   r   I  sC    2  70		*9			Er,   r   rK   )r   r    r   rL   rI   ztype[ReferrerPolicy] | None):rX   
__future__r   r   typingr   r   urllib.parser   	w3lib.urlr   scrapyr   r	   scrapy.exceptionsr
   scrapy.httpr   r   scrapy.spidermiddlewares.baser   scrapy.utils.miscr   scrapy.utils.pythonr   scrapy.utils.urlr   typing_extensionsr   scrapy.crawlerr   scrapy.settingsr   r   rQ   rY   r_   rf   rl   rr   ry   r   r   r   r   rT   r[   ra   rh   rn   rt   r{   r   r   r!   r   r   r   )ps   0r)   <module>r      s  
 #  & ! % " + ) > ) * &&&,"  # $@ !" & "< )J &  ( 59 59p~ N .~ &2> 2  2. * @4n 4(&9 & 	%#)
4
 FFAI
40   4  ',# 0JE, JEW4s   <D9