U a= @sPUdZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddlm Z ej r|dd lmZed Zeed Zd Zd deDZddedDZGdddejZGdddeZGdddeZGdddeZeeiZej ej!e"ej e#e"ffe$d<dnej%e&e#fej%e&e#fe#dddZ'ej%ej(e&e&fej)ej*e&e&ffe&e+ej,ej-ej*e&e&fgej.fej/e&dd d!Z0doe&e&e&d"d#d$Z1dpe&ej,e&e+ed&d'd(Z2dqe&e&ej%e&e#fej%e&e#fej-e#ge&fd,d-d.Z3e3Z4e3d/d0d1Z5e#e&d2d3d4Z6drej%e&e#fe&e&ej%e&e#fej%e&e#fe&d5d6d7Z7dse&e&e&e&e&d8d9d:Z8ej*e&e&e&e&e&fe&d;de?ej*e&e"fdJdKdLZ@eAdMe@dwej%e&ej*e&e&e&e&e&ffe&e&e&dNdOdPZBdQZCdxej%e&ej*e&e&e&e&e&ffe&e&e+e&dSdTdUZDdyejEe&de+e&e&ej,ejFdWdXdYdZd[ZGdzejHe&de+e&e#ej,ejFdWej,e"e+dXd] d^d_ZIej)ejEe&e+e&ej/ej*e&e&fd`dadbZJd{ej%ej(e&e&fej)ej*e&e&ffe&de+ej,ej-ej*e&e&fgej.fe&e&dcdddeZKd|ej%ej(e&e&fej)ej*e&e&ffej,ejLe&de+ej,ej-ej*e&e&fgej.fe&ddfdgdhZMd}ej%e&ej*e&e&e&e&e&ffej%e&ej*e&e&e&e&e&ffe+e&didjdkZNGdldmdmZOdS)~zFunctions for working with URLs. Contains implementations of functions from :mod:`urllib.parse` that handle bytes and strings. N)_check_str_tuple) _decode_idna) _encode_idna)_make_encode_wrapper)_to_str)datastructuresz^[a-zA-Z0-9+-.]+$sBabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~0123456789ABCDEFabcdefcCs8i|]0}tD]&}||dt||dq qS)ascii) _hexdigitsencodeint).0abrNC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-1tps7o9u\werkzeug\urls.py #s rcCsg|]}d|ddqS)%02Xr )r )rcharrrr (src@s6eZdZUeed<eed<eed<eed<eed<dS) _URLTupleschemenetlocpathqueryfragmentN)__name__ __module__ __qualname__str__annotations__rrrrr+s rc@seZdZUdZdZeed<eed<eed<eed<eddd Zej dd d d Z e ej edd dZ e ej edddZe ej edddZe ej edddZe ej edddZe ej edddZe ej edddZe ej edddZej ej dddd Zej ej ddd!d"Zedd#d$Zedd%d&Zedd'd(Zddd)d*Zddd+d,Zd7ej eejej eej efd.d/d0Zejej eefdd1d2Zejej eej efdd3d4Z ejej eej efdd5d6Z!d-S)8BaseURLz7Superclass of :py:class:`URL` and :py:class:`BytesURL`.r_at_colon _lbracket _rbracketreturncCs|SN)to_urlselfrrr__str__<szBaseURL.__str__)kwargsr+cKs |jf|S)zReturn an URL with the same values, except for those parameters given new values by whichever keyword arguments are specified.)_replace)r/r1rrrreplace?szBaseURL.replacecCs |dS)zThe host part of the URL if available, otherwise `None`. The host is either the hostname or the IP address mentioned in the URL. It will not contain the port. r) _split_hostr.rrrhostDsz BaseURL.hostcCsR|j}|dk rFt|trFz t|}Wn tk rD|dd}YnXt|ddS)a Works exactly like :attr:`host` but will return a result that is restricted to ASCII. If it finds a netloc that is not ASCII it will attempt to idna decode it. This is useful for socket operations when the URL might include internationalized characters. Nr ignore)r5 isinstancer#r UnicodeErrorr rr/rvrrr ascii_hostLs zBaseURL.ascii_hostc CsTz6tt|d}d|kr*dkr4nn|WSWnttfk rNYnXdS)z}The port in the URL as an integer if it was present, `None` otherwise. This does not fill in default ports. rriN)rrr4 ValueError TypeErrorr9rrrport[s z BaseURL.portcCs |dS)zSThe authentication part in the URL if available, `None` otherwise. r) _split_netlocr.rrrauthhsz BaseURL.authcCs |d}|dk rt|SdS)zThe username if it was part of the URL, `None` otherwise. This undergoes URL decoding and will always be a string. rN _split_auth_url_unquote_legacyr9rrrusernameos zBaseURL.usernamecCs |dS)zThe username if it was part of the URL, `None` otherwise. Unlike :attr:`username` this one is not being decoded. rrBr.rrr raw_usernameyszBaseURL.raw_usernamecCs |d}|dk rt|SdS)zThe password if it was part of the URL, `None` otherwise. This undergoes URL decoding and will always be a string. rNrAr9rrrpasswords zBaseURL.passwordcCs |dS)zThe password if it was part of the URL, `None` otherwise. Unlike :attr:`password` this one is not being decoded. rrEr.rrr raw_passwordszBaseURL.raw_passwordds.MultiDict[str, str])argsr1r+cOst|jf||S)zDecodes the query part of the URL. Ths is a shortcut for calling :func:`url_decode` on the query argument. The arguments and keyword arguments are forwarded to :func:`url_decode` unchanged. ) url_decoderr/rJr1rrr decode_queryszBaseURL.decode_querycOstt|f||S)zJoins this URL with another one. This is just a convenience function for calling into :meth:`url_join` and then parsing the return value again. ) url_parseurl_joinrLrrrjoinsz BaseURL.joincCst|S)zReturns a URL string or bytes depending on the type of the information stored. This is just a convenience function for calling :meth:`url_unparse` for this URL. ) url_unparser.rrrr-szBaseURL.to_urlc Cs|jpd}d|krd|d}|j}|dk r:|d|}dtdt|jpLddddt|jp^ddddg}|r|d |}|S) z6Encodes the netloc part to an ASCII safe URL as bytes.:[]Nutf-8strictz/:%@)r;r>rPfilter url_quoterFrHr/r:r>r@rrr encode_netlocs"   zBaseURL.encode_netloccCst|jp d}d|kr"d|d}|j}|dk r>|d|}dtdt|jpPddt|jp^ddg}|r||d|}|S)z&Decodes the netloc part into a string.rRrSrTrUNz/:%@rX)rr5r>rPrYrCrFrHr[rrr decode_netlocs"  zBaseURL.decode_netloccCs tt|S)a*Returns a :class:`BytesURL` tuple that holds a URI. This will encode all the information in the URL properly to ASCII using the rules a web browser would follow. It's usually more interesting to directly call :meth:`iri_to_uri` which will return a string. )rN iri_to_urir.rrr to_uri_tupleszBaseURL.to_uri_tuplecCs tt|S)aSReturns a :class:`URL` tuple that holds a IRI. This will try to decode as much information as possible in the URL without losing information similar to how a web browser does it for the URL bar. It's usually more interesting to directly call :meth:`uri_to_iri` which will return a string. )rN uri_to_irir.rrr to_iri_tuples zBaseURL.to_iri_tupleN) pathformatr+cCs:|jdkrdSt|j}|jp d}|dkr>tjdkr:d}nd}|dkr|dddkr|dd r|d d d kr|dd d |d d}|dd d k}ddl}||}|r|dkr| d dd}t |d kr|\}}n |d}d}n,|dkrddl }||}nt d||dkr2d}||fS)a@Returns a tuple with the location of the file in the form ``(server, location)``. If the netloc is empty in the URL or points to localhost, it's represented as ``None``. The `pathformat` by default is autodetection but needs to be set when working with URLs of a specific system. The supported values are ``'windows'`` when working with Windows or DOS paths and ``'posix'`` when working with posix paths. If the URL does not point to a local file, the server and location are both represented as ``None``. :param pathformat: The expected format of the path component. Currently ``'windows'`` and ``'posix'`` are supported. Defaults to ``None`` which is autodetect. fileNNNntZwindowsposixr/z|:rS)z\\\z///r\rRzInvalid path format )z 127.0.0.1z::1 localhost)r url_unquoterrosnameisalphantpathnormpathlstripsplitlen posixpathr=)r/rbrr5Z windows_sharerppartsrurrrget_file_locations6    0       zBaseURL.get_file_locationcCs2|j|jkr(|j|j\}}}||fSd|jfSr,)r&r partition)r/r@_rrrrr?$s zBaseURL._split_netloccCs@|d}|sdS|j|kr&|dfS||j\}}}||fS)Nrrd)r?r'rx)r/r@rDryrGrrrrB*s  zBaseURL._split_authcCs|d}|sdS||jsL|j|krD||j\}}}||fS|dfS||j}|dkrh|dfS|d|}||dd}||jr||ddfS|dfS)Nrrdr)r? startswithr(r'rxfindr))r/r:r5ryr>idxrestrrrr44s       zBaseURL._split_host)N)"r r!r"__doc__ __slots__r#r$r0tAnyr3propertyOptionalr5r;rr>r@rDrFrGrHrMrPr-r\r]r_raTuplerwr?rBr4rrrrr%3sN       >$ r%c@s8eZdZdZdZdZdZdZdZde e d d d d Z d S)URLzRepresents a parsed URL. This behaves like a regular tuple but also has some extra attributes that give further insight into the URL. rrXrSrTrUrVr3BytesURLcharseterrorsr+c Cs:t|jd||j|||j|||j||S)zEncodes the URL to a tuple made out of bytes. The charset is only being used for the path, query and fragment. r )rrr r\rrrr/rrrrrr Vs    z URL.encodeN)rVr3) r r!r"r~rr&r'r(r)r#r rrrrrJsrc@sTeZdZdZdZdZdZdZdZe ddd Z e dd d Z de e ddddZ dS)rz!Represents a parsed URL in bytes.r@:[]r*cCs|ddS)NrVr3)r-decoder.rrrr0lszBytesURL.__str__cCs|jS)z&Returns the netloc unchanged as bytes.)rr.rrrr\oszBytesURL.encode_netlocrVr3rrc Cs:t|jd||j|||j|||j||S)zDecodes the URL to a tuple made out of strings. The charset is only being used for the path, query and fragment. r )rrrr]rrrrrrrrss    zBytesURL.decodeN)rVr3)r r!r"r~rr&r'r(r)r#r0bytesr\rrrrrrcsr _unquote_mapsrR)stringunsafer+cst|tr|d}ttr(dttt|d}tt|d}z t}Wn2t k rfddt D}t<YnX|D]N}|dd}||kr| ||| |ddq| d| |qt|S)NrV%csi|]\}}|kr||qSrr)rhrrrrrsz%_unquote_to_bytes..rh%)r7r#r frozenset bytearrayiterrsnextrKeyError _hextobyteitemsappendextendr)rrgroupsresultZ hex_to_bytegroupcoderrr_unquote_to_bytess*          r)objrsortkeyr+c csddlm}||}|r$t||d}|D]f\}}|dkr:q(t|tsTt||}n|}t|tsrt||} n|} t|dt| Vq(dS)Nr)iter_multi_items)r=)rrsortedr7rr#r _fast_url_quote_plus) rrrrriterableZkey_strZ value_str key_bytesZ value_bytesrrr_url_encode_impls     r)valuerr+cCs:zt|dd|dWStk r4t|d|dYSXdS)NrVrW)rrrlatin1)rr)rlr8)rrrrrrCsrCT)urlrallow_fragmentsr+c st|t|t}|dkr"d}d}}}|d}|dkrtt|d|ddr||dd}|rtfdd |Dr|d||}}|dd d krFt |} d D]"} || d } | dkrt | | } q|d | || d}}d |kr"d|ks>d|krFd |krFt d|rnd|krn| dd\}}d|kr| dd\}}|rt nt} | |||||S)aParses a URL from a string into a :class:`URL` tuple. If the URL is lacking a scheme it can be provided as second argument. Otherwise, it is ignored. Optionally fragments can be stripped from the URL by setting `allow_fragments` to `False`. The inverse of this function is :func:`url_unparse`. :param url: the URL to parse. :param scheme: the default schema to use if the URL is schemaless. :param allow_fragments: if set to `False` a fragment will be removed from the URL. NrRrSrr3)rrc3s|]}|dkVqdS) 0123456789Nrrcsrr szurl_parse..rh//z/?#rTrUzInvalid IPv6 URL#?)rr7r#r{ _scheme_rematchranylowerrtminr<rsrr) rrrZ is_text_basedrrrir}delimrwdelimZ result_typerrrrNs: "     rNrVrW/:)rrsaferr+csvttr||t|tr,|||}tttBtt|fddtdDttdfdd }|S)aPrecompile the translation table for a URL encoding function. Unlike :func:`url_quote`, the generated function only takes the string to quote. :param charset: The charset to encode the result with. :param errors: How to handle encoding errors. :param safe: An optional sequence of safe characters to never encode. :param unsafe: An optional sequence of unsafe characters to always encode. cs(g|] }|krt|n d|dqS)rr)chrrrrrrsz(_make_fast_url_quote..rrr+csdfdd|DS)NrRcsg|] }|qSrrrtablerrrsz7_make_fast_url_quote..quote..)rPrrrrquotesz#_make_fast_url_quote..quote)r7r#r rr _always_saferanger)rrrrrr)rrr_make_fast_url_quotes    r +)rrrcCst|ddS)Nrr)_fast_quote_plusr3rrrrrsr)rrrrrr+cCst|tttfst|}t|tr.|||}t|trD|||}t|trZ|||}tt|tBtt|}t}t|D]&}||kr||q|t |qt| |S)aDURL encode a single string with a given encoding. :param s: the string to quote. :param charset: the charset to be used. :param safe: an optional sequence of safe characters. :param unsafe: an optional sequence of unsafe characters. .. versionadded:: 0.9.2 The `unsafe` parameter was added. ) r7r#rrr rrrr _bytetohexr)rrrrrr:rrrrrZ#s        rZ)rrrrr+cCst||||ddddS)zURL encode a single string with the given encoding and convert whitespace to "+". :param s: The string to quote. :param charset: The charset to be used. :param safe: An optional sequence of safe characters. rr)rZr3)rrrrrrrurl_quote_plusFs r) componentsr+cCst||\}}}}}t|}|d}|s<|rz||drz|r`|dd|dkr`|d|}|d|pp|d|}n |r||7}|r||d|}|r||d|}|r||d|}|S) zThe reverse operation to :meth:`url_parse`. This accepts arbitrary as well as :class:`URL` tuples and returns a URL as a string. :param components: the parsed URL as tuple which should be converted into a URL string. rRrgNrrrSrr)rrrz)rrrrrrrrrrrrQSs" rQr3)rrrrr+cCs"t||}|dkr|S|||S)afURL decode a single string with a given encoding. If the charset is set to `None` no decoding is performed and raw bytes are returned. :param s: the string to unquote. :param charset: the charset of the query string. If set to `None` no decoding will take place. :param errors: the error handling for the charset decoding. N)rr)rrrrr:rrrrlrs rl)rrrr+cCs0t|tr|dd}n |dd}t|||S)aURL decode a single string with the given `charset` and decode "+" to whitespace. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. :param s: The string to unquote. :param charset: the charset of the query string. If set to `None` no decoding will take place. :param errors: The error handling for the `charset` decoding. rr+ )r7r#r3rl)rrrrrrurl_unquote_pluss  r)rrr+cCst||ddd}|drP|ddrP|dddkrPd |dd }t|}t|j|d d }t|j|d d }t|j |d d }t |j | |||fS)aSometimes you get an URL by a user that just isn't a real URL because it contains unsafe characters like ' ' and so on. This function can fix some of the problems in a similar way browsers handle data entered by the user: >>> url_fix('http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)') 'http://de.wikipedia.org/wiki/Elf%20(Begriffskl%C3%A4rung)' :param s: the string with the URL to fix. :param charset: The target charset for the URL if the url was given as a string. r3rjrgzfile:// )z:/z|/zfile:///Nz /%+$!*'(),rz :&%=+$!*'(),) rr3rzrorNrZrrrrrQrr\)rrrrqsanchorrrrurl_fixs*rcCsg|]}|tkrt|qSr)rrrrrrrs)er+cCs t|j|j|j}||jfS)zRUsed in :func:`uri_to_iri` after unquoting to re-quote any invalid bytes. )_fast_url_quoteobjectstartend)routrrr_codec_error_url_quotesrwerkzeug.url_quote)urirrr+cCsht|trt|}tt||}t|j||t}t|j||t}t|j ||t}t|j | |||fS)aConvert a URI to an IRI. All valid UTF-8 characters are unquoted, leaving all reserved and invalid characters quoted. If the URL has a domain, it is decoded from Punycode. >>> uri_to_iri("http://xn--n3h.net/p%C3%A5th?q=%C3%A8ry%DF") 'http://\u2603.net/p\xe5th?q=\xe8ry%DF' :param uri: The URI to convert. :param charset: The encoding to encode unquoted bytes with. :param errors: Error handler to use during ``bytes.encode``. By default, invalid bytes are left quoted. .. versionchanged:: 0.15 All reserved and invalid characters remain quoted. Previously, only some reserved characters were preserved, and invalid bytes were replaced instead of left quoted. .. versionadded:: 0.6 ) r7tuplerQrNrrlr_to_iri_unsaferrrr])rrrrrrrrrr`s r`z:/?#[]@!$&'()*+,;=%F)irirrsafe_conversionr+c Cst|trt|}|rXz,t|}|d}t|dkr@|WSWntk rVYnXtt|||}t |j ||t }t |j ||t }t |j ||t }t|j||||fS)aConvert an IRI to a URI. All non-ASCII and unsafe characters are quoted. If the URL has a domain, it is encoded to Punycode. >>> iri_to_uri('http://\u2603.net/p\xe5th?q=\xe8ry%DF') 'http://xn--n3h.net/p%C3%A5th?q=%C3%A8ry%DF' :param iri: The IRI to convert. :param charset: The encoding of the IRI. :param errors: Error handler to use during ``bytes.encode``. :param safe_conversion: Return the URL unchanged if it only contains ASCII characters and no whitespace. See the explanation below. There is a general problem with IRI conversion with some protocols that are in violation of the URI specification. Consider the following two IRIs:: magnet:?xt=uri:whatever itms-services://?action=download-manifest After parsing, we don't know if the scheme requires the ``//``, which is dropped if empty, but conveys different meanings in the final URL if it's present or not. In this case, you can use ``safe_conversion``, which will return the URL unchanged if it only contains ASCII characters and no whitespace. This can result in a URI with unquoted characters if it was not already quoted correctly, but preserves the URL's semantics. Werkzeug uses this for the ``Location`` header for redirects. .. versionchanged:: 0.15 All reserved characters remain unquoted. Previously, only some reserved characters were left unquoted. .. versionchanged:: 0.9.6 The ``safe_conversion`` parameter was added. .. versionadded:: 0.6 r r)r7rrQrr rtrsr8rNrZr _to_uri_saferrrr\) rrrrZ native_iriZ ascii_irirrrrrrr^s+   r^&z ds.MultiDictrI)rr decode_keys include_emptyr separatorclsr+cCs|dk rtjdtdd|dkr0ddlm}|}t|trTt|tsT||pNd}n"t|trvt|tsv| |prd}|t | ||||S)awParse a query string and return it as a :class:`MultiDict`. :param s: The query string to parse. :param charset: Decode bytes to string with this charset. If not given, bytes are returned as-is. :param include_empty: Include keys with empty values in the dict. :param errors: Error handling behavior when decoding bytes. :param separator: Separator character between pairs. :param cls: Container to hold result instead of :class:`MultiDict`. .. versionchanged:: 2.0 The ``decode_keys`` parameter is deprecated and will be removed in Werkzeug 2.1. .. versionchanged:: 0.5 In previous versions ";" and "&" could be used for url decoding. Now only "&" is supported. If you want to use ";", a different ``separator`` can be provided. .. versionchanged:: 0.5 The ``cls`` parameter was added. N@'decode_keys' is deprecated and will be removed in Werkzeug 2.1.rh stacklevelr MultiDictr ) warningswarnDeprecationWarningrrr7r#rrr _url_decode_implrs)rrrrrrrrrrrrK3s* rK&) streamrrrrrrlimitreturn_iteratorr+c Csvddlm} |dk r$tjdtdd| |||} t| |||} |rVtjdtdd| S|dkrnddlm} | }|| S) a_Works like :func:`url_decode` but decodes a stream. The behavior of stream and limit follows functions like :func:`~werkzeug.wsgi.make_line_iter`. The generator of pairs is directly fed to the `cls` so you can consume the data while it's parsed. :param stream: a stream with the encoded querystring :param charset: the charset of the query string. If set to `None` no decoding will take place. :param include_empty: Set to `False` if you don't want empty values to appear in the dict. :param errors: the decoding error behavior. :param separator: the pair separator to be used, defaults to ``&`` :param cls: an optional dict class to use. If this is not specified or `None` the default :class:`MultiDict` is used. :param limit: the content length of the URL data. Not necessary if a limited stream is provided. .. versionchanged:: 2.0 The ``decode_keys`` and ``return_iterator`` parameters are deprecated and will be removed in Werkzeug 2.1. .. versionadded:: 0.8 r)make_chunk_iterNrrhrzD'return_iterator' is deprecated and will be removed in Werkzeug 2.1.r)Zwsgirrrrrrr) rrrrrrrrrr pair_iterdecoderrrrrurl_decode_streamgs(#   r)rrrrr+c csj|D]`}|sqt|}|d}||kr8||d\}}n|s>q|}|d}t|||t|||fVqdS)NrrrR)rrsr) rrrrpairrequalrrrrrrs  r)rr encode_keysrrrr+cCs6|dk rtjdtddt|d}|t||||S)aURL encode a dict/`MultiDict`. If a value is `None` it will not appear in the result string. Per default only values are encoded into the target charset strings. :param obj: the object to encode into a query string. :param charset: the charset of the query string. :param sort: set to `True` if you want parameters to be sorted by `key`. :param separator: the separator to be used for the pairs. :param key: an optional function to be used for sorting. For more details check out the :func:`sorted` documentation. .. versionchanged:: 2.0 The ``encode_keys`` parameter is deprecated and will be removed in Werkzeug 2.1. .. versionchanged:: 0.5 Added the ``sort``, ``key``, and ``separator`` parameters. N@'encode_keys' is deprecated and will be removed in Werkzeug 2.1.rhrr )rrrrrPr)rrrrrrrrr url_encodes r )rrrrrrrr+c Csj|dk rtjdtddt|d}t||||}|dkr<|St|D] \}} |rZ|||| qDdS)aLike :meth:`url_encode` but writes the results to a stream object. If the stream is `None` a generator over all encoded pairs is returned. :param obj: the object to encode into a query string. :param stream: a stream to write the encoded object into or `None` if an iterator over the encoded pairs should be returned. In that case the separator argument is ignored. :param charset: the charset of the query string. :param sort: set to `True` if you want parameters to be sorted by `key`. :param separator: the separator to be used for the pairs. :param key: an optional function to be used for sorting. For more details check out the :func:`sorted` documentation. .. versionchanged:: 2.0 The ``encode_keys`` parameter is deprecated and will be removed in Werkzeug 2.1. .. versionadded:: 0.8 Nr rhrr )rrrrr enumeratewrite) rrrrrrrgenr|chunkrrrurl_encode_streams   r)baserrr+cst|trt|}t|tr$t|}t||ft||s@|S|sH|St||d\}}}}}t|||\}} } } } ||kr|S| rt|| | | | fS|} | dddkr| d} n@| s|d} | s|} n$|ddd| d} | ddkrd| d<fdd | D} d}t| d}||kr| |d kr| |ddd fkr| |d|d=q.|d7}q>qq.dd g}| dd |kr| d=qd| } t|| | | | fS) a Join a base URL and a possibly relative URL to form an absolute interpretation of the latter. :param base: the base URL for the join operation. :param url: the URL to join. :param allow_fragments: indicates whether fragments should be allowed. )rNrrg.rRcsg|]}|dkr|qS)rr)rsegmentrrrr?s zurl_join..z..rh) r7rrQrrrNrsrtrP)rrrbschemebnetlocbpathbquery bfragmentrrrrrsegmentsrnZunwanted_markerrrrrO sV   $   0  rOc@s*eZdZdZd ddZdd Zd d ZdS) HrefanImplements a callable that constructs URLs with the given base. The function can be called with any number of positional and keyword arguments which than are used to assemble the URL. Works with URLs and posix paths. Positional arguments are appended as individual segments to the path of the URL: >>> href = Href('/foo') >>> href('bar', 23) '/foo/bar/23' >>> href('foo', bar=23) '/foo/foo?bar=23' If any of the arguments (positional or keyword) evaluates to `None` it will be skipped. If no keyword arguments are given the last argument can be a :class:`dict` or :class:`MultiDict` (or any other dict subclass), otherwise the keyword arguments are used for the query parameters, cutting off the first trailing underscore of the parameter name: >>> href(is_=42) '/foo?is=42' >>> href({'foo': 'bar'}) '/foo?foo=bar' Combining of both methods is not allowed: >>> href({'foo': 'bar'}, bar=42) Traceback (most recent call last): ... TypeError: keyword arguments and query-dicts can't be combined Accessing attributes on the href object creates a new href object with the attribute name as prefix: >>> bar_href = href.bar >>> bar_href("blub") '/foo/bar/blub' If `sort` is set to `True` the items are sorted by `key` or the default sorting algorithm: >>> href = Href("/", sort=True) >>> href(a=1, b=2, c=3) '/?a=1&b=2&c=3' .. deprecated:: 2.0 Will be removed in Werkzeug 2.1. Use :mod:`werkzeug.routing` instead. .. versionadded:: 0.5 `sort` and `key` were added. ./rVFNcCs4tjdtdd|sd}||_||_||_||_dS)NzY'Href' is deprecated and will be removed in Werkzeug 2.1. Use 'werkzeug.routing' instead.rhrr)rrrrrrr)r/rrrrrrr__init__sz Href.__init__cCsP|dddkrt||j}|dddkr6|d7}tt|||j|j|jS)Nrh__rrg)AttributeErrorrrrOrrr)r/rnrrrr __getattr__s zHref.__getattr__c s|r6t|dtr6|rtd|d|dd}}n|rLdd|D}dfdd|Dd}j}|r|ds|d7}t|d|}|r|d t t |j j j d d 7}|S) Nrz3keyword arguments and query-dicts can't be combinedcSs,i|]$\}}|dr"|ddn||qS)ryNr)endswith)rkvrrrrsz!Href.__call__..rgcs&g|]}|dk rtt|jdqS)Nr )rrZr)rxr.rrrsz!Href.__call__..rr)rrr )r7dictr=rrPrrrr!rOrr rrr)r/rrr:rr.r__call__s0  z Href.__call__)rrVFN)r r!r"r~rr r&rrrrrTs7 r)rR)rR)NT)rVrWrrR)rVrWrrR)rVrWrR)rVr3rR)rVr3)rV)rVr)rVrWF)rVNTr3rN)rVNTr3rNNF)rVNFNr)NrVNFNr)T)Pr~codecsrmretypingrr _internalrrrrr TYPE_CHECKINGrRrZdscompilerrrrr rrr NamedTuplerr%rrrDict FrozenSetrrr$Unionr#rMappingIterablerboolrCallablerIteratorrrCrNrrrrrZrrQrlrrrPrr8rregister_errorr`rr^AnyStrTyperKBinaryIOrrr TextIOrrOrrrrrs        ,  "&   4        $ !      # D 6 @  &  &&   1 G