o xg$@sJddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z Gddde Z d1d d ZedeeeejejejfZd dZd1ddZd1ddZd1ddZd1ddZd1ddZddZgdeddeddgZd d!eDZd"Ze d#d!ed$dDd%d&Z!d'd(Z"d)d*Z#d+d,Z$d-d.Z%d/d0Z&e&Z'dS)2N)Decimalquote)RemovedInDjango40Warning)Promisecs(eZdZfddZfddZZS)DjangoUnicodeDecodeErrorcs||_tj|dS)N)objsuper__init__)selfrargs __class__7/usr/lib/python3/dist-packages/django/utils/encoding.pyr sz!DjangoUnicodeDecodeError.__init__csdt|jt|jfS)Nz%s. You passed in %r (%s))r __str__rtype)r r rrrsz DjangoUnicodeDecodeError.__str__)__name__ __module__ __qualname__r r __classcell__rrr rr s rutf-8FstrictcCt|tr|St||||S)z Return a string representing 's'. Treat bytestrings using the 'encoding' codec. If strings_only is True, don't convert (some) non-string-like objects. ) isinstancer force_strsencoding strings_onlyerrorsrrr smart_strs r!cCs t|tS)zDetermine if the object instance is of a protected type. Objects of protected types are preserved as-is when passed to force_str(strings_only=True). )r_PROTECTED_TYPES)rrrris_protected_type's r#c Csxtt|tr |S|rt|r|Szt|tr t|||}W|St|}W|Sty;}z t|g|jRd}~ww)z Similar to smart_str(), except that lazy instances are resolved to strings, rather than kept as lazy objects. If strings_only is True, don't convert (some) non-string-like objects. N) issubclassrstrr#rbytesUnicodeDecodeErrorrr )rrrr errrr0s   rcCr)z Return a bytestring version of 's', encoded as specified in 'encoding'. If strings_only is True, don't convert (some) non-string-like objects. )rr force_bytesrrrr smart_bytesFs r*cCs\t|tr|dkr |S|d|||S|rt|r|St|tr&t|St|||S)z Similar to smart_bytes, except that lazy instances are resolved to strings, rather than kept as lazy objects. If strings_only is True, don't convert (some) non-string-like objects. r)rr&decodeencoder# memoryviewr%rrrrr)Rs   r)cCtjdtddt||||S)Nz3smart_text() is deprecated in favor of smart_str(). stacklevel)warningswarnrr!rrrr smart_textf r4cCr.)Nz3force_text() is deprecated in favor of force_str().r/r0)r2r3rrrrrr force_textnr5r6cCs*|dur|St|trt|}t|ddS)u Convert an Internationalized Resource Identifier (IRI) portion to a URI portion that is suitable for inclusion in a URL. This is the algorithm from section 3.1 of RFC 3987, slightly simplified since the input is assumed to be a string rather than an arbitrary byte stream. Take an IRI (string or UTF-8 bytes, e.g. '/I ♥ Django/' or b'/I ♥ Django/') and return a string containing the encoded result with ASCII chars only (e.g. '/I%20%E2%99%A5%20Django/'). Nz/#%[]=:;$&()+,!?*@'~safe)rrr%r)irirrr iri_to_urivs   r:)-._~A[a{cCs4i|]}|D]}dD] }||t|fq qqS))z%02xz%02X)r,r&).0 ascii_rangecharfmtrrr s rG0123456789ABCDEFabcdefcCs.i|]}tD]}||t||qqSr)_hexdigr,r&fromhex)rCabrrrrGs cCs|dur|St|}|d}t|dkr|}n=|dg}|j}t}|ddD]'}|dd}||vrG|||dd||ddq(|d||q(d|}t|S)uL Convert a Uniform Resource Identifier(URI) into an Internationalized Resource Identifier(IRI). This is the algorithm from section 3.2 of RFC 3987, excluding step 4. Take an URI in ASCII bytes (e.g. '/I%20%E2%99%A5%20Django/') and return a string containing the encoded result (e.g. '/I%20♥%20Django/'). N%rr/)r)splitlenappend _hextobytejoinrepercent_broken_unicoder+)uribitsr9partsrS hextobyteitemhexrrr uri_to_iris$        r]cCs t|ddS)zh Escape the unsafe characters from the path portion of a Uniform Resource Identifier (URI). z/:@&+$,-_.!~*'()r7rpathrrrescape_uri_paths r`cCs|ddS)z:Return the Punycode of the given domain if it's non-ASCII.idnaascii)r,r+)domainrrrpunycodesrdc Csg} z|Wn3ty<}z't||j|jdd}||d|j|||jd}WYd}~n d}~wwd||Sq)z As per section 3.2 of RFC 3987, step three of converting a URI into an IRI, repercent-encode any octet produced that is not part of a strictly legal UTF-8 octet sequence. Ts/#%[]=:;$&()+,!?*@'~r7NrP)r+r'rstartendrSr,rU)r_ changed_partsr( repercentrrrrVs rVcCs$|dur|Stt|ddddS)aAConvert a file system path to a URI portion that is suitable for inclusion in a URL. Encode certain chars that would normally be recognized as special chars for URIs. Do not encode the ' character, as it is a valid character within URIs. See the encodeURIComponent() JavaScript function for details. N\/z/~!*()'r7)rr%replacer^rrrfilepath_to_urisrlcCs:ztdpd}t|W|Styd}Y|Sw)z The encoding of the default system locale. Fallback to 'ascii' if the #encoding is unsupported by Python or could not be determined. See tickets #10335 and #5846. rOrb)localegetdefaultlocalecodecslookup Exception)rrrrget_system_encodings  rr)rFr)(rodatetimermr2decimalr urllib.parserdjango.utils.deprecationrdjango.utils.functionalrr'rr!rintfloatdatetimer"r#rr*r)r4r6r:range _ascii_rangesrTrIupdater]r`rdrVrlrrDEFAULT_LOCALE_ENCODINGrrrrsD        "  $