관리-도구
편집 파일: rdata.cpython-39.opt-1.pyc
a �����M�es������������������� ���@���s~��U�d�Z�ddlZddlZddlZddlZddlZddlZddlmZ�ddl m Z mZmZm Z mZ�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZdZdZG�dd��dejj�Zed fd d�Zed fdd �Z ed fdd�Z!dZ"dd��Z#dd��Z$ej%j&Z'ej%j%G�dd��d��Z(ej%j%G�dd��de(��Z)i�Z*ee ej+j,ej-j.f�e f�e/d<�dZ0dd��Z1d,eej+j,e2f�eej-j.e2f�eej3j4e2f�eej5j6�e7eej5j6�eej5j8�e(d�dd�Z9d-eej+j,e2f�eej-j.e2f�ej:j;eej5j6�e(d �d!d"�Z<d.eej+j,e2f�eej-j.e2f�e=e>e>eej5j6�e(d#�d$d%�Z?G�d&d'��d'ejj�Z@d(ej+jAfe e>e2e7ej+j,dd)�d*d+�ZBdS�)/z DNS rdata.�����N)� import_module)�Any�Dict�Optional�Tuple�Union� ���Tc�������������������@���s���e�Zd�ZdZdS�)�NoRelativeRdataOrderingz�An attempt was made to do an ordered comparison of one or more rdata with relative names. The only reliable way of sorting rdata is to use non-relativized rdata. N)�__name__� __module__�__qualname__�__doc__��r���r����-/usr/lib/python3.9/site-packages/dns/rdata.pyr ���3���s���r ������� c��������������������s6�����s�����S�|����fdd�tdt�����D�������S�)zXBreak a binary string into chunks of chunksize characters separated by a space. c��������������������s���g�|�]}�||������qS�r���r���)�.0�i�� chunksize�datar���r���� <listcomp>C��������z_wordbreak.<locals>.<listcomp>r���)�decode�join�range�len)r���r���� separatorr���r���r���� _wordbreak;���s �����r���c�����������������K���s���t�t�|��||�S�)zConvert a binary string into its hex encoding, broken up into chunks of chunksize characters separated by a separator. )r����binasciiZhexlify�r���r���r����kwr���r���r����_hexifyJ���s����r!���c�����������������K���s���t�t�|��||�S�)z�Convert a binary string into its base64 encoding, broken up into chunks of chunksize characters separated by a separator. )r����base64Z b64encoder���r���r���r���� _base64ifyR���s����r#���s���"\c�����������������C���sz���t�|�t�r|����}�t�|�t�s$t|��}�d}|�D�]H}|tv�rJ|dt|��7�}q,|dkrh|dk�rh|t|�7�}q,|d|�7�}q,|S�)z7Escape the characters in a quoted string which need it.���\r�������z\%03d)� isinstance�str�encode� bytearray� __escaped�chr)Zqstring�text�cr���r���r���� _escapify_���s���� r/���c�����������������C���sF���t�t|��d�dd�D�]$}|�|�dkr|�d|d�����S�q|�dd��S�)z�Determine the index of greatest byte that isn't all zeros, and return the bitmap that contains all the bytes less than that index. �������r���)r���r���)Zwhatr���r���r���r����_truncate_bitmapr���s����r2���c���������������� ���@���s���e�Zd�ZdZg�d�Zdd��Zdd��Zdd��Zd d ��Ze j jd�dd �Ze d�dd�Zd]ee jj�eeeef�ed�dd�Zd^ee�ee jj�ee jj�eed�dd�Zd_ee�ee jj�ee jj�eed�dd�Zd`ee jj�dd�dd�Zdaee jj�ed�dd �Zd!d"��Zd#d$��Zd%d&��Zd'd(��Z d)d*��Z!d+d,��Z"d-d.��Z#d/d0��Z$d1d2��Z%d3d4��Z&e'dbe j(j)e j je j*j+ee jj�eee jj�d�d5�d6d7��Z,e'dce j(j)e j je j-j.ee jj�d�d8�d9d:��Z/ed�d;�d<d=�Z0e'd>d?���Z1e'd@dA���Z2e'ddeeee �eedB�dCdD��Z3e'dEdF���Z4e'dGdH���Z5e'dIdJ���Z6e'dKdL���Z7e'dMdN���Z8e'dedOdP��Z9e'dQdR���Z:e'dSdT���Z;e'dUdV���Z<e'dWdX���Z=e'dYdZ���Z>e'd[d\���Z?dS�)f�Rdataz#Base class for all DNS rdata types.)�rdclass�rdtype� rdcommentc�����������������C���s"���|���|�|�_|��|�|�_d|�_dS�)z�Initialize an rdata. *rdclass*, an ``int`` is the rdataclass of the Rdata. *rdtype*, an ``int`` is the rdatatype of the Rdata. N)�_as_rdataclassr4���� _as_rdatatyper5���r6���)�selfr4���r5���r���r���r����__init__����s����zRdata.__init__c�����������������C���s���t�j�dd��|�jjD���S�)Nc�����������������s���s���|�]}t�|d�g��V��qdS�)� __slots__N)�getattr)r����clsr���r���r���� <genexpr>����s���z'Rdata._get_all_slots.<locals>.<genexpr>)� itertools�chain� from_iterable� __class__�__mro__�r9���r���r���r����_get_all_slots����s�����zRdata._get_all_slotsc�����������������C���s$���i�}|�����D�]}t|�|�||<�q|S��N)rE���r<���)r9����state�slotr���r���r����__getstate__����s���� zRdata.__getstate__c�����������������C���s<���|����D�]\}}t�|�||��qt|�d�s8t�|�dd���d�S�)Nr6���)�items�object�__setattr__�hasattr)r9���rG���rH����valr���r���r����__setstate__����s���� zRdata.__setstate__)�returnc�����������������C���s���t�jjS�)a���Return the type a Rdata covers. DNS SIG/RRSIG rdatas apply to a specific type; this type is returned by the covers() function. If the rdata type is not SIG or RRSIG, dns.rdatatype.NONE is returned. This is useful when creating rdatasets, allowing the rdataset to contain only RRSIGs of a particular type, e.g. RRSIG(NS). Returns a ``dns.rdatatype.RdataType``. )�dns� rdatatype�NONErD���r���r���r����covers����s����zRdata.coversc�����������������C���s���|�����d>�|�jB�S�)z�Return a 32-bit type value, the least significant 16 bits of which are the ordinary DNS type, and the upper 16 bits of which are the "covered" type, if any. Returns an ``int``. ����)rT���r5���rD���r���r���r����extended_rdatatype����s����zRdata.extended_rdatatypeNT��origin� relativizer ���rP���c�����������������K���s���t��dS�)zEConvert an rdata to text format. Returns a ``str``. N��NotImplementedError�r9���rX���rY���r ���r���r���r����to_text����s����z Rdata.to_textF)�file�compressrX����canonicalizerP���c�����������������C���s���t��d�S�rF���rZ����r9���r^���r_���rX���r`���r���r���r����_to_wire����s����zRdata._to_wirec�����������������C���s8���|r|���||||�S�t���}|���||||��|���S�dS�)zSConvert an rdata to wire format. Returns a ``bytes`` or ``None``. N)rb����io�BytesIO�getvalue)r9���r^���r_���rX���r`����fr���r���r����to_wire����s ����z Rdata.to_wirezdns.rdata.GenericRdata)rX���rP���c�����������������C���s���t�j�|�j|�j|�j|d��S�)zrCreates a dns.rdata.GenericRdata equivalent of this rdata. Returns a ``dns.rdata.GenericRdata``. )rX���)rQ����rdata�GenericRdatar4���r5���rg����r9���rX���r���r���r���� to_generic����s�����zRdata.to_genericc�����������������C���s���|�j�|dd�S�)z�Convert rdata to a format suitable for digesting in hashes. This is also the DNSSEC canonical form. Returns a ``bytes``. T)rX���r`���)rg���rj���r���r���r���� to_digestable����s����zRdata.to_digestablec�����������������C���sf���|�����}|tjjkrd}ndtj�|��d�}dtj�|�j��d�tj�|�j��|�d�t|���d�S�)Nr$����(�)z<DNS � z rdata: �>) rT���rQ���rR���rS���r]���� rdataclassr4���r5���r(���)r9���rT���Zctextr���r���r����__repr__��s(������������zRdata.__repr__c�����������������C���s���|�����S�rF���)r]���rD���r���r���r����__str__��s����z Rdata.__str__c�����������������C���s����z|�����}d}W�n,�tjjy<���tr4|���tjj�}d}Y�n0�z|����}d}W�n,�tjjyz���trr|��tjj�}d}Y�n0�tr�||kr�|r�dS�dS�n|s�|r�t�||kr�dS�||kr�dS�dS�dS�)a��Compare an rdata with another rdata of the same rdtype and rdclass. For rdata with only absolute names: Return < 0 if self < other in the DNSSEC ordering, 0 if self == other, and > 0 if self > other. For rdata with at least one relative names: The rdata sorts before any rdata with only absolute names. When compared with another relative rdata, all names are made absolute as if they were relative to the root, as the proper origin is not available. While this creates a stable ordering, it is NOT guaranteed to be the DNSSEC ordering. In the future, all ordering comparisons for rdata with relative names will be disallowed. FTr1���r0���r���N)rl���rQ����name�NeedAbsoluteNameOrOrigin�_allow_relative_comparisons�rootr ���)r9����other�our�our_relative�their�their_relativer���r���r����_cmp��s4���� z Rdata._cmpc�����������������C���s����t�|t�sdS�|�j|jks&|�j|jkr*dS�d}d}z|����}W�n(�tjjyf���|��tjj�}d}Y�n0�z|���}W�n(�tjjy����|�tjj�}d}Y�n0�||kr�dS�||kS�)NFT) r'���r3���r4���r5���rl���rQ���rt���ru���rw���)r9���rx���rz���r|���ry���r{���r���r���r����__eq__F��s&���� zRdata.__eq__c�����������������C���s6���t�|t�sdS�|�j|jks&|�j|jkr*dS�|��|��S�)NT)r'���r3���r4���r5���r~����r9���rx���r���r���r����__ne__[��s ���� zRdata.__ne__c�����������������C���s4���t�|t�r"|�j|jks"|�j|jkr&tS�|��|�dk�S��Nr����r'���r3���r4���r5����NotImplementedr}���r���r���r���r����__lt__b��s����� � �zRdata.__lt__c�����������������C���s4���t�|t�r"|�j|jks"|�j|jkr&tS�|��|�dkS�r����r����r���r���r���r����__le__k��s����� � �zRdata.__le__c�����������������C���s4���t�|t�r"|�j|jks"|�j|jkr&tS�|��|�dkS�r����r����r���r���r���r����__ge__t��s����� � �zRdata.__ge__c�����������������C���s4���t�|t�r"|�j|jks"|�j|jkr&tS�|��|�dkS�r����r����r���r���r���r����__gt__}��s����� � �zRdata.__gt__c�����������������C���s���t�|��tjj��S�rF���)�hashrl���rQ���rt���rw���rD���r���r���r����__hash__���s����zRdata.__hash__)r4���r5����tokrX���rY���� relativize_torP���c�����������������C���s���t��d�S�rF���rZ���)r=���r4���r5���r����rX���rY���r����r���r���r���� from_text���s���� zRdata.from_text�r4���r5����parserrX���rP���c�����������������C���s���t��d�S�rF���rZ����r=���r4���r5���r����rX���r���r���r����from_wire_parser���s����zRdata.from_wire_parser)�kwargsrP���c��������������������s����t���j�j}��D�]F}|dkr q||vr<td��jj|���|dv�rtd��jj|���q���fdd�|D��}�j|��}���d�j �}|dur�t �|d|��|S�)a��� Create a new Rdata instance based on the instance replace was invoked on. It is possible to pass different parameters to override the corresponding properties of the base Rdata. Any field specific to the Rdata type can be replaced, but the *rdtype* and *rdclass* fields cannot. Returns an instance of the same Rdata subclass as *self*. r6���z!'{}' object has no attribute '{}'�r4���r5���z$Cannot overwrite '{}' attribute '{}'c�����������������3���s ���|�]}����|t�|��V��qd�S�rF���)�getr<���)r����key�r����r9���r���r���r>������r���z Rdata.replace.<locals>.<genexpr>N)�inspectZ signaturer:���� parameters�AttributeError�formatrB���r ���r����r6���rK���rL���)r9���r����r����r�����argsZrdr6���r���r����r����replace���s,���� ���� z Rdata.replacec�����������������C���s���t�jj�|�S�rF���)rQ���rq���� RdataClass�make�r=����valuer���r���r���r7������s����zRdata._as_rdataclassc�����������������C���s���t�jj�|�S�rF���)rQ���rR���� RdataTyper����r����r���r���r���r8������s����zRdata._as_rdatatype)r����r)���� max_length�empty_okrP���c�����������������C���s|���|rt�|t�r|���}n,t�|t�r,t|�}nt�|t�r<|}ntd��|d�ur`t|�|kr`td��|sxt|�dkrxtd��|S�)Nz not bytesztoo longr���zempty bytes not allowed)r'���r(���r)���r*����bytes� ValueErrorr���)r=���r����r)���r����r����Zbvaluer���r���r���� _as_bytes���s���� zRdata._as_bytesc�����������������C���s0���t�|t�rtj�|�S�t�|tjj�s,td��|S�)Nz not a name)r'���r(���rQ���rt���r�����Namer����r����r���r���r����_as_name���s ���� zRdata._as_namec�����������������C���s.���t�|t�std��|dk�s"|dkr*td��|S�)N�not an integerr�������znot a uint8�r'����intr����r����r���r���r���� _as_uint8���s ���� zRdata._as_uint8c�����������������C���s.���t�|t�std��|dk�s"|dkr*td��|S�)Nr����r���i����znot a uint16r����r����r���r���r���� _as_uint16��s ���� zRdata._as_uint16c�����������������C���s.���t�|t�std��|dk�s"|dkr*td��|S�)Nr����r���l������znot a uint32r����r����r���r���r���� _as_uint32 ��s ���� zRdata._as_uint32c�����������������C���s.���t�|t�std��|dk�s"|dkr*td��|S�)Nr����r���l�������znot a uint48r����r����r���r���r���� _as_uint48��s ���� zRdata._as_uint48c�����������������C���sF���t�|t�std��|d�ur*||k�r*td��|d�urB||krBtd��|S�)Nr����zvalue too smallzvalue too larger����)r=���r����ZlowZhighr���r���r����_as_int��s���� z Rdata._as_intc�����������������C���s8���t�|t�rtj�|�S�t�|t�r,tj�|�S�td��d�S�)Nznot an IPv4 address)r'���r(���rQ���Zipv4r`���r����� inet_ntoar����r����r���r���r����_as_ipv4_address#��s ���� zRdata._as_ipv4_addressc�����������������C���s8���t�|t�rtj�|�S�t�|t�r,tj�|�S�td��d�S�)Nznot an IPv6 address)r'���r(���rQ���Zipv6r`���r����r����r����r����r���r���r����_as_ipv6_address,��s ���� zRdata._as_ipv6_addressc�����������������C���s���t�|t�r|S�td��d�S�)Nz not a boolean)r'����boolr����r����r���r���r����_as_bool5��s���� zRdata._as_boolc�����������������C���s>���t�|t�r|��|dtjj�S�t�|t�r2tj�|�S�td��d�S�)Nr���z not a TTL) r'���r����r����rQ���ZttlZMAX_TTLr(���r����r����r����r���r���r����_as_ttl<��s ���� z Rdata._as_ttlc��������������������s:���z��|�fW�S��t�y4���t��fdd�|D����Y�S�0�d�S�)Nc�����������������3���s���|�]}��|�V��qd�S�rF���r���)r����v��as_valuer���r���r>���N��r���z"Rdata._as_tuple.<locals>.<genexpr>)� Exception�tuple)r=���r����r����r���r����r���� _as_tupleE��s����zRdata._as_tuplec�����������������C���s���t�|�}t�|��|S�rF���)�list�randomZshuffle)r=����iterablerJ���r���r���r����_processing_orderR��s���� zRdata._processing_order)NT)NNF)NNNF)N)N)NTN)N)FNT)NN)@r ���r���r���r ���r;���r:���rE���rI���rO���rQ���rR���r����rT���r����rV���r���rt���r����r����r���r(���r���r]���ZCompressTyper����rb���rg���rk���rl���rr���rs���r}���r~���r����r����r����r����r����r�����classmethodrq���r����� tokenizer� Tokenizerr�����wire�Parserr����r����r7���r8���r����r����r����r����r����r����r����r����r����r����r����r����r����r���r���r���r���r3�������s������� ����� ������ ��� � / ���� ��� � 1 ����� r3���c�����������������������sr���e�Zd�ZdZdgZ��fdd�Zdeejj �e eee f�ed�dd �Zedd d��Zdd d�Zeddd��Z���ZS�)ri���z�Generic Rdata Class This class is used for rdata types for which we have no better implementation. It implements the DNS "unknown RRs" scheme. r���c��������������������s���t����||��||�_d�S�rF���)�superr:���r���)r9���r4���r5���r����rB���r���r���r:���c��s����zGenericRdata.__init__NTrW���c�����������������K���s ���dt�|�j��t|�jfi�|���S�)Nz\# %d )r���r���r!���r\���r���r���r���r]���g��s����zGenericRdata.to_textc�����������������C���sj���|����}|���r|jdkr&tj�d��|���}|�d����} t � | �} t| �|kr^tj�d��|�||| �S�)N�\#z$generic rdata does not start with \#Tz'generic rdata hex data has wrong length)r����� is_identifierr����rQ���� exception�SyntaxErrorZget_intZ!concatenate_remaining_identifiersr)���r���Z unhexlifyr���)r=���r4���r5���r����rX���rY���r�����token�length�hexr���r���r���r���r����o��s���� zGenericRdata.from_textFc�����������������C���s���|��|�j��d�S�rF���)�writer���ra���r���r���r���rb���}��s����zGenericRdata._to_wirec�����������������C���s���|�|||�����S�rF���)Z get_remainingr����r���r���r���r�������s����zGenericRdata.from_wire_parser)NT)NTN)NNF)N)r ���r���r���r ���r;���r:���r���rQ���rt���r����r����r���r(���r���r]���r����r����rb���r����� __classcell__r���r���r����r���ri���Y��s"������ ��� ri����_rdata_classeszdns.rdtypesc�����������������C���s����t��|�|f�}|s�t��tjj|f�}|s�tj�|��}tj�|�}|�dd�}z.td� t ||g��}t||�}|t�|�|f<�W�nd�ty����z>td� t d|g��}t||�}|t�tjj|f<�|t�|�|f<�W�n�ty����Y�n0�Y�n0�|s�t }|t�|�|f<�|S�)N�-�_�.�ANY)r����r����rQ���rR���r����rq���r]���r����r���r����_module_prefixr<����ImportErrorri���)r4���r5���r=���Zrdclass_text�rdtype_text�modr���r���r����get_rdata_class���s2����� r����)r4���r5���r����rX���rY���r����� idna_codecrP���c�������������� ���C���s6��t�|t�rtjj||d�}tjj�|��}�tjj �|�}t |�|�}tj�tjj ����d}|tkr�|���} |�| ��| ���r�| jdkr�t�|�|||||�} t|�|| jdt| j�|�}|���}|| jkr�tj� d��|du�r�|�|�|||||�}|���} | jdu�rt�|d| j��|W��d����S�1��s(0����Y��dS�)a3��Build an rdata object from text format. This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_text() class method is called with the parameters to this function. If *tok* is a ``str``, then a tokenizer is created and the string is used as its input. *rdclass*, a ``dns.rdataclass.RdataClass`` or ``str``, the rdataclass. *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype. *tok*, a ``dns.tokenizer.Tokenizer`` or a ``str``. *origin*, a ``dns.name.Name`` (or ``None``), the origin to use for relative names. *relativize*, a ``bool``. If true, name will be relativized. *relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use when relativizing names. If not set, the *origin* value will be used. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder to use if a tokenizer needs to be created. If ``None``, the default IDNA 2003 encoder/decoder is used. If a tokenizer is not created, then the codec associated with the tokenizer is the one that is used. Returns an instance of the chosen Rdata subclass. )r����Nr����r���z9compressed data in generic syntax form of known rdatatyper6���)r'���r(���rQ���r����r����rq���r����r����rR���r����r����r�����ExceptionWrapperr����ri���r����Zungetr����r����r����� from_wirer���r���rg���Zget_eol_as_tokenZcommentrK���rL���)r4���r5���r����rX���rY���r����r����r=���rh���r����ZgrdataZrwirer���r���r���r�������s<����- �� ��r����r����c�����������������C���sj���t�jj�|��}�t�jj�|�}t|�|�}t�j�t�jj �� �|� |�|||�W��d����S�1�s\0����Y��dS�)a��Build an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. *rdclass*, a ``dns.rdataclass.RdataClass`` or ``str``, the rdataclass. *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype. *parser*, a ``dns.wire.Parser``, the parser, which should be restricted to the rdata length. *origin*, a ``dns.name.Name`` (or ``None``). If not ``None``, then names will be relativized to this origin. Returns an instance of the chosen Rdata subclass. N)rQ���rq���r����r����rR���r����r����r����r����Z FormErrorr����)r4���r5���r����rX���r=���r���r���r���r������s ���� r����)r4���r5���r�����current�rdlenrX���rP���c�����������������C���sJ���t�j�||�}|�|���t|�|||�W��d����S�1�s<0����Y��dS�)a1��Build an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. *rdclass*, an ``int``, the rdataclass. *rdtype*, an ``int``, the rdatatype. *wire*, a ``bytes``, the wire-format message. *current*, an ``int``, the offset in wire of the beginning of the rdata. *rdlen*, an ``int``, the length of the wire-format rdata *origin*, a ``dns.name.Name`` (or ``None``). If not ``None``, then names will be relativized to this origin. Returns an instance of the chosen Rdata subclass. N)rQ���r����r����Zrestrict_tor����)r4���r5���r����r����r����rX���r����r���r���r���r����%��s����"r����c�������������������@���s���e�Zd�ZdZddhZdZdS�)�RdatatypeExistszDNS rdatatype already exists.r4���r5���zKThe rdata type with class {rdclass:d} and rdtype {rdtype:d} already exists.N)r ���r���r���r ���Zsupp_kwargsZfmtr���r���r���r���r����L��s����r����F)�implementationr5���r�����is_singletonr4���rP���c�����������������C���sf���t�jj�|�}t||�}|tks,t�j�|�r8t||d��t|�|� dd��t ||f<�t�j�|||��dS�)a���Dynamically register a module to handle an rdatatype. *implementation*, a module implementing the type in the usual dnspython way. *rdtype*, an ``int``, the rdatatype to register. *rdtype_text*, a ``str``, the textual form of the rdatatype. *is_singleton*, a ``bool``, indicating if the type is a singleton (i.e. RRsets of the type can have only one member.) *rdclass*, the rdataclass of the type, or ``dns.rdataclass.ANY`` if it applies to all classes. r����r����r����N)rQ���rR���r����r����r����ri���Zis_metatyper����r<���r����r����� register_type)r����r5���r����r����r4���Zexisting_clsr���r���r���r����V��s���� �r����)NTNN)N)N)Cr ���r"���r���r����rc���r?���r����� importlibr����typingr���r���r���r���r���Z dns.exceptionrQ���Z dns.immutableZdns.ipv4Zdns.ipv6Zdns.nameZdns.rdataclassZ dns.rdatatypeZ dns.tokenizerZdns.ttlZdns.wireZ _chunksizerv���r����ZDNSExceptionr ���r���r!���r#���r+���r/���r2���Z immutableZconstifyZ _constifyr3���ri���r����rq���r����rR���r�����__annotations__r����r����r(���r����r����rt���r����r����Z IDNACodecr����r����r����r����r����r����r����r�����INr����r���r���r���r����<module>���s���� ���Z,�" ����� �^�� �*�� �'��