grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a àMÒeŒã@sÌdZddlZddlmZmZmZddlZddlZej Z ej Z e e e dœdd„Ze e e dœdd „Ze e d œd d „Ze ed œd d„Ze ed œdd„Zdee e fee edœdd„Zdd„Ze e d œdd„ZdS)z*Generic Internet address helper functions.éN)ÚAnyÚOptionalÚTuple)ÚfamilyÚtextÚreturncCs2|tkrtj |¡S|tkr*tj |d¡St‚dS)aConvert the textual form of a network address into its binary form. *family* is an ``int``, the address family. *text* is a ``str``, the textual address. Raises ``NotImplementedError`` if the address family specified is not implemented. Returns a ``bytes``. TN)ÚAF_INETÚdnsÚipv4Ú inet_atonÚAF_INET6Úipv6ÚNotImplementedError)rr©rú,/usr/lib/python3.9/site-packages/dns/inet.pyÚ inet_pton!s  r)rÚaddressrcCs0|tkrtj |¡S|tkr(tj |¡St‚dS)a0Convert the binary form of a network address into its textual form. *family* is an ``int``, the address family. *address* is a ``bytes``, the network address in binary form. Raises ``NotImplementedError`` if the address family specified is not implemented. Returns a ``str``. N)rr r Z inet_ntoar r r)rrrrrÚ inet_ntop6s   r)rrc CsZztj |¡tWStyTztj |d¡tWYStyNt‚Yn0Yn0dS)zäDetermine the address family of a textual-form network address. *text*, a ``str``, the textual address. Raises ``ValueError`` if the address family cannot be determined from the input. Returns an ``int``. TN)r r r rÚ Exceptionr r Ú ValueError©rrrrÚaf_for_addressKs     rc Csrz"tj |¡d}|dko |dkWStylz tj |d¡d}|dkWYStyft‚Yn0Yn0dS)zÝIs the textual-form network address a multicast address? *text*, a ``str``, the textual address. Raises ``ValueError`` if the address family cannot be determined from the input. Returns a ``bool``. réàéïTéÿN)r r r rr r)rÚfirstrrrÚ is_multicastas   rc CsXztj |¡WdStyRztj |d¡WYdStyLYYdS0Yn0dS)z{Is the specified string an IPv4 or IPv6 address? *text*, a ``str``, the textual address. Returns a ``bool``. TFN)r r r rr rrrrÚ is_addressws   r)Ú high_tupleÚafrc Csâ|\}}|durt|ƒ}|tkr(||fS|tkrÐ| d¡}|dkrN||ddfS|d|…}||dd…}| ¡r‚||dt|ƒfSz||dt |¡fWStyÌtj }tj |||d�^�^}} }| YS0nt d|›�ƒ‚dS)aXGiven a "high-level" address tuple, i.e. an (address, port) return the appropriate "low-level" address tuple suitable for use in socket calls. If an *af* other than ``None`` is provided, it is assumed the address in the high-level tuple is valid and has that af. If af is ``None``, then af_for_address will be called. Nú%ré)Úflagsúunknown address family ) rrr ÚfindÚisdigitÚintÚsocketZif_nametoindexÚAttributeErrorZAI_NUMERICHOSTZ getaddrinfor) rrrÚportÚiZaddrpartZscopeZai_flagsÚ_ÚtuprrrÚlow_level_address_tupleŠs(      r-cCs.|tjkrdS|tjkrdStd|›�ƒ‚dS)z:Return the 'any' address for the specified address family.z0.0.0.0z::r#N)r'rr r)rrrrÚ any_for_af®s   r.c CsPztj |¡WStyJztj |¡WYStyDt‚Yn0Yn0dS)aVerify that *address* is a valid text form IPv4 or IPv6 address and return its canonical text form. IPv6 addresses with scopes are rejected. *text*, a ``str``, the address in textual form. Raises ``ValueError`` if the text is not valid. N)r r Ú canonicalizerr rrrrrr/·s  r/)N)Ú__doc__r'ÚtypingrrrZdns.ipv4r Zdns.ipv6rr r&ÚstrÚbytesrrrÚboolrrr-r.r/rrrrÚs$ÿþ $