
    Pi                        d dl mZ 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mZ d dlmZmZmZ d dlmZ ddZddZdS )    )annotationsN)Dict)	HTTPError)quote)urljoinurlsplit)HTTPRedirectHandlerRequesturlopen)
addinfourlrequestr
   
http_errorr   returnc                   |j                             d          }||t          |t                    st	          d|d          t          |          }|j        dvr-t          ||j        |j	         d|d|j         |j
                  t          |dt          j        	          }t          | j        |          }d
fd| j                                         D             }t#          ||| j        d          }t'          | d          r| j        }|                    |d          t*          j        k    st/          |          t*          j        k    r9t          | j        |j        t*          j        |j	        z   |j         |j
                  ni }t5          | d|           t5          |d|           |                    |d          dz   ||<   |S )a  Create a new request object for a redirected request.

    The logic is based on [HTTPRedirectHandler](https://github.com/python/cpython/blob/b58bc8c2a9a316891a5ea1a0487aebfc86c2793a/Lib/urllib/request.py#L641-L751) from urllib.request.

    Args:
        request: The original request that resulted in the redirect.
        http_error: The response to the original request that indicates a
            redirect should occur and contains the new location.

    Returns:
        A new request object to the location indicated by the response.

    Raises:
        HTTPError: the supplied `http_error` if the redirect request
            cannot be created.
        ValueError: If the response code is None.
        ValueError: If the response does not contain a `Location` header
            or the `Location` header is not a string.
        HTTPError: If the scheme of the new location is not `http`,
            `https`, or `ftp`.
        HTTPError: If there are too many redirects or a redirect loop.
    LocationNzLocation header z is not a string)httphttpsftp z - Redirection to url z is not allowedz
iso-8859-1)encodingsafe)zcontent-lengthzcontent-typec                H    i | ]\  }}|                                 v||S  )lower).0kvcontent_headerss      f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rdflib/_networking.py
<dictcomp>z*_make_redirect_request.<locals>.<dictcomp>A   s8       AAGGII_4T4T14T4T4T    T)headersorigin_req_hostunverifiableredirect_dictr      )r"   get
isinstancestr
ValueErrorr   schemer   codereasonfpurlquotestringpunctuationr   full_urlitemsr
   r#   hasattrr%   r	   max_repeatslenmax_redirectionsinf_msgsetattr)r   r   new_urlnew_url_parts
newheadersnew_requestvisitedr   s          @r   _make_redirect_requestr?      s   .  $$Z00Ggs## IGGGGGHHHW%%M #???O RRRRRM
 
 	
 wF<NOOOGg&00G
 9O    ..00  J /	  K w(( 3'KK##':'FFF7||2CCC #+j.??"   D '222K'222{{7A..2GGr!   r   c                    	 t          |           S # t          $ rE}|j        dk    r4t          j        dk     r$t          | |          }t          |          cY d}~S  d}~ww xY w)aA  This is a shim for `urlopen` that handles HTTP redirects with status code
    308 (Permanent Redirect).

    This function should be removed once all supported versions of Python
    handles the 308 HTTP status code.

    Args:
        request: The request to open.

    Returns:
        The response to the request.
    i4  )      N)r   r   r,   sysversion_infor?   _urlopen)r   errorr=   s      r   rE   rE   b   s    w 
 
 
:!1G!;!; 1%@@KK((((((((
s     
A 9AA AA )r   r
   r   r   r   r
   )r   r
   r   r   )
__future__r   r0   rC   typingr   urllib.errorr   urllib.parser   r/   r   r   urllib.requestr	   r
   r   urllib.responser   r?   rE   r   r!   r   <module>rM      s    " " " " " "  



       " " " " " " * * * * * * * * * * * * * * @ @ @ @ @ @ @ @ @ @ & & & & & &R R R Rj     r!   