Your IP : 3.148.108.174


Current Path : /usr/lib/python3.6/site-packages/dns/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/dns/__pycache__/rdata.cpython-36.pyc

3

�b�W�:�@s�dZddlmZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlm
Z
mZmZdZefdd�ZdZefd	d
�Zed�Zdd
�Zdd�ZGdd�de�ZGdd�de�ZiZdZdd�Zddd�Zddd�ZdS)a�DNS rdata.

@var _rdata_modules: A dictionary mapping a (rdclass, rdtype) tuple to
the module which implements that type.
@type _rdata_modules: dict
@var _module_prefix: The prefix to use when forming modules names.  The
default is 'dns.rdtypes'.  Changing this value will break the library.
@type _module_prefix: string
@var _hex_chunk: At most this many octets that will be represented in each
chunk of hexstring that _hexify() produces before whitespace occurs.
@type _hex_chunk: int�)�BytesION�)�xrange�string_types�	text_type� cs4tj|��dj��fdd�tdt����D��j�S)aConvert a binary string into its hex encoding, broken up into chunks
    of I{chunksize} characters separated by a space.

    @param data: the binary string
    @type data: string
    @param chunksize: the chunk size.  Default is L{dns.rdata._hex_chunksize}
    @rtype: string
    � csg|]}�||���qS�r	)�.0�i)�	chunksize�liner	�/usr/lib/python3.6/rdata.py�
<listcomp>6sz_hexify.<locals>.<listcomp>r)�binasciiZhexlify�join�range�len�decode)�datarr	)rr
r�_hexify+s

rcs4tj|��dj��fdd�tdt����D��j�S)a$Convert a binary string into its base64 encoding, broken up into chunks
    of I{chunksize} characters separated by a space.

    @param data: the binary string
    @type data: string
    @param chunksize: the chunk size.  Default is
    L{dns.rdata._base64_chunksize}
    @rtype: string
    rcsg|]}�||���qSr	r	)r
r)rr
r	rrIsz_base64ify.<locals>.<listcomp>r)�base64Z	b64encoderrrr)rrr	)rr
r�
_base64ify=s
rs"\cCs~t|t�r|j�}t|t�s$t|�}d}xP|D]H}|tkrL|dt|�7}q.|dkrj|dkrj|t|�7}q.|d|7}q.W|S)z�Escape the characters in a quoted string which need it.

    @param qstring: the string
    @type qstring: string
    @returns: the escaped string
    @rtype: string
    ��\r�z\%03d)�
isinstancer�encode�	bytearray�	__escaped�chr)Zqstring�text�cr	r	r�	_escapifyOs	


r#cCsFx8tt|�ddd�D] }||dkr|d|d�SqW|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.

    @param what: a string of octets representing a bitmap.
    @type what: string
    @rtype: string
    rr���r$)rr)Zwhatrr	r	r�_truncate_bitmaphs	r%c@s�eZdZdZddgZdd�Zdd�Zdd	�Zd.dd
�Zd/dd�Z	d0dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zed1d(d)��Zed2d*d+��Zd3d,d-�Zd
S)4�Rdataz(Base class for all DNS rdata types.
    �rdclass�rdtypecCs||_||_dS)z�Initialize an rdata.
        @param rdclass: The rdata class
        @type rdclass: int
        @param rdtype: The rdata type
        @type rdtype: int
        N)r'r()�selfr'r(r	r	r�__init__~szRdata.__init__cCstjjS)a_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).
        @rtype: int
        )�dns�	rdatatype�NONE)r)r	r	r�covers�s	zRdata.coverscCs|j�d>|jBS)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.
        @rtype: int
        �)r.r()r)r	r	r�extended_rdatatype�szRdata.extended_rdatatypeNTcKst�dS)z@Convert an rdata to text format.
        @rtype: string
        N)�NotImplementedError)r)�origin�
relativize�kwr	r	r�to_text�sz
Rdata.to_textcCst�dS)z@Convert an rdata to wire format.
        @rtype: string
        N)r1)r)�file�compressr2r	r	r�to_wire�sz
