
    &th^                    R   d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZm Z  d	d
l!m"Z"m#Z# d	dl$m%Z%m&Z& d	dl'm(Z( d	dl)m*Z* dodZ+ ej,        de+           dZ-dZ.e-e.z   Z/ej0        ej1        z   dz   2                    d          Z3dZ4e3e.z   dz   Z5e/e3z   e4z   dz   Z6e67                    dd          Z8e59                    dd          Z:e69                    dd          Z;e;Z<e;9                    dd           Z=e;Z>d! e"D             Z?dpd$Z@	 	 	 dqdrd,ZA ejB        d-          ZC	 dsdtd.ZDdud0ZEe	 	 dvdwd7            ZFe	 dxdyd8            ZF	 	 dvdzd9ZF	 	 	 	 	 	 d{d|dEZGd}dHZHd~dKZIddMZJddOZKddQZLddSZM eN eOeP eQdT                              ZRdUS                     ejT        dVU                    eR eN eOeP eQddW                              z
   eNdX          z
                                ZVdYS                     ejT        dVU                    eRh dZz
                       ejT        dVU                    eR                              ZW ejB        d[S                    eV\          2                                          ZX ejB        d]S                    eVeW^          2                                          ZY G d_ d`e          ZZddaZ[g dbZ\	 dsddfZ]	 	 	 dddhZ^ddjZ_	 dddkZ`	 dddnZadS )zW
This module contains general purpose URL functions not found in the standard
library.
    )annotationsN)Sequence)Callable
NamedTuplecastoverload)_coerce_args)ParseResultparse_qs	parse_qslquoteunquoteunquote_to_bytes	urldefrag	urlencodeurlparseurlsplit
urlunparse
urlunsplit)pathname2urlurl2pathname   )_ASCII_TAB_OR_NEWLINE_C0_CONTROL_OR_SPACE)AnyUnicodeError
StrOrBytes)_SPECIAL_SCHEMES)
to_unicodeerrorUnicodeErrorreturntuple[str, int]c                    t          t          |           } t          t          | j        | j        | j                                     | j        fS N)r   r   r   r   objectstartend)r   s    ]/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/w3lib/url.py_quote_byter)   (   s>    %((EuU\%+	*ABCCDDeiPP    percentencodes   :/?#[]@s   !$&'()*+,;=z-._~ascii   |   :   %   #r*   s   :;=)deletes   #[]|   'c                .    i | ]}t          |          d S r$   )ord).0chars     r(   
<dictcomp>r7   K   s-     + + +CIIt+ + +r*   urlstrc                f    |                      t                                        t                    S r$   )stripr   	translate'_ASCII_TAB_OR_NEWLINE_TRANSLATION_TABLE)r8   s    r(   _stripr>   P   s*    99)**44/  r*   utf8Tr   encodingpath_encoding
quote_pathboolc                |   t          | |d          }t          t          |                    }|j        |j        |j        |j        f\  }}}}	d}
|||:t          t          |          t                    }|
|
                    |          z  }
|?|
dz  }
t          t          |          t                    }|
|
                    |          z  }
|
dz  }
|B	 |
|
                    d          z  }
n(# t          $ r |
|
                    |          z  }
Y nw xY w|	*|
dz  }
|
t          |	          
                    |          z  }
