
    i                        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y)    )annotationsN)Dict)	HTTPError)quote)urljoinurlsplit)HTTPRedirectHandlerRequesturlopen)
addinfourlc                   |j                   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	}| j                   j!                         D ci c]  \  }}|j#                         |vs|| }}}t%        ||| j&                  d
      }t)        | d      r| j*                  }	|	j                  |d      t,        j.                  k\  st1        |	      t,        j2                  k\  rat        | j                  |j                  t,        j4                  |j                  z   |j                   |j                        i }	t7        | d|	       t7        |d|	       |	j                  |d      dz   |	|<   |S c c}}w )a  
    Create a new request object for a redirected request.

    The logic is based on `urllib.request.HTTPRedirectHandler` from `this commit <https://github.com/python/cpython/blob/b58bc8c2a9a316891a5ea1a0487aebfc86c2793a/Lib/urllib/request.py#L641-L751>_`.

    :param request: The original request that resulted in the redirect.
    :param http_error: The response to the original request that indicates a
        redirect should occur and contains the new location.
    :return: A new request object to the location indicated by the response.
    :raises HTTPError: the supplied ``http_error`` if the redirect request
        cannot be created.
    :raises ValueError: If the response code is `None`.
    :raises ValueError: If the response does not contain a ``Location`` header
        or the ``Location`` header is not a string.
    :raises HTTPError: If the scheme of the new location is not ``http``,
        ``https``, or ``ftp``.
    :raises HTTPError: If there are too many redirects or a redirect loop.
    Locationz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-typeT)headersorigin_req_hostunverifiableredirect_dictr      )r   get
isinstancestr
ValueErrorr   schemer   codereasonfpurlquotestringpunctuationr   full_urlitemslowerr
   r   hasattrr   r	   max_repeatslenmax_redirectionsinf_msgsetattr)
request
http_errornew_urlnew_url_partscontent_headerskv
newheadersnew_requestvisiteds
             AC:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/_networking.py_make_redirect_requestr9      s   &   $$Z0Ggs#+G;6FGHHW%M #??OO  !!7{/RMM
 	
 wF<N<NOGg&&0G
 9O ..00AAGGI_4T10   //	K w(''KK#':'F'FF7|2CCC  #++j.?.??""  '2K'2{{7A.2GG=s   &HHc                    	 t        |       S # t        $ rD}|j                  dk(  r/t        j                  dk  rt        | |      }t        |      cY d}~S  d}~ww xY w)a6  
    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.

    :param request: The request to open.
    :return: The response to the request.
    i4  )      N)r   r   r   sysversion_infor9   _urlopen)r.   errorr6   s      r8   r?   r?   ^   sW    w 
::!1!1G!; 1%@KK((
s    
 	A8AAAA)r.   r
   r/   r   returnr
   )r.   r
   rA   r   )
__future__r   r#   r=   typingr   urllib.errorr   urllib.parser   r"   r   r   urllib.requestr	   r
   r   urllib.responser   r9   r?        r8   <module>rJ      s/    "  
  " * * @ @ &NbrI   