3 ]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)uriNcsNeZdZdZfZdfdd ZddZddZedd d Z dd d Z 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|j||pd|pd|pd||}||_|S)zCreate a new IRIReference.N)superr __new__encoding)clsscheme authoritypathqueryfragmentr ref) __class__?/tmp/pip-build-el9acr48/urllib3/urllib3/packages/rfc3986/iri.pyr .s zIRIReference.__new__c Csv|}t|tr|j|}nLt|tsfy|jj|}Wn0tk rdtdjt|jt|jYnXt|t|kS)z"Compare this reference to another.z Unable to compare {0}() to {1}()) isinstancetuplerr from_string TypeErrorformattype__name__)selfotherZ other_refrrr__eq__;s   zIRIReference.__eq__cCstjj|jS)N)rZISUBAUTHORITY_MATCHERmatchr)rrrr_match_subauthorityKsz IRIReference._match_subauthoritycCsZtj||}tjj|j}||d|dtj|d|tj|d|tj|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_stringr Z split_irirrrrNs  zIRIReference.from_stringNcsj}|rdkr0tdkr$tjdfddd}jrZdjfddjjdD}jdk r|tj 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 encodingc sNtdd|DrJytj|jdddStjk rHtjjYnX|S)Ncss|]}t|dkVqdS)N)ord).0crrr ysz.idna_encoder..T)strict std3_rules)anyidnaencodelower IDNAErrorrZInvalidAuthorityr)name)rrr idna_encoderxs z)IRIReference.encode..idna_encoder.csg|]}tj|qSr)rr$)r)part)r4rr sz'IRIReference.encode..@:)rrrr )rr/rZMissingDependencyErrorhostjoinsplituserinforr&r portstrrZ URIReferencerrrr)rr4rr)r4rrr0as*   zIRIReference.encode)r )r )N) r __module__ __qualname____doc__slotsr r!r# classmethodrr0 __classcell__rr)rrr s   r )rC collectionsrr5rrrrrr/ ImportErrorZURI_COMPONENTSZURIMixinr rrrrs