|
                                }|r.t          |j        
                    |          t                    }n|j        }|j        t"          v r.t          |j        
                    |          t&                    }n-t          |j        
                    |          t(                    }t+          |j        |||t          |j        
                    |          t.                    f          S )u  Return a URL equivalent to *url* that a wide range of web browsers and
    web servers consider valid.

    *url* is parsed according to the rules of the `URL living standard`_,
    and during serialization additional characters are percent-encoded to make
    the URL valid by additional URL standards.

    .. _URL living standard: https://url.spec.whatwg.org/

    The returned URL should be valid by *all* of the following URL standards
    known to be enforced by modern-day web browsers and web servers:

    -   `URL living standard`_

    -   `RFC 3986`_

    -   `RFC 2396`_ and `RFC 2732`_, as interpreted by `Java 8’s java.net.URI
        class`_.

    .. _Java 8’s java.net.URI class: https://docs.oracle.com/javase/8/docs/api/java/net/URI.html
    .. _RFC 2396: https://www.ietf.org/rfc/rfc2396.txt
    .. _RFC 2732: https://www.ietf.org/rfc/rfc2732.txt
    .. _RFC 3986: https://www.ietf.org/rfc/rfc3986.txt

    If a bytes URL is given, it is first converted to `str` using the given
    encoding (which defaults to 'utf-8'). If quote_path is True (default),
    path_encoding ('utf-8' by default) is used to encode URL path component
    which is then quoted. Otherwise, if quote_path is False, path component
    is not encoded or quoted. Given encoding is used for query string
    or form data.

    When passing an encoding, you should use the encoding of the
    original page (the page from which the URL was extracted from).

    Calling this function on an already "safe" URL will return the URL
    unmodified.
    r+   )r@   errorsr*   Nr.      @idna)r   r   r>   usernamepasswordhostnameportr   r   _USERINFO_SAFEST_CHARSencoder    r9   decodepath_PATH_SAFEST_CHARSschemer   query_SPECIAL_QUERY_SAFEST_CHARS_QUERY_SAFEST_CHARSr   fragment_FRAGMENT_SAFEST_CHARS)r8   r@   rA   rB   decodedpartsrH   rI   rJ   rK   netloc_bytessafe_usernamesafe_passwordnetlocrO   rR   s                   r(   safe_url_stringr]   V   sE   b xHHHGVG__%%E 	
	*&Hh$ Lx3!'("3"35KLLMM00:::LD L!'("3"35KLLMM00:::L	6HOOF333LL 	6 	6 	6 HOOH555LLL	6 D		((222  ""F  UZ&&}557IJJz|'''ek((224OPPek((224GHHL%.''113IJJ	
  s   C2 2"DDz
/?(\.\./)+c                8   t          | ||          }t          |          \  }}}}}|r]t                              dt	          j        |                    }|                    d          r|                    d          s|dz  }nd}t          ||||df          S )zMake a url for download. This will call safe_url_string
    and then strip the fragment, if one exists. The path will
    be normalised.

    If the path is outside the document root, it will be changed
    to be within the document root.
     /)r]   r   _parent_dirssub	posixpathnormpathendswithr   )	r8   r@   rA   safe_urlrQ   r\   rO   rR   _s	            r(   safe_download_urlrh      s     sHm<<H%-h%7%7"FFD% I$6t$<$<==S!! 	$--*<*< 	CKDvvtUB7888r*   textc                <    |                      d          d         dv S )Nz://r   )filehttphttps)	partition)ri   s    r(   is_urlro      s    >>%  #'@@@r*   	parameterdefaultNonekeep_blank_values
bool | int
str | Nonec                    d S r$    r8   rp   rq   rs   s       r(   url_query_parameterry      s	     r*   c                    d S r$   rw   rx   s       r(   ry   ry      s	     #r*   c                    t          t          t          |                     d         t          |                    }||v r||         d         S |S )a  Return the value of a url parameter, given the url and parameter name

    General case:

    >>> import w3lib.url
    >>> w3lib.url.url_query_parameter("product.html?id=200&foo=bar", "id")
    '200'
    >>>

    Return a default value if the parameter is not found:

    >>> w3lib.url.url_query_parameter("product.html?id=200&foo=bar", "notthere", "mydefault")
    'mydefault'
    >>>

    Returns None if `keep_blank_values` not set or 0 (default):

    >>> w3lib.url.url_query_parameter("product.html?id=", "id")
    >>>

    Returns an empty string if `keep_blank_values` set to 1:

    >>> w3lib.url.url_query_parameter("product.html?id=", "id", keep_blank_values=1)
    ''
    >>>

       rs   r   )r   r   r9   rC   )r8   rp   rq   rs   queryparamss        r(   ry   ry      s\    D S16G1H1H  K K9%a((Nr*   rw   &=Fparameterlist!StrOrBytes | Sequence[StrOrBytes]sepkvsepremoveuniquekeep_fragmentsc                h   t          |t          t          f          r|g}t          |           \  } }t	          t          |           } t	          t          |          }|                     d          \  }}	}
t                      }g }|
                    |          D ]]}|s|                    |          \  }}	}	|r||v r%|r||v r,|s||vr3|                    |           |	                    |           ^|r*d
                    ||
                    |          g          n|} |r
|r| d|z   z  } | S )a  Clean URL arguments leaving only those passed in the parameterlist keeping order

    >>> import w3lib.url
    >>> w3lib.url.url_query_cleaner("product.html?id=200&foo=bar&name=wired", ('id',))
    'product.html?id=200'
    >>> w3lib.url.url_query_cleaner("product.html?id=200&foo=bar&name=wired", ['id', 'name'])
    'product.html?id=200&name=wired'
    >>>

    If `unique` is ``False``, do not remove duplicated keys

    >>> w3lib.url.url_query_cleaner("product.html?d=1&e=b&d=2&d=3&other=other", ['d'], unique=False)
    'product.html?d=1&d=2&d=3'
    >>>

    If `remove` is ``True``, leave only those **not in parameterlist**.

    >>> w3lib.url.url_query_cleaner("product.html?id=200&foo=bar&name=wired", ['id'], remove=True)
    'product.html?foo=bar&name=wired'
    >>> w3lib.url.url_query_cleaner("product.html?id=2&foo=bar&name=wired", ['id', 'foo'], remove=True)
    'product.html?name=wired'
    >>>

    By default, URL fragments are removed. If you need to preserve fragments,
    pass the ``keep_fragments`` argument as ``True``.

    >>> w3lib.url.url_query_cleaner('http://domain.tld/?bla=123#123123', ['bla'], remove=True, keep_fragments=True)
    'http://domain.tld/#123123'

    ?#)
isinstancer9   bytesr   r   rn   setsplitappendaddjoin)r8   r   r   r   r   r   r   rU   baserg   rR   seen	querylistksvks                  r(   url_query_cleanerr     s_   P -#u.. (&cNNMC
sC..CC""H]]3''ND!U55DI{{3   	--&&1a 	a4ii 	a=(( 	!=003<
F#((D#((9--.
/
/
/$C ( sX~Jr*   paramsdict[str, str]c                  	 t          |           }t          |j        d          }g }t                      	|D ]W\  }}||vr|                    ||f           !|	vr2|                    |||         f           	                    |           X	fd|                                D             }||z  }t          |          }t          |	                    |                    S )NTr}   c                &    g | ]\  }}|v	||fS rw   rw   )r5   namevalueseen_paramss      r(   
<listcomp>z._add_or_replace_parameters.<locals>.<listcomp>d  s2       %$4{;R;Ru;R;R;Rr*   )rR   )
r   r   rR   r   r   r   itemsr   r   _replace)
r8   r   parsedcurrent_argsnew_argsr   r   not_modified_argsrR   r   s
            @r(   _add_or_replace_parametersr   W  s   c]]FV\TBBBLH%%K# " "evOOT5M****$$OOT6$<0111OOD!!!   )/   !!HhEfooEo22333r*   r   	new_valuec                &    t          | ||i          S )aN  Add or remove a parameter to a given url

    >>> import w3lib.url
    >>> w3lib.url.add_or_replace_parameter('http://www.example.com/index.php', 'arg', 'v')
    'http://www.example.com/index.php?arg=v'
    >>> w3lib.url.add_or_replace_parameter('http://www.example.com/index.php?arg1=v1&arg2=v2&arg3=v3', 'arg4', 'v4')
    'http://www.example.com/index.php?arg1=v1&arg2=v2&arg3=v3&arg4=v4'
    >>> w3lib.url.add_or_replace_parameter('http://www.example.com/index.php?arg1=v1&arg2=v2&arg3=v3', 'arg3', 'v3new')
    'http://www.example.com/index.php?arg1=v1&arg2=v2&arg3=v3new'
    >>>

    r   )r8   r   r   s      r(   add_or_replace_parameterr   m  s     &cD)+<===r*   new_parametersc                "    t          | |          S )a  Add or remove a parameters to a given url

    >>> import w3lib.url
    >>> w3lib.url.add_or_replace_parameters('http://www.example.com/index.php', {'arg': 'v'})
    'http://www.example.com/index.php?arg=v'
    >>> args = {'arg4': 'v4', 'arg3': 'v3new'}
    >>> w3lib.url.add_or_replace_parameters('http://www.example.com/index.php?arg1=v1&arg2=v2&arg3=v3', args)
    'http://www.example.com/index.php?arg1=v1&arg2=v2&arg3=v3new&arg4=v4'
    >>>

    r   )r8   r   s     r(   add_or_replace_parametersr   }  s     &c>:::r*   rO   c                    t          t          j                            |                     }d|                    d           S )zwConvert local filesystem path to legal File URIs as described in:
    http://en.wikipedia.org/wiki/File_URI_scheme
    zfile:///r`   )r   osrO   abspathlstrip)rO   xs     r(   path_to_file_urir     s7     	RW__T**++A%ahhsmm%%%r*   uric                H    t          |           j        }t          |          S )zmConvert File URI to local filesystem path according to:
    http://en.wikipedia.org/wiki/File_URI_scheme
    )r   rO   r   )r   uri_paths     r(   file_uri_to_pathr     s      }}!H!!!r*   uri_or_pathc                    t           j                            |           d         rt          |           S t	          |           }|j        r| nt          |           S )zRIf given a path name, return its File URI, otherwise return it
    unmodified
    r   )r   rO   
splitdriver   r   rQ   )r   us     r(   
any_to_urir     sV     
w+&&q) -,,,A(E;;(8(E(EEr*      z[{}]+r_       z()<>@,;:\"/[]?= z(?:[{}]|(?:\\[{}]))*>   "\z{token}/{token})tokenz%;({token})=(?:({token})|"({quoted})"))r   quotedc                  2    e Zd ZU dZded<   ded<   ded<   dS )	ParseDataURIResultz/Named tuple returned by :func:`parse_data_uri`.r9   
media_typer   media_type_parametersr   dataN)__name__
__module____qualname____doc____annotations__rw   r*   r(   r   r     s6         99 OOO))))KKKKKr*   r   c                .   t          | t                    s"t          |                               d          } 	 |                     dd          \  }} n# t
          $ r t          d          w xY w|                                dk    rt          d          t          |           } d}i }t          	                    |           }|rC|
                                                                }| |                                d         } nd	|d
<   	 t          	                    |           }|rv|                                \  }}}|rt          j        dd|          }|                                ||                                <   | |                                d         } nn	 |                     dd          \  }}	n# t
          $ r t          d          w xY w|r)|dk    rt          d          t#          j        |	          }	t'          |||	          S )z3Parse a data: URI into :class:`ParseDataURIResult`.r,   r.   r   zinvalid URIs   dataznot a data URIz
text/plainNzUS-ASCIIcharsetTs   \\(.)s   \1   ,zinvalid data URIs   ;base64)r   r   r]   rM   r   
ValueErrorlowerr   _mediatype_patternmatchgrouprN   r'   _mediatype_parameter_patterngroupsrerb   base64	b64decoder   )
r   rQ   r   media_type_paramsm	attributer   value_quoted	is_base64r   s
             r(   parse_data_urir     s#   c5!! 3c""))'22(iia(( ( ( ('''(||~~  )*** 3

CJ  %%A 2WWYY%%''
!%%''))n'1)$	(..s33 	-.XXZZ*Iul @y&,??49LLNNi..001aeeggii.CC	-))D!,,	44 - - -+,,,- &
""/000%%j*;TBBBs   A A-$F> >G)r   r   r   canonicalize_urlr   ro   r   r   rh   r]   r   ry   rX   r
   #tuple[str, str, str, str, str, str]c           
        	 | j                             d                                          }n# t          $ r
 | j         }Y nw xY w| j        |t          | j                            |          t                    t          | j                            |          t                    t          | j
                            |          t                    t          | j                            |          t                    fS )NrG   )r\   rM   rN   r    rQ   r   rO   _path_safe_charsr   _safe_charsrR   rU   )rX   r@   rA   r\   s       r(   _safe_ParseResultr     s    
$$V,,3355    	ej..0@AAel!!-00+>>ek  **K88en##H--{;; s   ,/ AAStrOrBytes | ParseResultc                   t          | t                    rt          |           } 	 t          t	          |           |pd          \  }}}}}}	n5# t
          $ r( t          t	          |           d          \  }}}}}}	Y nw xY wt          ||          }
