U mÃfÈã@s¸dZddlZddlZddlmZmZddlZddlZe  d¡Z e e dœdd„Z e  d¡Ze  d ¡Ze  d ¡Zdee e fee d œd d„ZdZe edœdd„Zee e fe dœdd„ZdS)zIPv6 helper functions.éN)ÚListÚUnionz 0+([0-9a-f]+))ÚaddressÚreturncCs–t|ƒdkrtdƒ‚t |¡}g}d}t|ƒ}||krz|||d… ¡}t |¡}|dk rf| d¡}| |¡|d7}q.d}d}d} d} t d ƒD]B}||d krÈ| rÔ|} | | } | |krÂ| }| }d} q’| s’|} d } q’| röd } | | } | |krö| }| }|dkrˆ|dkrZ|d ks,|d krZ|d dkrZ|d krt| ƒ} | dkrÐtjj‚| dkrêdd| | } |  | ¡qp|d kr|stjj‚d | ¡}z t |¡WStjtfk rJtjj‚YnXdS)a+Convert an IPv6 address in text form to binary form. *text*, a ``str`` or ``bytes``, the IPv6 address in textual form. *ignore_scope*, a ``bool``. If ``True``, a scope will be ignored. If ``False``, the default, it is an error for a scope to be present. Returns a ``bytes``. ó%éróó:s::s0::Nz{}:{:02x}{:02x}:{:02x}{:02x}rér r FTs0000ró0)Ú isinstanceÚbytesÚencodeÚsplitrrÚ exceptionÚ SyntaxErrorÚendswithÚ startswithÚ _v4_endingrrÚ inet_atonrÚformatrÚ_colon_colon_startÚ_colon_colon_endrrrrÚ unhexlifyÚErrorÚ TypeError) r)r*ZbtextÚpartsr!r#ÚbrZ seen_emptyÚ canonicalÚcÚ_Úlcr'r'r(r:hsz         ÿÿ            r:s ÿÿcCs | t¡S)zŒIs the specified address a mapped IPv4 address? *address*, a ``bytes`` is an IPv6 address in binary form. Returns a ``bool``. )r8Ú_mapped_prefix)rr'r'r(Ú is_mappedÈsrH)r)rcCstj tj |¡¡S)aVerify that *address* is a valid text form IPv6 address and return its canonical text form. Addresses with scopes are rejected. *text*, a ``str`` or ``bytes``, the IPv6 address in textual form. Raises ``dns.exception.SyntaxError`` if the text is not valid. )rZipv6rr:)r)r'r'r(Ú canonicalizeÓsrI)F)Ú__doc__rÚreÚtypingrrZ dns.exceptionrZdns.ipv4Úcompilerr2Ústrrr9r<r=Úboolr:rGrHrIr'r'r'r(Ús E   ]