
    	a                         d Z ddlZddlmZ ddlmZ d Zd Zd Zd	 Zd
 Z	d Z
d Zd Z ej                  d      Zd Zd Zd Zy)z.Module with functions to normalize components.    N   )compat)miscc                 "    | j                         S )zNormalize the scheme component.)lower)schemes    5/usr/lib/python3/dist-packages/rfc3986/normalizers.pynormalize_schemer
      s    <<>    c                 p    | \  }}}d}|r|t        |      dz   z  }|r|t        |      z  }|r|d|z   z  }|S )z)Normalize an authority tuple to a string. @:)normalize_percent_charactersnormalize_host)	authorityuserinfohostportresults        r	   normalize_authorityr      sS    $HdDF.x83>>.&&#*Mr   c                 ,    t        j                  |       S )z<Normalize a username to make it safe to include in userinfo.r   urlquote)usernames    r	   normalize_usernamer   '       ??8$$r   c                 ,    t        j                  |       S )z/Normalize a password to make safe for userinfo.r   )passwords    r	   normalize_passwordr    ,   r   r   c                 F   t         j                  j                  |       rs| j                  d      }|dk7  r]| j                  d      }|dk(  s||k  s||k(  r$|t	        |       dz
  k(  r| j                  ddd      } | d| j                         | |d z   S | j                         S )zNormalize a host string.%z%25   r   N)r   IPv6_MATCHERmatchfindlenreplacer   )r   percent
percent_25s      r	   r   r   1   s    t$))C.b=5)J b Z'z)jCIM.I||C2 >'')DN::::<r   c                 6    | s| S t        |       } t        |       S )zNormalize the path string.)r   remove_dot_segments)paths    r	   normalize_pathr/   H   s    '-Dt$$r   c                      | s| S t        |       S )zNormalize the query string.r   )querys    r	   normalize_queryr3   Q   s    '..r   c                      | s| S t        |       S )zNormalize the fragment string.r1   )fragments    r	   normalize_fragmentr6   X   s    '11r   z%[A-Fa-f0-9]{2}c                     t        t        j                  |             }|D ]3  }|j                         r| j	                  ||j                               } 5 | S )zAll percent characters should be upper-cased.

    For example, ``"%3afoo%DF%ab"`` should be turned into ``"%3Afoo%DF%AB"``.
    )setPERCENT_MATCHERfindallisupperr)   upper)smatchesms      r	   r   r   b   sN    
 /))!,-G (yy{		!QWWY'A( Hr   c                 P   | j                  d      }g }|D ]2  }|dk(  r	|dk7  r|j                  |        |s#|j                          4 | j                  d      r|r|d   r|j	                  dd       | j                  d      r|j                  d       dj                  |      S )zURemove dot segments from the string.

    See also Section 5.2.4 of :rfc:`3986`.
    /.z..r   r   )z/.z/..)splitappendpop
startswithinsertendswithjoin)r=   segmentsoutputsegments       r	   r-   r-   n   s     wws|HF 
c>_MM'" JJL
 	||C&F1Ia 	zz- b88Fr   c                 0   | | S t        t        j                  t        j                  | |                  }t        j
                  | |      }||j                  d      k(  }t               }t        dt        |            D ]  }|||dz    }t        |      }|r|dk(  s%|dk  r2|j                         t        j                  v r|j                  |       T|j                  d|dj                         j                                 |j                  |      S )z7Encode the specific component in the provided encoding.   %r   r      r"   02x)r(   r9   r:   r   to_strto_bytescount	bytearrayrangeorddecoder   NON_PCT_ENCODEDextendencoder<   )	uri_componentencodingpercent_encodings	uri_bytesis_percent_encodedencoded_uriibytebyte_ords	            r	   encode_componentrd      s    mX FG x8I*iood.CC+K1c)n% 	@QU#t944<sNt{{}0D0DDt$Qxn-446<<>?	@ h''r   )__doc__rer   r   r   r
   r   r   r    r   r/   r3   r6   compiler9   r   r-   rd    r   r	   <module>ri      s^    5 	  

%
%
.%/2 "**./	D(r   