Rdata.to_wirecCst�}|j|d|�|j�S)zlConvert rdata to a format suitable for digesting in hashes.  This
        is also the DNSSEC canonical form.N)rr8�getvalue)r)r2�fr	r	r�
to_digestable�szRdata.to_digestablecCstjj|j|j|j��dS)z�Check that the current contents of the rdata's fields are
        valid.  If you change an rdata by assigning to its fields,
        it is a good idea to call validate() when you are done making
        changes.
        N)r+�rdata�	from_textr'r(r5)r)r	r	r�validate�szRdata.validatecCsf|j�}|tjjkrd}ndtjj|�d}dtjj|j�dtjj|j�|dt|�dS)Nr�(�)z<DNS � z rdata: �>)	r.r+r,r-r5�
rdataclassr'r(�str)r)r.Zctextr	r	r�__repr__�s
zRdata.__repr__cCs|j�S)N)r5)r)r	r	r�__str__�sz
Rdata.__str__cCs8|jtjj�}|jtjj�}||kr(dS||kr4dSdS)z�Compare an rdata with another rdata of the same rdtype and
        rdclass.  Return < 0 if self < other in the DNSSEC ordering,
        0 if self == other, and > 0 if self > other.
        rrr$)r;r+�name�root)r)�otherZourZtheirr	r	r�_cmp�sz
Rdata._cmpcCs8t|t�sdS|j|jks&|j|jkr*dS|j|�dkS)NFr)rr&r'r(rJ)r)rIr	r	r�__eq__�s

zRdata.__eq__cCs8t|t�sdS|j|jks&|j|jkr*dS|j|�dkS)NTr)rr&r'r(rJ)r)rIr	r	r�__ne__�s

zRdata.__ne__cCs6t|t�s$|j|jks$|j|jkr(tS|j|�dkS)Nr)rr&r'r(�NotImplementedrJ)r)rIr	r	r�__lt__�szRdata.__lt__cCs6t|t�s$|j|jks$|j|jkr(tS|j|�dkS)Nr)rr&r'r(rMrJ)r)rIr	r	r�__le__�szRdata.__le__cCs6t|t�s$|j|jks$|j|jkr(tS|j|�dkS)Nr)rr&r'r(rMrJ)r)rIr	r	r�__ge__�szRdata.__ge__cCs6t|t�s$|j|jks$|j|jkr(tS|j|�dkS)Nr)rr&r'r(rMrJ)r)rIr	r	r�__gt__�szRdata.__gt__cCst|jtjj��S)N)�hashr;r+rGrH)r)r	r	r�__hash__�szRdata.__hash__cCst�dS)a�Build an rdata object from text format.

        @param rdclass: The rdata class
        @type rdclass: int
        @param rdtype: The rdata type
        @type rdtype: int
        @param tok: The tokenizer
        @type tok: dns.tokenizer.Tokenizer
        @param origin: The origin to use for relative names
        @type origin: dns.name.Name
        @param relativize: should names be relativized?
        @type relativize: bool
        @rtype: dns.rdata.Rdata instance
        N)r1)�clsr'r(�tokr2r3r	r	rr=�szRdata.from_textcCst�dS)a<Build an rdata object from wire format

        @param rdclass: The rdata class
        @type rdclass: int
        @param rdtype: The rdata type
        @type rdtype: int
        @param wire: The wire-format message
        @type wire: string
        @param current: The offset in wire of the beginning of the rdata.
        @type current: int
        @param rdlen: The length of the wire-format rdata
        @type rdlen: int
        @param origin: The origin to use for relative names
        @type origin: dns.name.Name
        @rtype: dns.rdata.Rdata instance
        N)r1)rTr'r(�wire�current�rdlenr2r	r	r�	from_wireszRdata.from_wirecCsdS)zWConvert any domain names in the rdata to the specified
        relativization.
        Nr	)r)r2r3r	r	r�choose_relativity&szRdata.choose_relativity)NT)NN)N)NT)N)NT)�__name__�
__module__�__qualname__�__doc__�	__slots__r*r.r0r5r8r;r>rErFrJrKrLrNrOrPrQrS�classmethodr=rYrZr	r	r	rr&ws0	



