
    !h,                    >   % S r SSKJr  SSKrSSKrSSK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  SSKJrJr  \(       a  SS	KJrJr  SS
KJrJr  \" 5       rS\S'   SS jr\" 5       rS\S'    S     SS jjrSS jrSS jr\R@                  4     SS jjr!g)zZ
This module provides some useful functions for working with
scrapy.http.Response objects
    )annotationsN)TYPE_CHECKINGAny)WeakKeyDictionary)http)html)to_bytes
to_unicode)CallableIterable)ResponseTextResponsez WeakKeyDictionary[Response, str]_baseurl_cachec                    U [         ;  aA  U R                  SS n[        R                  " XR                  U R
                  5      [         U '   [         U    $ )zGReturn the base url of the given response, joined with the response urlr      )r   textr   get_base_urlurlencoding)responser   s     \/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/utils/response.pyr   r      sK    ~%}}Qt$#'#4#4,, 1 1$
x  (##    zBWeakKeyDictionary[Response, tuple[None, None] | tuple[float, str]]_metaref_cachec                    U [         ;  a@  U R                  SS n[        R                  " X R                  U R
                  US9[         U '   [         U    $ )z>Parse the http-equiv refresh parameter from the given responser   r   )ignore_tags)r   r   r   get_meta_refreshr   r   )r   r   r   s      r   r   r   +   sO    
 ~%}}Qt$#'#8#8,, 1 1{$
x  (##r   c                x    [        U 5      n[        R                  R                  US5      nU S[	        U5       3$ )z7Return status code plus status text descriptive messagezUnknown Status )intr   	RESPONSESgetr
   )status
status_intmessages      r   response_status_messager%   8   s9    VJnn  -=>G\:g./00r   c                    U R                  S5      nUS:w  aF  U R                  SUS-   5      nUS:X  a  U S U $ U S U XS-   S  -   n U R                  S5      nUS:w  a  MF  U $ )Ns   <!--s   -->      )find)bodystartends      r   _remove_html_commentsr.   ?   st    IIgE
2+ii	*"9<FU|d79o-		'" 2+ Kr   c                   SSK JnJn  U R                  n[	        X5      (       aD  SU;  a;  [        U5        SU R                   S3n[        R                  " S[        U5      USS9nS	nO5[	        X5      (       a  S
nO"[        SU R                  R                   35      e[        R                  " U5      u  px[        R                   " Xt5        [        R"                  " U5        U" SU 35      $ )a  Open *response* in a local web browser, adjusting the `base tag`_ for
external links to work, e.g. so that images and styles are displayed.

.. _base tag: https://www.w3schools.com/tags/tag_base.asp

For example:

.. code-block:: python

    from scrapy.utils.response import open_in_browser


    def parse_details(self, response):
        if "item name" not in response.body:
            open_in_browser(response)
r   )HtmlResponser   s   <basez\0<base href="z">s   <head(?:[^<>]*?>)r(   )countz.htmlz.txtzUnsupported response type: zfile://)scrapy.httpr0   r   r+   
isinstancer.   r   resubr	   	TypeError	__class____name__tempfilemkstemposwriteclose)	r   	_openfuncr0   r   r+   replextfdfnames	            r   open_in_browserrC   J   s    ( 7 ==D())4!$'$X\\N"5D66/$QOD	H	+	+5h6H6H6Q6Q5RSTT  %IBHHRHHRLwug&''r   )r   r   returnstr))scriptnoscript)r   r   r   zIterable[str]rD   z%tuple[None, None] | tuple[float, str])r"   zbytes | float | strrD   rE   )r+   bytesrD   rH   )r   r   r>   zCallable[[str], Any]rD   r   )"__doc__
__future__r   r;   r4   r9   
webbrowsertypingr   r   weakrefr   twisted.webr   w3libr   scrapy.utils.pythonr	   r
   collections.abcr   r   r2   r   r   r   __annotations__r   r   r   r%   r.   openrC    r   r   <module>rU      s   
 # 	 	   % %   4223D3F0 F$  R  "8
$
$
$ +
$1 '1oo%(%(#%( 	%(r   