|
                                 t          |
          }t          |          }t          |t                    pd}|sdn|	}	|                    d          }|d                                                             d          |d<   d                    |          }t!          ||||||	f          S )a  Canonicalize the given url by applying the following procedures:

    - make the URL safe
    - sort query arguments, first by key, then by value
    - normalize all spaces (in query arguments) '+' (plus symbol)
    - normalize percent encodings case (%2f -> %2F)
    - remove query arguments with blank values (unless `keep_blank_values` is True)
    - remove fragments (unless `keep_fragments` is True)

    The url passed can be bytes or unicode, while the url returned is
    always a native str (bytes in Python 2, unicode in Python 3).

    >>> import w3lib.url
    >>>
    >>> # sorting query arguments
    >>> w3lib.url.canonicalize_url('http://www.example.com/do?c=3&b=5&b=2&a=50')
    'http://www.example.com/do?a=50&b=2&b=5&c=3'
    >>>
    >>> # UTF-8 conversion + percent-encoding of non-ASCII characters
    >>> w3lib.url.canonicalize_url('http://www.example.com/r\u00e9sum\u00e9')
    'http://www.example.com/r%C3%A9sum%C3%A9'
    >>>

    For more examples, see the tests in `tests/test_url.py`.
    r?   )r@   r`   r_   @:)r   r9   r>   r   	parse_urlUnicodeEncodeErrorparse_qsl_to_bytessortr   _unquotepathr   r   r   r   rstripr   r   )r8   rs   r   r@   rQ   r\   rO   r   rR   rU   keyvalsuqpnetloc_partss                r(   r   r   /  sp   H #s Skk
8IcNNX%79
 9
 9
5feXX  
 
 
8IcNNV9
 9
 9
5feXXX
@ !(9::GLLNNNgE t

C&''.3D'5rrXH <<$$L#B'--//66s;;LXXl##F vvtVUHEFFFs   'A /B ?B r   c                    dD ]0}|                      d|z   d|                                z             } 1t          |           S )N)2f2F3f3F%z%25)replaceupperr   )rO   reserveds     r(   r   r     sK    , F F||C(NEHNN4D4D,DEE D!!!r*   c                j    t          | t                    r| S t          t          | |                    S )z\Return urlparsed url from the given argument (which could be an already
    parsed url)
    )r   r
   r   r   )r8   r@   s     r(   r   r     s3     #{## 
JsH--...r*   qslist[tuple[bytes, bytes]]c           	        t          t          dt          t          t          dt          f         f         f         t
                    } ||           \  } }d |                     d          D             }g }|D ]}|s|                    dd          }t          |          dk    r|r|                    d           nGt          |d                   s|r|d         	                    d	d
          }t          |          } ||          }|d         	                    d	d
          }	t          |	          }	 ||	          }	|                    ||	f           |S )a	  Parse a query given as a string argument.

    Data are returned as a list of name, value pairs as bytes.

    Arguments:

    qs: percent-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        percent-encoded queries should be treated as blank strings.  A
        true value indicates that blanks should be retained as blank
        strings.  The default false value indicates that blank values
        are to be ignored and treated as if they were  not included.

    .c                B    g | ]}|                     d           D ]}|S );)r   )r5   s1s2s      r(   r   z&parse_qsl_to_bytes.<locals>.<listcomp>  s/    @@@B"((3--@@BR@@@@r*   r   r   r      r_   r   + )r   r   tupler9   r   r	   r   lenr   r   r   )
r   rs   coerce_args_coerce_resultpairsr
name_valuenvr   r   s
             r(   r   r     sZ   , xU3e0D+D%E EFUUK$RB@@"((3--@@@E
A $ $
 	c1%%r77a<<  		"r!u:: 	$* 	$!!u}}S#66D#D))D!>$''D "1c3 7 7E$U++E"N5))EHHdE]###Hr*   )r   r    r!   r"   )r8   r9   r!   r9   )r?   r?   T)
r8   r   r@   r9   rA   r9   rB   rC   r!   r9   )r?   r?   )r8   r   r@   r9   rA   r9   r!   r9   )ri   r9   r!   rC   )Nr   )
r8   r   rp   r9   rq   rr   rs   rt   r!   ru   )r   )
r8   r   rp   r9   rq   r9   rs   rt   r!   r9   )
r8   r   rp   r9   rq   ru   rs   rt   r!   ru   )rw   r   r   FTF)r8   r   r   r   r   r9   r   r9   r   rC   r   rC   r   rC   r!   r9   )r8   r9   r   r   r!   r9   )r8   r9   r   r9   r   r9   r!   r9   )r8   r9   r   r   r!   r9   )rO   r9   r!   r9   )r   r9   r!   r9   )r   r9   r!   r9   )r   r   r!   r   )rX   r
   r@   r9   rA   r9   r!   r   )TFN)
r8   r   rs   rC   r   rC   r@   ru   r!   r9   )rO   r9   r!   r   r$   )r8   r   r@   ru   r!   r
   )F)r   r9   rs   rC   r!   r   )br   
__future__r   r   codecsr   rc   r   stringcollections.abcr   typingr   r   r   r   urllib.parser	   r
   r   r   r   r   r   r   r   r   r   r   r   urllib.requestr   r   _infrar   r   _typesr   r   _urlr   utilr   r)   register_errorRFC3986_GEN_DELIMSRFC3986_SUB_DELIMSRFC3986_RESERVEDascii_lettersdigitsrM   RFC3986_UNRESERVEDEXTRA_SAFE_CHARSRFC3986_USERINFO_SAFE_CHARSr   r   r   r<   rL   rP   rT   rS   rV   r=   r>   r]   compilera   rh   ro   ry   r   r   r   r   r   r   r   r   mapchrrange_charformatescaper   _token_quoted_stringr   r   r   r   __all__r   r   r   r   r   rw   r*   r(   <module>r/     s   
 # " " " " "   				     				  $ $ $ $ $ $ 7 7 7 7 7 7 7 7 7 7 7 7 % % % % % %                            6 5 5 5 5 5 5 5 ? ? ? ? ? ? ? ? / / / / / / / / " " " " " "      Q Q Q Q
  o{ 3 3 3   # %(:: *V]:VCKKGTT  03EEL !336FFM&&tS11  5>>tF>SS  **4*@@ ( 0::4:MM + + + 5+ + + '
    	d d d d dN rz-(( CI9 9 9 9 9*A A A A 
 $%	    
 

 %&	    
 $%	' ' ' ' 'X 8: ? ? ? ? ?D4 4 4 4,> > > > ; ; ; ;& & & &" " " "F F F F 	CCUU3ZZ  !! 
BI
 CCq"&&''( C#$$%	
 	

 

 
 )//BIbgge////0011929RWWU^^3L3L   RZ 2 9 9 9 G G N N P PQQ )rz,33^ 4  fhh           3C 3C 3C 3Cl  " FL    , # 	\G \G \G \G \G~	" 	" 	" 	" ;?/ / / / / (-, , , , , , ,r*   