
    3 d                        U d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlmZ ddl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mZ  e            Zd
ed<   dddefdZ e            Zded<   	 dddde	ee                  dee
d         e
eef         f         fdZ dee!ee"ef         defdZ#edede!fd            Z$ej%        fded         deegef         defdZ&dS )zZ
This module provides some useful functions for working with
scrapy.http.Response objects
    N)AnyCallableIterableOptionalTupleUnion)WeakKeyDictionary)http)html)Response)
deprecated)to_bytes
to_unicodez WeakKeyDictionary[Response, str]_baseurl_cacheresponse&scrapy.http.response.text.TextResponsereturnc                     | t           vr7| j        dd         }t          j        || j        | j                  t           | <   t           |          S )zGReturn the base url of the given response, joined with the response urlr      )r   textr   get_base_urlurlencoding)r   r   s     5lib/python3.11/site-packages/scrapy/utils/response.pyr   r      sO    ~% 
}QtV$#'#4(, 1$
 $
x  (##    zHWeakKeyDictionary[Response, Union[Tuple[None, None], Tuple[float, str]]]_metaref_cachescriptnoscriptignore_tags)NNc                     | t           vr9| j        dd         }t          j        || j        | j        |          t           | <   t           |          S )z>Parse the http-equiv refresh parameter from the given responser   r   )r    )r   r   r   get_meta_refreshr   r   )r   r    r   s      r   r"   r"   &   sX    
 ~% 
}QtV$#'#8(, 1{$
 $
 $
x  (##r   statusc                     t          |           }t          j                            |d          }| dt	          |           S )z7Return status code plus status text descriptive messagezUnknown Status )intr
   	RESPONSESgetr   )r#   
status_intmessages      r   response_status_messager+   3   sA    VJn  -=>>G00:g..000r   c           	      z   dt          t          | j                            dt          t          j                            | j        d                    dg}| j        r.|                    | j                                        dg           |                    d| j	        g           d
                    |          S )zReturn raw HTTP representation (as bytes) of the given response. This
    is provided only for reference, since it's not the exact stream of bytes
    that was received (that's not exposed by Twisted).
    s	   HTTP/1.1     r   s   
)r   strr#   r
   r'   r(   headersextend	to_stringbodyjoin)r   valuess     r   response_httpreprr5   :   s     	X_%%&&##HOS99::F  ?x'1133W=>>>
MM7HM*+++88Fr   )z&scrapy.http.response.html.HtmlResponser   	_openfuncc                    ddl m}m} | j        }t	          | |          rWd|vrPd| j         d}t          j        dd|t          j                  }t          j        d	t          |          |          }d
}n/t	          | |          rd}nt          d| j        j                   t          j        |          \  }}t          j        ||           t          j        |            |d|           S )zmOpen the given response in a local web browser, populating the <base>
    tag for external links to work
    r   )HtmlResponseTextResponses   <basez\1<base href="z">s
   <!--.*?-->r   )flagss   (<head(?:>|\s.*?>))z.htmlz.txtzUnsupported response type: zfile://)scrapy.httpr8   r9   r2   
isinstancer   resubDOTALLr   	TypeError	__class____name__tempfilemkstemposwriteclose)	r   r6   r8   r9   r2   replextfdfnames	            r   open_in_browserrL   M   s    76666666 =D(L)) 	X4 	I5X\555D6-d")DDDD618D>>4HHD	Hl	+	+ XV9K9TVVWWW %%IBHRHRLLL9&u&&'''r   )r   )'__doc__rE   r=   rC   
webbrowsertypingr   r   r   r   r   r   weakrefr	   twisted.webr
   w3libr   scrapyscrapy.http.responser   scrapy.utils.decoratorsr   scrapy.utils.pythonr   r   r   __annotations__r.   r   r   floatr"   bytesr&   r+   r5   openrL    r   r   <module>r\      s]     
			 				      B B B B B B B B B B B B B B B B % % % % % %              ) ) ) ) ) ) . . . . . . 4 4 4 4 4 4 4 45F5F5H5H2 H H H$C $ $ $ $ $  Z    ,B
$ 
$6
$(3-(
$ 5eE3J//0
$ 
$ 
$ 
$1E%S*@$A 1c 1 1 1 1  U    . '1o( (	2(
 s
#( 	( ( ( ( ( (r   