
    ViE                        S r SSKrSSKrSSKrSSKJr  \" S5      r \  \" S5      r\R                  " S5      r\" \R                    V Vs/ s HJ  n \R                     H6  nX-   R#                  S5      \" \" X-   S5      5      R#                  S	5      4PM8     ML     snn 5      r\R                  " S
5      r0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S!_S#S$_S%S&_S'S(_S)S*_0 S+S,_S-S._S/S_S0S1_S2S3_S4S5_S6S7_S8S9_S:S;_S<S=_S>S?_S@SA_SBSC_SDSE_SFSG_SHSI_SJSK_ESGSSLSMSNSOSPSSSSQ.
Er\" / SRQ5      r\" SS5      r\" ST5      r\\-  r\\-  r\\-
  r\\-  \" SU5      -  r\\-
  r\\-  \" SV5      -  r\\-
  r \\\" SW5      -
  -  r!\\!-
  r" " SX SY\#5      r$SZr%S[ r&\R                  " \&" S\5      5      r'SS] jr(S^ r)\)" \5      r*\)" \5      r+\)" \!5      r,\)" \5      r-SS` jr.SSa jr/SSb jr0SSc jr1SSd jr2Se r3SSf jr4Sg r5 " Sh Si\65      r7 " Sj Sk\65      r8 SSlKJ9r9  Sp rBSq rC\C" S5      rDS_\%4Sr jrE  SSsKFJGrGJHrHJIrI   SStKKJLrL   SSvKNJOrO  \O" SwSx9rP\Q" Sy5      u  rRrSrTrUrVrW " Sz S{\5      rX SS|KYJXrX  \XrZ " S} S~\X5      r[g! \	 a    \
r GNof = fs  snn f ! \: a_    SSK;r; " Sm Sn\;Rx                  5      r=\;R|                  R~                  R                  r@\;R|                  R~                  R                  rASo r9 Nf = f! \: a    SSsKJJGrGJHrHJIrI   Nf = f! \: a	    SSuKKJMrL   Nf = f! \: a
    \6" 5       rP Nf = f! \: a     Nf = f)a  :mod:`urlutils` is a module dedicated to one of software's most
versatile, well-aged, and beloved data structures: the URL, also known
as the `Uniform Resource Locator`_.

Among other things, this module is a full reimplementation of URLs,
without any reliance on the :mod:`urlparse` or :mod:`urllib` standard
library modules. The centerpiece and top-level interface of urlutils
is the :class:`URL` type. Also featured is the :func:`find_all_links`
convenience function. Some low-level functions and constants are also
below.

The implementations in this module are based heavily on `RFC 3986`_ and
`RFC 3987`_, and incorporates details from several other RFCs and `W3C
documents`_.

