B \Z@sdZddlmZddlmZddlmZddlmZddlmZddlmZy dd l Z Wne k rpd Z YnXGd d d ed ej ej Z d S) z?Module containing the implementation of the IRIReference class.) namedtuple)compat) exceptions)misc) normalizers)uriNcsNeZdZdZdZdfdd ZddZdd Zedd d Z dd dZ Z S) IRIReferenceaAImmutable object representing a parsed IRI Reference. Can be encoded into an URIReference object via the procedure specified in RFC 3987 Section 3.1 .. note:: The IRI submodule is a new interface and may possibly change in the future. Check for changes to the interface when upgrading. utf-8cs0tt|||pd|pd|pd||}||_|S)zCreate a new IRIReference.N)superr __new__encoding)clsscheme authoritypathqueryfragmentrref) __class__r ?/tmp/pip-build-uw_ogi45/urllib3/urllib3/packages/rfc3986/iri.pyr .s zIRIReference.__new__c Csv|}t|tr|j|}nLt|tsfy|j|}Wn0tk rdtdt|jt|jYnXt|t|kS)z"Compare this reference to another.z Unable to compare {0}() to {1}()) isinstancetuplerr from_string TypeErrorformattype__name__)selfotherZ other_refr r r__eq__;s   zIRIReference.__eq__cCstj|jS)N)rZISUBAUTHORITY_MATCHERmatchr)rr r r_match_subauthorityKsz IRIReference._match_subauthorityc CsZt||}tj|}||d|dt|d|t|d|t|d||S)a Parse a IRI reference from the given unicode IRI string. :param str iri_string: Unicode IRI to be parsed into a reference. :param str encoding: The encoding of the string provided :returns: :class:`IRIReference` or subclass thereof rrrrr)rto_strrZ IRI_MATCHERr" groupdictrencode_component)rZ iri_stringrZ split_irir r rrNs  zIRIReference.from_stringNcsj}|rdkr0tdkr$tdfddd}jrZdfddjdD}jdk r|t jj d |}j dk r|d t j 7}t jj|jjjj d S) aEncode an IRIReference into a URIReference instance. If the ``idna`` module is installed or the ``rfc3986[idna]`` extra is used then unicode characters in the IRI host component will be encoded with IDNA2008. :param idna_encoder: Function that encodes each part of the host component If not given will raise an exception if the IRI contains a host component. :rtype: uri.URIReference :returns: A URI reference NzICould not import the 'idna' module and the IRI hostname requires encodingcsNtdd|DrJytj|dddStjk rHtjYnX|S)Ncss|]}t|dkVqdS)N)ord).0cr r r ysz.idna_encoder..T)strict std3_rules)anyidnaencodelower IDNAErrorrZInvalidAuthorityr)name)rr r idna_encoderxs z)IRIReference.encode..idna_encoder.csg|]}t|qSr )rr$)r)part)r4r r sz'IRIReference.encode..@:)rrrr)rr/rZMissingDependencyErrorhostjoinsplituserinforr&rportstrrZ URIReferencerrrr)rr4rr )r4rrr0as*   zIRIReference.encode)r )r )N) r __module__ __qualname____doc__slotsr r!r# classmethodrr0 __classcell__r r )rrr s   r )rC collectionsrr5rrrrrr/ ImportErrorZURI_COMPONENTSZURIMixinr r r r rs