r&csVeZdZdZdgZ�fdd�Zddd�Zedd	d
��Zddd�Z	edd
d��Z
�ZS)�GenericRdataz�Generate Rdata Class

    This class is used for rdata types for which we have no better
    implementation.  It implements the DNS "unknown RRs" scheme.
    rcstt|�j||�||_dS)N)�superrar*r)r)r'r(r)�	__class__r	rr*8szGenericRdata.__init__NTcKsdt|j�t|j�S)Nz\# %d )rrr)r)r2r3r4r	r	rr5<szGenericRdata.to_textcCs�|j�}|j�s|jdkr(tjjd��|j�}g}x&|j�}|j�rHP|j|jj	��q6Wdj
|�}	tj|	�}
t
|
�|kr�tjjd��||||
�S)Nz\#z$generic rdata does not start with \#�z'generic rdata hex data has wrong length)�get�
is_identifier�valuer+Z	exception�SyntaxErrorZget_intZ
is_eol_or_eof�appendrrrZ	unhexlifyr)rTr'r(rUr2r3�tokenZlengthZchunks�hexrr	r	rr=?s"

zGenericRdata.from_textcCs|j|j�dS)N)�writer)r)r6r7r2r	r	rr8SszGenericRdata.to_wirecCs|||||||��S)Nr	)rTr'r(rVrWrXr2r	r	rrYVszGenericRdata.from_wire)NT)NT)NN)N)r[r\r]r^r_r*r5r`r=r8rY�
__classcell__r	r	)rcrra.s

razdns.rdtypescCs�dd�}tj||f�}tjj|�}tjj|�}|jdd�}|s�tjtjj|f�}|s�y$|djt	||g��}|t||f<WnVt
k
r�y(|djt	d|g��}|ttjj|f<Wnt
k
r�d}YnXYnX|r�t||�}nt}|S)NcSs6t|�}|jd�}x|dd�D]}t||�}q W|S)N�.r)�
__import__�split�getattr)rG�modZ
components�compr	r	r�
import_module`s

z&get_rdata_class.<locals>.import_module�-�_rn�ANY)
�_rdata_modulesrer+rCr5r,�replacerwr�_module_prefix�ImportErrorrqra)r'r(rtrrZrdclass_textZrdtype_textrTr	r	r�get_rdata_class^s.r|TcCs�t|t�rtjj|�}t||�}|tkrx|j�}|j|�|j	�rx|j
dkrxtj|||||�}t|||j
dt|j
�|�S|j|||||�S)adBuild 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 I{tok} is a string, then a tokenizer is created and the string
    is used as its input.

    @param rdclass: The rdata class
    @type rdclass: int
    @param rdtype: The rdata type
    @type rdtype: int
    @param tok: The tokenizer or input text
    @type tok: dns.tokenizer.Tokenizer or string
    @param origin: The origin to use for relative names
    @type origin: dns.name.Name
    @param relativize: Should names be relativized?
    @type relativize: bool
    @rtype: dns.rdata.Rdata instancez\#r)rrr+Z	tokenizer�	Tokenizerr|rareZungetrfrgr=rYrr)r'r(rUr2r3rTrjr<r	r	rr=�s



r=cCs*tjj|�}t||�}|j||||||�S)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.

    @param rdclass: The rdata class
    @type rdclass: int
    @param rdtype: The rdata type
    @type rdtype: int
    @param wire: The wire-format message
    @type wire: string
    @param current: The offset in wire of the beginning of the rdata.
    @type current: int
    @param rdlen: The length of the wire-format rdata
    @type rdlen: int
    @param origin: The origin to use for relative names
    @type origin: dns.name.Name
    @rtype: dns.rdata.Rdata instance)r+ZwiredataZ
maybe_wrapr|rY)r'r(rVrWrXr2rTr	r	rrY�s
rY)NT)N) r^�iorrrZ
dns.exceptionr+Zdns.nameZdns.rdataclassZ
dns.rdatatypeZ
dns.tokenizerZdns.wiredataZ_compatrrrZ_hex_chunksizerZ_base64_chunksizerrrr#r%�objectr&rarxrzr|r=rYr	r	r	r�<module>s28,"
/

?>