.. _Uniform Resource Locator: https://en.wikipedia.org/wiki/Uniform_Resource_Locator
.. _RFC 3986: https://tools.ietf.org/html/rfc3986
.. _RFC 3987: https://tools.ietf.org/html/rfc3987
.. _W3C documents: https://www.w3.org/TR/uri-clarification/

    N)	normalize zB~-._0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzz~^((?P<scheme>[^:/?#]+):)?((?P<_netloc_sep>//)(?P<authority>[^/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?ascii   charmapz([ -]+)acapi  afpi$  dictiD
  dns5   fileftp   giti$  gopherF   httpP   httpsi  imap   ippiw  ippsirc   ircsi)  ldapi  ldapsi|  mmsi  msrpi'  msrpsmtqpi  nfso   nntpw   nntpsi3  popn   prosperoi  redisi  rsyncii  rtspi*  rtspsiB  rtspui  sftp   smbi  snmp   ij     i  i     )
sshsteamsvntelnetventrilovncwaiswswssxmpp)urnaboutbitcoinblobdatageomagnetmailtonewspkcs11sipsipstelz:/?#[]@z!$&'()*+,;=z:@z/?z&=+c                       \ rS rSrSrSrg)URLParseErrory   zException inheriting from :exc:`ValueError`, raised when failing to
parse a URL. Mostly raised on invalid ports and IPv6 addresses.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__rQ       c/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/boltons/urlutils.pyrO   rO   y   s     	rX   rO   utf8c                 V     [        U 5      $ ! [         a    [        U [        S9s $ f = f)N)encoding)unicodeUnicodeDecodeErrorDEFAULT_ENCODING)objs    rY   
to_unicodera      s.    7s| 7s%5667s   
 ((z\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()<>]|&amp;|&quot;)*(?:[^!"#$%'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)c                 x  ^^ [        U 5      n Su  pEn/ mTR                  mUU4S jn[        R                  U 5       H  nUR	                  S5      UR                  S5      peXE:  a  U(       a
  T" XU 5        Un UR                  S5      n	[        U	5      n
U
R                  (       d%  U(       a  [        US-   U	-   5      n
OU" XU 5        M  U(       a  U
R                  U;  a  U" XU 5        M  T" U
5        M     U(       a  XS nU(       a  U" U5        T$ ! [         a    U(       a  U" XU 5         M   M  f = f)a  This function uses heuristics to searches plain text for strings
that look like URLs, returning a :class:`list` of :class:`URL`
objects. It supports limiting the accepted schemes, and returning
interleaved text as well.

>>> find_all_links('Visit https://boltons.rtfd.org!')
[URL(u'https://boltons.rtfd.org')]
>>> find_all_links('Visit https://boltons.rtfd.org!', with_text=True)
[u'Visit ', URL(u'https://boltons.rtfd.org'), u'!']

Args:
   text (str): The text to search.

   with_text (bool): Whether or not to interleave plaintext blocks
      with the returned URL objects. Having all tokens can be
      useful for transforming the text, e.g., replacing links with
      HTML equivalents. Defaults to ``False``.

   default_scheme (str): Many URLs are written without the scheme
      component. This function can match a reasonable subset of
      those, provided *default_scheme* is set to a string. Set to
      ``False`` to disable matching scheme-less URLs. Defaults to
      ``'https'``.

   schemes (list): A list of strings that a URL's scheme must
      match in order to be included in the results. Defaults to
      empty, which matches all schemes.

.. note:: Currently this function does not support finding IPv6
  addresses or URLs with netloc-less schemes, like mailto.

)r   NNc                 p   > T(       a&  [        TS   [        5      (       a  TS==   U -  ss'   g T" U 5        g N)
isinstancer]   )t_addrets    rY   	_add_text!find_all_links.<locals>._add_text   s*    :c"gw//GqLGGrX      r   z://N)
ra   append_FIND_ALL_URL_REfinditerstartendgroupURLschemerO   )text	with_textdefault_schemeschemesprev_endrp   rq   rj   matchcur_url_textcur_urltailrh   ri   s               @@rY   find_all_linksr~      s#   B dD(HS
C::D "**40[[^UYYq\s	u%&	+ ;;q>L,'G>>!!.5"8<"GHGdo.7>>8$S/*W# 10 IdOJ  	+ $S/* 	+s   :AD!D/DD98D9c                     0 n[        [        S5      [        S5      5       H6  u  p#[        U5      nX@;   a
  U=X'   X'   M  SR                  U5      =X'   X'   M8     U$ )N   z%{0:02X})ziprangechrformat)
safe_charsri   ivcs        rY   _make_quote_mapr      s`    
C E#Jc
+F?CFSV(//22CFSV , JrX   Tc                 (   U(       aM  [        S[        U 5      5      R                  S5      nSR                  U Vs/ s H  n[        U   PM     sn5      $ SR                  U  Vs/ s H  nU[
        ;   a	  [        U   OUPM     sn5      $ s  snf s  snf )z0
Percent-encode a single segment of a URL path.
NFCrZ   r   )r   ra   encodejoin_PATH_PART_QUOTE_MAP_PATH_DELIMSru   
full_quotebytestrbrg   s        rY   quote_path_partr      s     E:d#34;;FCxx'B'Q-a0'BCC88"$" 12\0A)!,qH"$ % % C$   B
$Bc                 (   U(       aM  [        S[        U 5      5      R                  S5      nSR                  U Vs/ s H  n[        U   PM     sn5      $ SR                  U  Vs/ s H  nU[
        ;   a	  [        U   OUPM     sn5      $ s  snf s  snf )z4
Percent-encode a single query string key or value.
r   rZ   r   )r   ra   r   r   _QUERY_PART_QUOTE_MAP_QUERY_DELIMSr   s        rY   quote_query_partr      s     E:d#34;;FCxx7C7a.q17CDD88"$" 23m1C*1-J"$ % % D$r   c                 (   U(       aM  [        S[        U 5      5      R                  S5      nSR                  U Vs/ s H  n[        U   PM     sn5      $ SR                  U  Vs/ s H  nU[
        ;   a	  [        U   OUPM     sn5      $ s  snf s  snf )zqQuote the fragment part of the URL. Fragments don't have
subdelimiters, so the whole URL fragment can be passed.
r   rZ   r   )r   ra   r   r   _FRAGMENT_QUOTE_MAP_FRAGMENT_DELIMSr   s        rY   quote_fragment_partr     s     E:d#34;;FCxxAA,Q/ABB88"$" 014D/D(+!K"$ % % B$r   c                 (   U(       aM  [        S[        U 5      5      R                  S5      nSR                  U Vs/ s H  n[        U   PM     sn5      $ SR                  U  Vs/ s H  nU[
        ;   a	  [        U   OUPM     sn5      $ s  snf s  snf )zQuote special characters in either the username or password
section of the URL. Note that userinfo in URLs is considered
deprecated in many circles (especially browsers), and support for
percent-encoded userinfo can be spotty.
r   rZ   r   )r   ra   r   r   _USERINFO_PART_QUOTE_MAP_USERINFO_DELIMSr   s        rY   quote_userinfo_partr     s     E:d#34;;FCxxgFg1!4gFGG88%)+%) 569I4I-a0%)+ , , G+r   c                 F   SU ;  a  U R                     U $ Uc  SnUc  Sn[        R                  U 5      nUS   /nUR                  n[        S[	        U5      S5       H2  nU" [        X6   5      R                  X5      5        U" X6S-      5        M4     SR                  U5      $ )a  Percent-decode a string, by replacing %xx escapes with their
single-character equivalent. The optional *encoding* and *errors*
parameters specify how to decode percent-encoded sequences into
Unicode characters, as accepted by the :meth:`bytes.decode()` method.  By
default, percent-encoded sequences are decoded with UTF-8, and
invalid sequences are replaced by a placeholder character.

>>> unquote(u'abc%20def')
u'abc def'
%utf-8replacer   rl      r   )split	_ASCII_RErm   r   lenunquote_to_bytesdecoder   )stringr\   errorsbitsresrm   r   s          rY   unquoter     s     &~??6"D7)CZZF1c$i#(//ABtE{ $ 773<rX   c                    U (       d  U R                     g[        U [        5      (       a  U R                  " S5      n U R                   " S5      n[	        U5      S:X  a  U $ US   /nUR
                  nUSS  H!  n U" [        USS    5        U" USS 5        M#     SR                  U5      $ ! [         a    U" S5        U" U5         MS  f = f)z,unquote_to_bytes('abc%20def') -> b'abc def'.rX   r      %rl   r   Nr   )	r   rf   r]   r   r   rm   _HEX_CHAR_MAPKeyErrorr   )r   r   r   rm   items        rY   r   r   8  s     &'""w'<<D
4yA~7)CZZFQR	=bq*+48  88C=  	4L4L	s   :B,,C
	C
c                    U R                  5       n Ub   [        U5      nUSL a
  U[        U '   gUSL a'  Ub  [        SU-  5      e[        R                  U 5        gUb  [        S5      eg! [         a    [        SU< 35      ef = f)a  Registers new scheme information, resulting in correct port and
slash behavior from the URL object. There are dozens of standard
schemes preregistered, so this function is mostly meant for
proprietary internal customizations or stopgaps on missing
standards information. If a scheme seems to be missing, please
`file an issue`_!

Args:
    text (str): Text representing the scheme.
       (the 'http' in 'http://hatnote.com')
    uses_netloc (bool): Does the scheme support specifying a
       network host? For instance, "http" does, "mailto" does not.
    default_port (int): The default port, if any, for netloc-using
       schemes.

.. _file an issue: https://github.com/mahmoud/boltons/issues
Nz+default_port expected integer or None, not TFz>unexpected default port while specifying non-netloc scheme: %rz)uses_netloc expected True, False, or None)lowerint
ValueErrorSCHEME_PORT_MAPNO_NETLOC_SCHEMESadd)ru   uses_netlocdefault_ports      rY   register_schemer   S  s    $ ::<D	0|,L
 d ,  
	# 68DE F Fd#  
	 DEE
  	0 ,/ 0 0	0s   A* *Bc                    / nU  HX  nUS:X  a  M  US:X  a6  U(       a-  [        U5      S:  d
  US   (       a  UR                  5         MC  ME  MG  UR                  U5        MZ     [        U SS 5      S/S/4;   a  UR                  S5        U$ )zNormalize the URL path by resolving segments of '.' and '..',
resulting in a dot-free path.  See RFC 3986 section 5.2.4, Remove
Dot Segments.
.z..rl   r   re   Nr   )r   r(   rm   list)
path_partsri   parts      rY   resolve_path_partsr   z  s     C4<U]C1A	 )/s JJt  JrsO$% 11

3JrX   c                   .    \ rS rSrSrS rSS jrS rSrg)	cachedpropertyi  a  The ``cachedproperty`` is used similar to :class:`property`, except
that the wrapped method is only called once. This is commonly used
to implement lazy attributes.

After the property has been accessed, the value is stored on the
instance itself, using the same name as the cachedproperty. This
allows the cache to be cleared with :func:`delattr`, or through
manipulating the object's ``__dict__``.
c                 2    [        US5      U l        Xl        g )NrV   )getattrrV   func)selfr   s     rY   __init__cachedproperty.__init__  s    tY/	rX   Nc                 v    Uc  U $ U R                  U5      =o1R                  U R                   R                  '   U$ N)r   __dict__rR   )r   r`   objtypevalues       rY   __get__cachedproperty.__get__  s4    ;K3799S>ATYY//0rX   c                 X    U R                   R                  nSU< SU R                  < S3$ )N<z func=>)	__class__rR   r   r   cns     rY   __repr__cachedproperty.__repr__  s     ^^$$!#TYY//rX   )rV   r   r   )	rR   rS   rT   rU   rV   r   r   r   rW   rQ   rX   rY   r   r     s    0rX   r   c                       \ rS rSrSrSrSS jr\  SS j5       r\	S 5       r
\
r\S 5       r\R                  S	 5       r\S
 5       r\S 5       rSS jrS rSS jrSS jrS rS rS rS rS rSrg)rs   i  a  The URL is one of the most ubiquitous data structures in the
virtual and physical landscape. From blogs to billboards, URLs are
so common, that it's easy to overlook their complexity and
power.

There are 8 parts of a URL, each with its own semantics and
special characters:

  * :attr:`~URL.scheme`
  * :attr:`~URL.username`
  * :attr:`~URL.password`
  * :attr:`~URL.host`
  * :attr:`~URL.port`
  * :attr:`~URL.path`
  * :attr:`~URL.query_params` (query string parameters)
  * :attr:`~URL.fragment`

Each is exposed as an attribute on the URL object. RFC 3986 offers
this brief structural summary of the main URL components::

    foo://user:pass@example.com:8042/over/there?name=ferret#nose
    \_/   \_______/ \_________/ \__/\_________/ \_________/ \__/
     |        |          |        |      |           |        |
   scheme  userinfo     host     port   path       query   fragment

And here's how that example can be manipulated with the URL type:

>>> url = URL('foo://example.com:8042/over/there?name=ferret#nose')
>>> print(url.host)
example.com
>>> print(url.get_authority())
example.com:8042
>>> print(url.qp['name'])  # qp is a synonym for query_params
ferret

URL's approach to encoding is that inputs are decoded as much as
possible, and data remains in this decoded state until re-encoded
using the :meth:`~URL.to_text()` method. In this way, it's similar
to Python's current approach of encouraging immediate decoding of
bytes to text.

Note that URL instances are mutable objects. If an immutable
representation of the URL is desired, the string from
:meth:`~URL.to_text()` may be used. For an immutable, but
almost-as-featureful, URL object, check out the `hyperlink
package`_.

.. _hyperlink package: https://github.com/mahmoud/hyperlink

)
rt   r   usernamepasswordfamilyhostportpathquery_paramsfragmentc                 h   [         nU(       a\  [        U[        5      (       a  UR                  5       nO+[        U[        5      (       a   UR                  [        5      n[        U5      nSnUS   =(       d    UU l
        US   =(       d    UU l        SUS   =(       d    U;   a  [        US   5      OUS   =(       d    UU l        SUS	   =(       d    U;   a  [        US	   5      OUS	   =(       d    UU l        US
   U l        US   (       d  X@l        O: US   R#                  S5      U l        U R                   R                  S5      U l        US   U l        [)        US   =(       d    UR+                  S5       Vs/ s H  nSU;   a  [        U5      OUPM     sn5      U l        US   =(       d    UU l        SUS   =(       d    U;   a  [        US   5      OUS   =(       d    UU l        g ! [         a  n[        S[        < SU< S35      eS nAff = f! [$         a    US   U l         Nf = fs  snf )Nzexpected text or zI-encoded bytes. try decoding the url bytes and passing the result. (got: )r   rt   _netloc_sepr   r   r   r   r   r   idnar   r   /queryr   )DEFAULT_PARSED_URLrf   rs   to_textbytesr   r_   r^   rO   	parse_urlrt   r   r   r   r   r   r   r   UnicodeEncodeErrorr   tupler   r   _queryr   )r   urludude_eps         rY   r   URL.__init__  s     #s##kkmC''C**%56C 3Bl(bm,2BzN$8b9 !J0?A*~?SQS 	  BzN$8b9 !J0?A*~?SQS 	l&zI5vJ--g6	 !II,,V4	vJ	%'Z%52$<$<T$B!D$B DEsaxQ!>$B!D Ek'RBzN$8b9 !J0?A*~?SQS 	 	C * C' ,<S)B C CC* & 'vJ	'!Ds0   
G+ H ;H/+
H5HHH,+H,Nc	                     U " 5       n	Xl         X)l        [        U5      =(       d    SU	l        U	R                  R                  U5        XYl        Xil        Xyl        Xl	        U	$ )a  Build a new URL from parts. Note that the respective arguments are
not in the order they would appear in a URL:

Args:
   scheme (str): The scheme of a URL, e.g., 'http'
   host (str): The host string, e.g., 'hatnote.com'
   path_parts (tuple): The individual text segments of the
     path, e.g., ('post', '123')
   query_params (dict): An OMD, dict, or list of (key, value)
     pairs representing the keys and values of the URL's query
     parameters.
   fragment (str): The fragment of the URL, e.g., 'anchor1'
   port (int): The integer port of URL, automatic defaults are
     available for registered schemes.
   username (str): The username for the userinfo part of the URL.
   password (str): The password for the userinfo part of the URL.

Note that this method does relatively little
validation. :meth:`URL.to_text()` should be used to check if
any errors are produced while composing the final textual URL.
r   )
rt   r   r   r   r   updater   r   r   r   )
clsrt   r   r   r   r   r   r   r   ri   s
             rY   
from_partsURL.from_parts  sS    0 e
z*4f-
rX   c                 @    [         R                  U R                  5      $ )a  The parsed form of the query string of the URL, represented as a
:class:`~dictutils.OrderedMultiDict`. Also available as the
handy alias ``qp``.

>>> url = URL('http://boltons.readthedocs.io/?utm_source=doctest&python=great')
>>> url.qp.keys()
[u'utm_source', u'python']
)QueryParamDict	from_textr   r   s    rY   r   URL.query_params5  s     ''44rX   c           
      t    SR                  U R                   Vs/ s H  n[        USS9PM     sn5      $ s  snf )zThe URL's path, in text form.r   Fr   )r   r   r   )r   r   s     rY   r   URL.pathC  s@     yy#'??4#2a *!>#24 5 	5 4s   5c                     [        [        U5      R                  S5       Vs/ s H  nSU;   a  [        U5      OUPM     sn5      U l        g s  snf )Nr   r   )r   ra   r   r   r   )r   	path_textr   s      rY   r   r  I  sT    *4Y*?*E*Ed*K!M*KQ 03axQ!>*K!M N!Ms   Ac                     U R                   nU R                  [        ;   a  gU R                  [        ;   a  gU R                  R	                  S5      S   [        ;   a  gU$ )a  Whether or not a URL uses :code:`:` or :code:`://` to separate the
scheme from the rest of the URL depends on the scheme's own
standard definition. There is no way to infer this behavior
from other parts of the URL. A scheme either supports network
locations or it does not.

The URL type's approach to this is to check for explicitly
registered schemes, with common schemes like HTTP
preregistered. This is the same approach taken by
:mod:`urlparse`.

URL adds two additional heuristics if the scheme as a whole is
not registered. First, it attempts to check the subpart of the
scheme after the last ``+`` character. This adds intuitive
behavior for schemes like ``git+ssh``. Second, if a URL with
an unrecognized scheme is loaded, it will maintain the
separator it sees.

>>> print(URL('fakescheme://test.com').to_text())
fakescheme://test.com
>>> print(URL('mockscheme:hello:world').to_text())
mockscheme:hello:world

TF+re   )r   rt   r   r   r   )r   defaults     rY   r   URL.uses_netlocO  sR    4 "";;/);;++;;S!"%8rX   c                      [         U R                     $ ! [         a4    [         R                  U R                  R	                  S5      S   5      s $ f = f)a3  Return the default port for the currently-set scheme. Returns
``None`` if the scheme is unrecognized. See
:func:`register_scheme` above. If :attr:`~URL.port` matches
this value, no port is emitted in the output of
:meth:`~URL.to_text()`.

Applies the same '+' heuristic detailed in :meth:`URL.uses_netloc`.
r
  re   )r   rt   r   getr   r  s    rY   r   URL.default_portr  sM    	C"4;;// 	C"&&t{{'8'8'=b'ABB	Cs    ;AAc                     [        U R                  5      U l        U(       a>  U R                  R                  5       U l        U R                  R                  5       U l        g)a*  Resolve any "." and ".." references in the path, as well as
normalize scheme and host casing. To turn off case
normalization, pass ``with_case=False``.

More information can be found in `Section 6.2.2 of RFC 3986`_.

.. _Section 6.2.2 of RFC 3986: https://tools.ietf.org/html/rfc3986#section-6.2.2
N)r   r   rt   r   r   )r   	with_cases     rY   r   URL.normalize  s@     -T__=++++-DK		)DIrX   c                 b   Sn[        U[        5      (       d  [        U5      Up!UR                  (       a!  UR                  (       a  Uc  [        U5      $ U$ UR                  nUR
                  (       aS  UR
                  R                  S5      (       a  [        UR                  5      nOEU R                  SS UR                  -   nO([        U R                  5      nU(       d  U R                  nU R                  UR                  =(       d    U R                  UR                  =(       d    U R                  UR                  =(       d    U R                  UUUR                  UR                  =(       d    U R                  UR                  =(       d    U R                  S9nUR                  5         U$ )a"  Factory method that returns a _new_ :class:`URL` based on a given
destination, *dest*. Useful for navigating those relative
links with ease.

The newly created :class:`URL` is normalized before being returned.

>>> url = URL('http://boltons.readthedocs.io')
>>> url.navigate('en/latest/')
URL(u'http://boltons.readthedocs.io/en/latest/')

Args:
   dest (str): A string or URL object representing the destination

More information can be found in `Section 5 of RFC 3986`_.

.. _Section 5 of RFC 3986: https://tools.ietf.org/html/rfc3986#section-5
Nr   re   )rt   r   r   r   r   r   r   r   )rf   rs   rt   r   r   r   
startswithr   r   r   r   r   r   r   r   )r   dest	orig_destr   new_path_partsri   s         rY   navigateURL.navigate  s.   $ 	$$$!$i);;499 !* 13t9;t;((99yy##D))!%doo!6!%"!5!G!$//2N#00ooT[[%?DKK#'99#9		#'99#9		)7+7'+}}'+}}'E'+}}'E  G 	
rX   c                    / nUR                   nU R                  (       a^  U(       aW  U" [        U R                  5      5        U R                  (       a#  U" S5        U" [        U R                  5      5        U" S5        U R                  (       a  U R
                  [        R                  :X  a#  U" S5        U" U R                  5        U" S5        OJU(       a1  U" U R                  R                  S5      R                  S5      5        OU" U R                  5        U R                  (       a=  U R                  U R                  :w  a#  U" S5        U" [        U R                  5      5        SR                  U5      $ )a  Used by URL schemes that have a network location,
:meth:`~URL.get_authority` combines :attr:`username`,
:attr:`password`, :attr:`host`, and :attr:`port` into one
string, the *authority*, that is used for
connecting to a network-accessible resource.

Used internally by :meth:`~URL.to_text()` and can be useful
for labeling connections.

>>> url = URL('ftp://user@ftp.debian.org:2121/debian/README')
>>> print(url.get_authority())
ftp.debian.org:2121
>>> print(url.get_authority(with_userinfo=True))
user@ftp.debian.org:2121

Args:
   full_quote (bool): Whether or not to apply IDNA encoding.
      Defaults to ``False``.
   with_userinfo (bool): Whether or not to include username
      and password, technically part of the
      authority. Defaults to ``False``.

:@[]r   r   r   )rm   r   r   r   r   r   socketAF_INET6r   r   r   r   r]   r   )r   r   with_userinfopartsrh   s        rY   get_authorityURL.get_authority  s    0 ||==]$T]]34}}S	(78I99{{foo-S	TYYS	TYY%%f-44W=>TYYyyTYY$*;*;;S	WTYY'(xxrX   c           
         U R                   nSR                  U R                   Vs/ s H  n[        X1S9PM     sn5      nU R	                  USS9nU R
                  R                  US9n[        U R                  US9n/ nUR                  n	U(       a  U	" U5        U	" S5        U(       a  U	" S5        U	" U5        O)U(       a"  USS S:w  a  U R                  (       a  U	" S5        U(       a'  U(       a  U(       a  USS	 S:w  a  U	" S5        U	" U5        U(       a  U	" S
5        U	" U5        U(       a  U	" S5        U	" U5        SR                  U5      $ s  snf )a  Render a string representing the current state of the URL
object.

>>> url = URL('http://listen.hatnote.com')
>>> url.fragment = 'en'
>>> print(url.to_text())
http://listen.hatnote.com#en

By setting the *full_quote* flag, the URL can either be fully
quoted or minimally quoted. The most common characteristic of
an encoded-URL is the presence of percent-encoded text (e.g.,
%60).  Unquoted URLs are more readable and suitable
for display, whereas fully-quoted URLs are more conservative
and generally necessary for sending over the network.
r   r  T)r   r!  r  z//Nr   rl   ?#r   )rt   r   r   r   r#  r   r   r   r   rm   r   )
r   r   rt   r   r   	authorityquery_stringr   r"  rh   s
             rY   r   URL.to_text  s+     yy#'??4#2a *!C#24 5&&*59 ' ;	((00J0G&t}}L||LIJObqT)d.>.>J)RaCS	 JIINxx;4s   Ec                 ^    U R                   R                  nU< SU R                  5       < S3$ )N(r   )r   rR   r   r   s     rY   r   URL.__repr__   s"    ^^$$//rX   c                 "    U R                  5       $ r   r   r  s    rY   __str__URL.__str__$      ||~rX   c                 "    U R                  5       $ r   r/  r  s    rY   __unicode__URL.__unicode__'  r2  rX   c                 `    U R                    H  n[        X5      [        XS 5      :X  a  M    g   g)NFT)
_cmp_attrsr   )r   otherattrs      rY   __eq__
URL.__eq__*  s,    OOD4&'%t*DD $ rX   c                     X:X  + $ r   rQ   r   r8  s     rY   __ne__
URL.__ne__0  s      rX   )
r   r   r   r   r   r   r   r   rt   r   r   )NNrQ   rQ   r   NNNT)FFF)rR   rS   rT   rU   rV   r7  r   classmethodr   r   r   qppropertyr   setterr   r   r   r  r#  r   r   r0  r4  r:  r>  rW   rQ   rX   rY   rs   rs     s    1hPJ,\ LNDH" "H 	5 	5 
B5 5
 
[[ 
    D C C .`-^.`0!rX   rs   )	inet_ptonc                       \ rS rSrS\R
                  4S\R                  4S\R                  S-  4S\R                  S-  4S\R                  4/r	S	r
g
)	_sockaddri:  	sa_family__pad1	ipv4_addr   	ipv6_addrr   __pad2rQ   N)rR   rS   rT   rU   ctypesc_shortc_ushortc_bytec_ulong_fields_rW   rQ   rX   rY   rH  rH  :  sO     &..1v/ &--!"34 &--""45v~~.	0rX   rH  c           	      ^   [        5       nUR                  S5      nXl        [        R                  " [        R
                  " U5      5      n[        XS [        R                  " U5      [        R                  " U5      5      S:w  a)  [        R                  " [        R                  " 5       5      eU [        R                  :X  a!  [        R                  " UR                  S5      $ U [        R                  :X  a!  [        R                  " UR                  S5      $ [        R                  " S5      e)Nr   r   rL  r   zunknown address family)rH  r   rI  rO  c_intsizeofWSAStringToAddressAbyrefr  errorFormatErrorAF_INET	string_atrK  r   rM  )address_family	ip_stringaddr	addr_sizes       rY   rF  rF  D  s    {$$W-	'LLt!45	y$T@RTZT`T`ajTklpqq,,v11344V^^+##DNNA66V__,##DNNB77ll344rX   c                    U (       d  gSU ;   aE  SU S   :X  a<  SU S   :X  a3  U SS n  [        [        R                  U 5        [        R                  nX4$  [        [        R                  U 5        [        R                  nX4$ ! [        R                   a  n[	        SU < S	U< S
35      eSnAf[
         a     Nef = f! [        R                  [
        4 a    Sn X4$ f = f)a  Low-level function used to parse the host portion of a URL.

Returns a tuple of (family, host) where *family* is a
:mod:`socket` module constant or ``None``, and host is a string.

>>> parse_host('googlewebsite.com') == (None, 'googlewebsite.com')
True
>>> parse_host('[::1]') == (socket.AF_INET6, '::1')
True
>>> parse_host('192.168.1.1') == (socket.AF_INET, '192.168.1.1')
True

Odd doctest formatting above due to py3's switch from int to enums
for :mod:`socket` constants.

)Nr   r  r  r   r  re   rl   zinvalid IPv6 host: z (r   N)rF  r  r   rZ  rO   r   r\  )r   r   ses      rY   
parse_hostrd  T  s    $ t|QDDH,<Abz	 foot, __F< &..$' < || 	Kb IJJ! 		 LL,-  <	s/   B B= B:B**B:9B:=CCc                    [        U 5      n [        R                  U 5      n UR                  5       nUS   nSSUpenU(       a/  UR                  S5      u  pxnU(       a  UR                  S5      u  pInSu  pU(       aq  UR                  S5      u  pnU(       aV  U
(       aC  U
S   S:X  a:  S	U;   a4  UR                  S	5      u  pnU
S-   U-   S	-   n
U(       a  US   S:X  a  US
S n [        U5      n[        U
5      u  pXBS'   XRS'   XS'   XS'   XS'   U$ ! [         a    [        SU -  5      ef = f! [         a    U(       a  [        SU-  5      eSn Nbf = f)a  Used to parse the text for a single URL into a dictionary, used
internally by the :class:`URL` type.

Note that "URL" has a very narrow, standards-based
definition. While :func:`parse_url` may raise
:class:`URLParseError` under a very limited number of conditions,
such as non-integer port, a surprising number of strings are
technically valid URLs. For instance, the text ``"url"`` is a
valid URL, because it is a relative path.

In short, do not expect this function to validate form inputs or
other more colloquial usages of URLs.

>>> res = parse_url('http://127.0.0.1:3000/?a=1')
>>> sorted(res.keys())  # res is a basic dictionary
['_netloc_sep', 'authority', 'family', 'fragment', 'host', 'password', 'path', 'port', 'query', 'scheme', 'username']
zcould not parse url: %rr(  Nr  r  NNr   r  r  rl   z!expected integer for port, not %rr   r   r   r   r   )r]   _URL_RErz   	groupdictAttributeErrorrO   
rpartition	partitionr   r   rd  )url_textumgsau_textuserpwhostinfouserinfosep_r   r   port_str
host_rightr   s                  rY   r   r   |  s   & x H	x	 BB\\^ oGtWhD")"4"4S"9x",,S1KDRJD&0068Q4DH,<*2*<*<T*B'
xd{Z/$6t 3'|H8} d#LFzNzNxLvJvJIK  B5@AAB0  '(K*2)3 4 4	s   D #D- D*-!EEc                    U R                  S5       VVs/ s H  o3R                  S5        H  oDPM     M     nnn/ nU H  nU(       d  M  UR                  S5      u  pn
U
(       d  U(       a  Sn
OM3  [        UR                  SS5      5      nU
(       a  [        U
R                  SS5      5      n
UR	                  X45        M     U$ s  snnf )z<
Converts a query string into a list of (key, value) pairs.
&;=Nr
   )r   rk  r   r   rm   )qskeep_blank_valuesr\   s1s2pairsri   pairkeyru  r   s              rY   	parse_qslr    s     ((3-@-B((3-BR-R-E@
Cs+ ckk#s+,EMM#s34E

C<   J As   #C)KeysView
ValuesView	ItemsView)izip_longest)zip_longest)make_sentinel_MISSING)var_name   c                     ^  \ rS rSrSrU 4S jrS rS rU 4S jrU 4S jr	S,U 4S jjr
\4U 4S	 jjrU 4S
 jr\4U 4S jjrS r\S,S j5       rS rS rU 4S jrU 4S jrU 4S jrS rS r\4S jr\4U 4S jjr\\4U 4S jjrS rS rS-S jrS-S jrS-S jr S-S jr!S.S jr"S.U 4S jjr#S  r$U 4S! jr%S-S" jr&S-S# jr'S-S$ jr(S% r)U 4S& jr*S' r+S( r,S) r-S* r.S+r/U =r0$ )/OrderedMultiDicti  a+  A MultiDict is a dictionary that can have multiple values per key
and the OrderedMultiDict (OMD) is a MultiDict that retains
original insertion order. Common use cases include:

  * handling query strings parsed from URLs
  * inverting a dictionary to create a reverse index (values to keys)
  * stacking data from multiple dictionaries in a non-destructive way

The OrderedMultiDict constructor is identical to the built-in
:class:`dict`, and overall the API is constitutes an intuitive
superset of the built-in type:

>>> omd = OrderedMultiDict()
>>> omd['a'] = 1
>>> omd['b'] = 2
>>> omd.add('a', 3)
>>> omd.get('a')
3
>>> omd.getlist('a')
[1, 3]

Some non-:class:`dict`-like behaviors also make an appearance,
such as support for :func:`reversed`:

>>> list(reversed(omd))
['b', 'a']

Note that unlike some other MultiDicts, this OMD gives precedence
to the most recent value added. ``omd['a']`` refers to ``3``, not
``1``.

>>> omd
OrderedMultiDict([('a', 1), ('b', 2), ('a', 3)])
>>> omd.poplast('a')
3
>>> omd
OrderedMultiDict([('a', 1), ('b', 2)])
>>> omd.pop('a')
1
>>> omd
OrderedMultiDict([('b', 2)])

Note that calling :func:`dict` on an OMD results in a dict of keys
to *lists* of values:

>>> from pprint import pprint as pp  # ensuring proper key ordering
>>> omd = OrderedMultiDict([('a', 1), ('b', 2), ('a', 3)])
>>> pp(dict(omd))
{'a': 3, 'b': 2}

Note that modifying those lists will modify the OMD. If you want a
safe-to-modify or flat dictionary, use :meth:`OrderedMultiDict.todict()`.

>>> pp(omd.todict())
{'a': 3, 'b': 2}
>>> pp(omd.todict(multi=True))
{'a': [1, 3], 'b': [2]}

With ``multi=False``, items appear with the keys in to original
insertion order, alongside the most-recently inserted value for
that key.

>>> OrderedMultiDict([('a', 1), ('b', 2), ('a', 3)]).items(multi=False)
[('a', 3), ('b', 2)]

c                 .  > [        U5      S:  a/  [        U R                  R                  < S[        U5      < 35      e[        [
        U ]  5         U R                  5         U(       a  U R                  US   5        U(       a  U R                  U5        g g )Nrl   z" expected at most 1 argument, got r   )
r   	TypeErrorr   rR   superr  r   	_clear_llupdate_extendr   )r   argskwargsr   s      rY   r   OrderedMultiDict.__init__1  sw    t9q=#~~66D	C D D.0tAw'KK rX   c                      U R                   nUR                  5         U R                  U R                  S /U R                  S S & g ! [         a    0 =ol         / U l         NRf = fr   )_mapri  rootclear)r   r  s     rY   r  OrderedMultiDict._clear_ll=  sY    	99D 	

		499d3		!	  	!!D9DI	s   A A! A!c                     U R                   nU R                  R                  U/ 5      nU[           nXSX/nU=U[        '   U[        '   UR                  U5        g r   )r  r  
setdefaultPREVNEXTrm   )r   kr   r  cellslastcells          rY   _insertOrderedMultiDict._insertF  sR    yy		$$Q+DzA!"&&T
T$ZTrX   c                 r   > [         [        U ]  U/ 5      nU R                  X5        UR	                  U5        g)zQAdd a single value *v* under a key *k*. Existing values under *k*
are preserved.
N)r  r  r  r  rm   )r   r  r   valuesr   s       rY   r   OrderedMultiDict.addN  s1     '9!R@QarX   c                    > U R                   n[        [        U ]  U/ 5      nU H  nU" X5        M     UR	                  U5        g)a\  Add an iterable of values underneath a specific key, preserving
any values already under that key.

>>> omd = OrderedMultiDict([('a', -1)])
>>> omd.addlist('a', range(3))
>>> omd
OrderedMultiDict([('a', -1), ('a', 0), ('a', 1), ('a', 2)])

Called ``addlist`` for consistency with :meth:`getlist`, but
tuples and other sequences and iterables work.
N)r  r  r  r  extend)r   r  r   self_insertr  subvr   s         rY   addlistOrderedMultiDict.addlistV  s@     ll'9!R@D  arX   c                 2   > [         [        U ]  X/5      S   $ )zReturn the value for key *k* if present in the dictionary, else
*default*. If *default* is not given, ``None`` is returned.
This method never raises a :exc:`KeyError`.

To get all values under a key, use :meth:`OrderedMultiDict.getlist`.
re   )r  r  r  r   r  r  r   s      rY   r  OrderedMultiDict.geth  s     %t0I>rBBrX   c                 p   >  [         [        U ]  U5      SS $ ! [         a    U[        L a  / s $ Us $ f = f)zGet all values for key *k* as a list, if *k* is in the
dictionary, else *default*. The list returned is a copy and
can be safely mutated. If *default* is not given, an empty
:class:`list` is returned.
N)r  r  __getitem__r   r  r  s      rY   getlistOrderedMultiDict.getlistq  sA    	)4<Q?BB 	("	N	s    555c                 J   > [         [        U ]  5         U R                  5         g)zEmpty the dictionary.N)r  r  r  r  )r   r   s    rY   r  OrderedMultiDict.clear~  s    +-rX   c                 Z   > [         [        U ]  U5      (       d  U[        L a  SOUX'   X   $ )zIf key *k* is in the dictionary, return its value. If not, insert
*k* with a value of *default* and return *default*. *default*
defaults to ``None``. See :meth:`dict.setdefault` for more
information.
N)r  r  __contains__r  r  s      rY   r  OrderedMultiDict.setdefault  s/     %t9!<<%1dwDGwrX   c                 >    U R                  U R                  SS95      $ )z(Return a shallow copy of the dictionary.Tmultir   	iteritemsr  s    rY   copyOrderedMultiDict.copy  s    ~~dnn4n899rX   c                 @    U " U Vs/ s H  o3U4PM     sn5      $ s  snf )ztCreate a dictionary from a list of keys, with all the values
set to *default*, or ``None`` if *default* is not set.
rQ   )r   keysr  r  s       rY   fromkeysOrderedMultiDict.fromkeys  s#    
 $/$QL$/00/s   c                    XL a  gU R                   n[        U[        5      (       a3  U H  nX@;   d  M
  X	 M     UR                  SS9 H  u  pEU" XE5        M     Ol[	        US5      (       a  UR                  5        H	  nX   X'   M     O=[        5       nUR                   nU H!  u  pEXF;  a  X@;   a
  X	 U" U5        U" XE5        M#     U H	  nX$   X'   M     g)zAdd items from a dictionary or iterable (and/or keyword arguments),
overwriting values under an existing key. See
:meth:`dict.update` for more details.
NTr  r  )r   rf   r  r  hasattrr  set)r   EFself_addr  r   seenseen_adds           rY   r   OrderedMultiDict.update  s     988a)**9  $/ 0QVVX$  5DxxH=QYQK	 
 AdDG rX   c                 (  ^ TU L a  [        TR                  5       5      nOS[        T[        5      (       a  TR	                  SS9nO.[        TS5      (       a  U4S jTR                  5        5       nOTnU R                  nU H  u  pVU" XV5        M     g)zAdd items from a dictionary, iterable, and/or keyword
arguments without overwriting existing items present in the
dictionary. Like :meth:`update`, but adds to existing keys
instead of overwriting them.
Tr  r  c              3   0   >#    U  H  oTU   4v   M     g 7fr   rQ   ).0r  r  s     rY   	<genexpr>1OrderedMultiDict.update_extend.<locals>.<genexpr>  s     48aAaD	8s   N)iteritemsrf   r  r  r  r  r   )r   r  r  iteratorr  r  r   s    `     rY   r  OrderedMultiDict.update_extend  sw     9AGGIH+,,{{{.HQ416684HH88DAQN rX   c                    > [         [        U ]  U5      (       a  U R                  U5        U R	                  X5        [         [        U ]  X/5        g r   )r  r  r  _remove_allr  __setitem__)r   r  r   r   s      rY   r  OrderedMultiDict.__setitem__  sB    !45a88QQ1!S9rX   c                 0   > [         [        U ]  U5      S   $ rd   )r  r  r  r   r  r   s     rY   r  OrderedMultiDict.__getitem__  s    %t8;B??rX   c                 N   > [         [        U ]  U5        U R                  U5        g r   )r  r  __delitem__r  r  s     rY   r  OrderedMultiDict.__delitem__  s!    1!4rX   c                    XL a  g [        U5      [        U 5      :w  a  g [        U[        5      (       at  U R	                  SS9nUR	                  SS9n[        X#SS9nU H  u  u  pVu  pxXW:w  d  Xh:w  d  M    g   [        U[        5      [        L a  [        U[        5      [        L d  gg[        US5      (       a  U  H  n X   X   :H    M     gg! [         a     gf = f! [         a       gf = f)NTFr  rf  )	fillvaluer  )
r   r  rf   r  r  r  nextr  r  r   )	r   r8  selfiotherizipped_itemsselfkselfvotherkothervs	            rY   r:  OrderedMultiDict.__eq__  s   =	5zSY& ' e-..NNN.E__4_0F'NL4@0 0?eo  5A x(H4FH-9UF##!LDK/ 
 +  		$   ! !s#   C 	C 
CC 
C.-C.c                     X:X  + $ r   rQ   r=  s     rY   r>  OrderedMultiDict.__ne__  s    ""rX   c                 v     U R                  U5      S   $ ! [         a    U[        L a  [        U5      e U$ f = f)zRemove all values under key *k*, returning the most-recently
inserted value. Raises :exc:`KeyError` if the key is not
present and no *default* is provided.
re   )popallr   r  )r   r  r  s      rY   r(   OrderedMultiDict.pop  sE    
	";;q>"%% 	"("qk! #	"s    88c                    > [        [        U 5      nUR                  U5      (       a  U R                  U5        U[        L a  UR                  U5      $ UR                  X5      $ )zRemove all values under key *k*, returning them in the form of
a list. Raises :exc:`KeyError` if the key is not present and no
*default* is provided.
)r  r  r  r  r  r(   )r   r  r  
super_selfr   s       rY   r  OrderedMultiDict.popall  sW    
 +T2
""1%%Qh>>!$$~~a))rX   c                 v  > U[         L a9  U (       a  U R                  [           [           nO[	        S[        U 5      -  5      e U R                  U5        [        [        U ]'  U5      nUR                  5       nU(       d  [        [        U ]/  U5        U$ ! [         a    U[         L a  [	        U5      eUs $ f = f)a  Remove and return the most-recently inserted value under the key
*k*, or the most-recently inserted key if *k* is not
provided. If no values remain under *k*, it will be removed
from the OMD.  Raises :exc:`KeyError` if *k* is not present in
the dictionary, or the dictionary is empty.
zempty %r)r  r  r  KEYr   type_remover  r  r  r(   r  )r   r  r  r  r   r   s        rY   poplastOrderedMultiDict.poplast  s     =IIdOC(zDJ677	LLO
 ':1=JJL"D5a8  	("qk!N	s   B  B87B8c                     U R                   U   nUR                  5       nU[           U[           sU[           [        '   U[           [        '   U(       d  U R                   U	 g g r   r  r(   r  r  r   r  r  r  s       rY   r  OrderedMultiDict._remove&  sS    1zz|-1$Zd*T
4$t*T*		! rX   c                     U R                   U   nU(       aH  UR                  5       nU[           U[           sU[           [        '   U[           [        '   U(       a  MH  U R                   U	 g r   r  r  s       rY   r  OrderedMultiDict._remove_all-  sW    1::<D15dT$Z.DJtd4j. f IIaLrX   c              #      #    U R                   nU[           nU(       a)  X2La$  U[           U[           4v   U[           nX2La  M#  ggU R	                  5        H  nX@U   4v   M     g7f)zIterate over the OMD's items in insertion order. By default,
yields only the most-recently inserted value for each key. Set
*multi* to ``True`` to get all inserted items.
N)r  r  r  VALUEiterkeys)r   r  r  currr  s        rY   r  OrderedMultiDict.iteritems4  sd     
 yyDz"3ie,,Dz " }}9n$ 's   AA("A(c              #     #    U R                   nU[           nU(       a   X2La  U[           v   U[           nX2La  M  gg[        5       nUR                  nX2La*  U[           nXd;  a  U" U5        Uv   U[           nX2La  M)  gg7f)zIterate over the OMD's keys in insertion order. By default, yields
each key once, according to the most recent insertion. Set
*multi* to ``True`` to get all keys, including duplicates, in
insertion order.
N)r  r  r  r  r   )r   r  r  r  yieldedyielded_addr  s          rY   r  OrderedMultiDict.iterkeysC  s      yyDz"3iDz " eG!++K"I#NGDz "s   9BABBc              #   D   #    U R                  US9 H	  u  p#Uv   M     g7f)zIterate over the OMD's values in insertion order. By default,
yields the most-recently inserted value per unique key.  Set
*multi* to ``True`` to get all values according to insertion
order.
r  N)r  )r   r  r  r   s       rY   
itervaluesOrderedMultiDict.itervaluesY  s#      NNN/DAG 0s    c           	          U(       a,  [        U  Vs/ s H  o"U R                  U5      4PM     sn5      $ [        U  Vs/ s H  o"X   4PM
     sn5      $ s  snf s  snf )a@  Gets a basic :class:`dict` of the items in this dictionary. Keys
are the same as the OMD, values are the most recently inserted
values for each key.

Setting the *multi* arg to ``True`` is yields the same
result as calling :class:`dict` on the OMD, except that all the
value lists are copies that can be safely mutated.
)r
   r  )r   r  r  s      rY   todictOrderedMultiDict.todictb  sR     t<t!T\\!_-t<==404a\4011 =0s
   AAc                 V    U R                   nU" [        U R                  5       XS95      $ )a)  Similar to the built-in :func:`sorted`, except this method returns
a new :class:`OrderedMultiDict` sorted by the provided key
function, optionally reversed.

Args:
    key (callable): A callable to determine the sort key of
      each element. The callable should expect an **item**
      (key-value pair tuple).
    reverse (bool): Set to ``True`` to reverse the ordering.

>>> omd = OrderedMultiDict(zip(range(3), range(3)))
>>> omd.sorted(reverse=True)
OrderedMultiDict([(2, 2), (1, 1), (0, 0)])

Note that the key function receives an **item** (key-value
tuple), so the recommended signature looks like:

>>> omd = OrderedMultiDict(zip('hello', 'world'))
>>> omd.sorted(key=lambda i: i[1])  # i[0] is the key, i[1] is the val
OrderedMultiDict([('o', 'd'), ('l', 'l'), ('e', 'o'), ('l', 'r'), ('h', 'w')])
r  reverse)r   sortedr  )r   r  r  r   s       rY   r  OrderedMultiDict.sortedo  s&    , nn6$..*EFFrX   c                 l  >  [         [        U ]  5       n[        U VVs/ s H  u  pEU[        XQU(       + S94PM     snn5      nU R                  5       nU R                  SS9 H%  nUR                  XFU   R                  5       5        M'     U$ ! [         a    [         [        U ]  5       n Nf = fs  snnf )a  Returns a copy of the :class:`OrderedMultiDict` with the same keys
in the same order as the original OMD, but the values within
each keyspace have been sorted according to *key* and
*reverse*.

Args:
    key (callable): A single-argument callable to determine
      the sort key of each element. The callable should expect
      an **item** (key-value pair tuple).
    reverse (bool): Set to ``True`` to reverse the ordering.

>>> omd = OrderedMultiDict()
>>> omd.addlist('even', [6, 2])
>>> omd.addlist('odd', [1, 5])
>>> omd.add('even', 4)
>>> omd.add('odd', 3)
>>> somd = omd.sortedvalues()
>>> somd.getlist('even')
[2, 4, 6]
>>> somd.keys(multi=True) == omd.keys(multi=True)
True
>>> omd == somd
False
>>> somd
OrderedMultiDict([('even', 2), ('even', 4), ('odd', 1), ('odd', 3), ('even', 6), ('odd', 5)])

As demonstrated above, contents and key order are
retained. Only value order changes.
r  Tr  )r  r  r  ri  r  r
   r  r   r  r   r(   )	r   r  r  superself_iteritemsr  r   sorted_val_mapri   r   s	           rY   sortedvaluesOrderedMultiDict.sortedvalues  s    <	H"'(8$"I"K +>@+>41 !"6!7{#LM+>@ AnnT*AGGAa(,,./ +
  	H"'(8$"E"G	H@s   B B0
B-,B-c                 L    U R                  S U R                  SS9 5       5      $ )a  Returns a new :class:`OrderedMultiDict` with values and keys
swapped, like creating dictionary transposition or reverse
index.  Insertion order is retained and all keys and values
are represented in the output.

>>> omd = OMD([(0, 2), (1, 2)])
>>> omd.inverted().getlist(2)
[0, 1]

Inverting twice yields a copy of the original:

>>> omd.inverted().inverted()
OrderedMultiDict([(0, 2), (1, 2)])
c              3   ,   #    U  H
  u  pX!4v   M     g 7fr   rQ   )r  r  r   s      rY   r  ,OrderedMultiDict.inverted.<locals>.<genexpr>  s     L1Kqf1Ks   Tr  r  r  s    rY   invertedOrderedMultiDict.inverted  s$     ~~Ld1KLLLrX   c                 X   >^ [         [        U ]
  mU R                  U4S jU  5       5      $ )zReturns a mapping from key to number of values inserted under that
key. Like :py:class:`collections.Counter`, but returns a new
:class:`OrderedMultiDict`.
c              3   H   >#    U  H  o[        T" U5      5      4v   M     g 7fr   )r   )r  r  super_getitems     rY   r  *OrderedMultiDict.counts.<locals>.<genexpr>  s     G$Q#mA&6"78$s   ")r  r  r  r   )r   r"  r   s    @rY   countsOrderedMultiDict.counts  s'     .A~~G$GGGrX   c                 2    [        U R                  US95      $ )zdReturns a list containing the output of :meth:`iterkeys`.  See
that method's docs for more details.
r  )r   r  r   r  s     rY   r  OrderedMultiDict.keys  s     DMMM.//rX   c                 2    [        U R                  US95      $ )zfReturns a list containing the output of :meth:`itervalues`.  See
that method's docs for more details.
r  )r   r  r'  s     rY   r  OrderedMultiDict.values  s     DOO%O011rX   c                 2    [        U R                  US95      $ )zeReturns a list containing the output of :meth:`iteritems`.  See
that method's docs for more details.
r  )r   r  r'  s     rY   r  OrderedMultiDict.items  s     DNNN/00rX   c                 "    U R                  5       $ r   )r  r  s    rY   __iter__OrderedMultiDict.__iter__  s    }}rX   c              #     >#    U R                   nU[           n0 nUR                  n[        [        U ]  nX!LaG  U[           nU" U5      nU" US5      [        U5      :X  a  Uv   X6==   S-  ss'   U[           nX!La  MF  g g 7f)Nrl   )r  r  r  r  r  r  r  r   )	r   r  r  lengths
lengths_sd
get_valuesr  valsr   s	           rY   __reversed__OrderedMultiDict.__reversed__  s     yyDz''
+T>
S	Aa=D!Q3t9,J!OJ:D s   A:B?Bc           
          U R                   R                  nSR                  U R                  SS9 VVs/ s H  u  p#[	        X#45      PM     snn5      nU< SU< S3$ s  snnf )Nz, Tr  z([z]))r   rR   r   r  repr)r   r   r  r   kvss        rY   r   OrderedMultiDict.__repr__  sT    ^^$$ii$..t.2LM2L$!qf2LMN%% Ns   A
c                     [        U 5      $ )zBOMD.viewkeys() -> a set-like object providing a view on OMD's keys)r  r  s    rY   viewkeysOrderedMultiDict.viewkeys  s    ~rX   c                     [        U 5      $ )z>OMD.viewvalues() -> an object providing a view on OMD's values)r  r  s    rY   
viewvaluesOrderedMultiDict.viewvalues  s    $rX   c                     [        U 5      $ )zDOMD.viewitems() -> a set-like object providing a view on OMD's items)r  r  s    rY   	viewitemsOrderedMultiDict.viewitems  s    rX   )r  r  r   rA  )NF)1rR   rS   rT   rU   rV   r   r  r  r   r  r  r  r  r  r  r  rB  r  r   r  r  r  r  r:  r>  r(   r  r  r  r  r  r  r  r  r  r  r  r$  r  r  r  r.  r5  r   r<  r?  rB  rW   __classcell__)r   s   @rY   r  r    s   AD
 4$C "* 
 %- : 1 1<&:@:# & 
 !) 
* !( 0%",2G2(TM"H021&
  rX   r  )r  c                   2    \ rS rSrSr\S 5       rSS jrSrg)r   i  a7  A subclass of :class:`~dictutils.OrderedMultiDict` specialized for
representing query string values. Everything is fully unquoted on
load and all parsed keys and values are strings by default.

As the name suggests, multiple values are supported and insertion
order is preserved.

>>> qp = QueryParamDict.from_text(u'key=val1&key=val2&utm_source=rtd')
>>> qp.getlist('key')
[u'val1', u'val2']
>>> qp['key']
u'val2'
>>> qp.add('key', 'val3')
>>> qp.to_text()
'key=val1&key=val2&utm_source=rtd&key=val3'

See :class:`~dictutils.OrderedMultiDict` for more API features.
c                 &    [        USS9nU " U5      $ )z@
Parse *query_string* and return a new :class:`QueryParamDict`.
T)r~  )r  )r   r)  r  s      rY   r  QueryParamDict.from_text  s    
 ,$?5zrX   c                    / nU R                  SS9 Hb  u  p4[        [        U5      US9nUc  UR                  U5        M.  [        [        U5      US9nUR                  SR	                  XV45      5        Md     SR	                  U5      $ )z
Render and return a query string.

Args:
   full_quote (bool): Whether or not to percent-quote special
      characters or leave them decoded for readability.
Tr  r  r{  ry  )r  r   ra   rm   r   )r   r   ret_listr  r   r  vals          rY   r   QueryParamDict.to_text'  sy     NNN.DA":a=ZHCy$&z!}L		3* 56 / yy""rX   rQ   NrA  )	rR   rS   rT   rU   rV   rB  r  r   rW   rQ   rX   rY   r   r     s     &  #rX   r   )Fr   rQ   r@  )r   r   rf  )\rV   rer  r   unicodedatar   r  r]   unichr	NameErrorr   	frozenset_UNRESERVED_CHARScompilerg  r
   	hexdigitsr   r   r   r   r   r  r   _GEN_DELIMS_SUB_DELIMS_ALL_DELIMS_USERINFO_SAFEr   
_PATH_SAFEr   _FRAGMENT_SAFEr   _QUERY_SAFEr   r   rO   r_   ra   rn   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   objectr   rs   rF  ImportErrorrO  	StructurerH  windllws2_32rX  WSAAddressToStringArd  r   r   r  collections.abcr  r  r  collections	itertoolsr  r  	typeutilsr  r  r   r  r  r  r  SPREVSNEXTr  boltons.dictutilsOMDr   )ar   s   00rY   <module>rj     sW  B, 
   !
s)

  ; <  ** - . %//K/!9I9IA ~~g.c!%n-44Y?A9IA/K L JJ'(	
D63 
Ds 
DFD 
D% 
D4
D!&
D,14
D9A2
D2
D&
D-3S
D:?
D 3
D !&s
D -3D
D ;A#
D C	
D "'	
D /5d	
D =DT	
D
 4
D
 "'
D
 .4S
D
 ;B3
D #
D  *4
D 29$
D AH
D 3
D !(
D /6t
D >DR
D #
D  &s
D 46"$tbd
D  / 0  
#'K'"[0/ ,s5z9
Z'"Z/#e*</ .3v;">>k)	J 	  7 ::j  *  @  A IX
 +>: &z2 '4 %n5 %%%
,66$N.0V 02G!& G!T5 >%P=@ r]  %)3C ,
<??6&'j1H
 (-Qx $dCuQt Qh	2 ,#% ,#Y.  FKP  50F$$ 0 !--..BB --..BB55L  <;;<
  656  xH|  		ss   J AJ
J 7
L L 	L) 0L< JJA"K>=K>LLL&%L&)L98L9<MM