Your IP : 3.21.44.115


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

3

�Of�L�@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z
ddlZ
ddlZ
ddl
Z
ddlZ
ddlZ
ddlmZmZejd/kr�eZnejZejZGdd�de
jj�ZGd	d
�d
e
jj�Zdd�Zd
d�Zdd�Zdd�Z dd�Z!e"ed�r�ea#nea#dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(d0d"d#�Z)d$d%�Z*d&d'�Z+d(d)�Z,d1d*d+�Z-e
j.j/e
j0j1dd ddd,dddddd!e
j2j3fd-d.�Z4dS)2zTalk to a DNS server.�)�
generatorsN�)�long�string_types�c@seZdZdZdS)�UnexpectedSourcez=A DNS query response came from an unexpected address or port.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/query.pyr,src@seZdZdZdS)�BadResponsez<A DNS query response does not respond to the question asked.N)rr	r
rrrrr
r1srcCs|dkrdStj�|SdS)N)�time)�timeoutrrr
�_compute_expiration6srcCsjd}|r|tjO}|r |tjO}|r.|tjO}tj�}|j||�|rZ|jt|d��}n|j�}t|�S)aqPoll polling backend.
    @param fd: File descriptor
    @type fd: int
    @param readable: Whether to wait for readability
    @type readable: bool
    @param writable: Whether to wait for writability
    @type writable: bool
    @param timeout: Deadline timeout (expiration time, in seconds)
    @type timeout: float
    @return True on success, False on timeout
    ri�)�selectZPOLLINZPOLLOUTZPOLLERR�poll�registerr�bool)�fd�readable�writable�errorrZ
event_maskZpollableZ
event_listrrr
�	_poll_for=s


rcCsrggg}}}|r|g}|r$|g}|r.|g}|dkrLtj|||�\}}	}
ntj||||�\}}	}
t|pn|	pn|
�S)asSelect polling backend.
    @param fd: File descriptor
    @type fd: int
    @param readable: Whether to wait for readability
    @type readable: bool
    @param writable: Whether to wait for writability
    @type writable: bool
    @param timeout: Deadline timeout (expiration time, in seconds)
    @type timeout: float
    @return True on success, False on timeout
    N)rr)rrrrrZrsetZwsetZxsetZrcountZwcountZxcountrrr
�_select_for\srcCs�d}x�|s�|dkrd}n|tj�}|dkr4tjj�yt|||||�sNtjj�Wn6tk
r�}z|jdtjkrv|�WYdd}~XnXd}qWdS)NFgrT)	r�dns�	exceptionZTimeout�_polling_backend�select_error�args�errnoZEINTR)rrrr�
expiration�doner�errr
�	_wait_forysr%cCs|adS)z#
    Internal API. Do not use.
    N)r)�fnrrr
�_set_polling_backend�sr'rcCst|ddd|�dS)NTF)r%)�sr"rrr
�_wait_for_readable�sr)cCst|ddd|�dS)NFT)r%)r(r"rrr
�_wait_for_writable�sr*cCsDtjj||d�}tjj||d�}||koB|dd�|dd�kS)Nrr)r�inetZ	inet_pton)�afZa1Za2Zn1Zn2rrr
�_addresses_equal�sr-cCs`|sdSt|||�s<tjj|d�r@|dd�|dd�kr@dS|rHdStd|�d|����dS)NTrrFzgot a response from z instead of )r-rr+Zis_multicastr)r,�from_address�destination�ignore_unexpectedrrr
�_matches_destination�s(r1cCs�|dkr6ytjj|�}Wntk
r4tjj}YnX|tjjkrp||f}|dk	sZ|dkr�|dkrfd}||f}n@|tjjkr�||ddf}|dk	s�|dkr�|dkr�d}||ddf}|||fS)Nrz0.0.0.0z::)rr+Zaf_for_address�	ExceptionZAF_INETZAF_INET6)r,�where�port�source�source_portr/rrr
�_destination_and_source�s$
r7�5Fc
Cs"|j�}
t|||||�\}}}t|tjd�}d}
z�t|�}|jd�|dk	rV|j|�t||�t	j	�}
|j
|
|�x�t||�|jd�\}
}t
|j|||�s�qvt	j	�|
}y"tjj|
|j|j|d�}||_	Wntk
r�|	r�wvn�YnX|j|��r�|S|	�rqvqvt�qvWWd|j�XdS)a�Return the response obtained after sending a query via UDP.

    @param q: the query
    @type q: dns.message.Message
    @param where: where to send the message
    @type where: string containing an IPv4 or IPv6 address
    @param timeout: The number of seconds to wait before the query times out.
    If None, the default, wait forever.
    @type timeout: float
    @param port: The port to which to send the message.  The default is 53.
    @type port: int
    @param af: the address family to use.  The default is None, which
    causes the address family to use to be inferred from the form of where.
    If the inference attempt fails, AF_INET is used.
    @type af: int
    @rtype: dns.message.Message object
    @param source: source address.  The default is the wildcard address.
    @type source: string
    @param source_port: The port from which to send the message.
    The default is 0.
    @type source_port: int
    @param ignore_unexpected: If True, ignore responses from unexpected
    sources.  The default is False.
    @type ignore_unexpected: bool
    @param one_rr_per_rrset: Put each RR into its own RRset
    @type one_rr_per_rrset: bool
    rNi��)�keyring�request_mac�one_rr_per_rrset)�to_wirer7�socket_factory�socket�
SOCK_DGRAMr�setblocking�bindr*rZsendtor)�recvfromr1Zfamilyr�message�	from_wirer9�macr2�is_responser�close)�qr3rr4r,r5r6r0r;�
ignore_errors�wirer/r(�
begin_timer"r.�
response_time�rrrr
�udp�sD




rNcCsJd}x@|dkrDt||�|j|�}|dkr.t�|t|�}||}qW|S)z�Read the specified number of bytes from sock.  Keep trying until we
    either get the desired amount, or we hit EOF.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    �r)r)Zrecv�EOFError�len)�sock�countr"r(�nrrr
�	_net_reads


rUcCs>d}t|�}x,||kr8t||�||j||d��7}qWdS)z�Write the specified data to the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    rN)rQr*�send)rR�datar"Zcurrent�lrrr
�
_net_write/s


rYcCspy|j|�Wn\tjk
rjtj�dd�\}}t|d�rF|j}n|d}|tjtjtj	gkrf|�YnXdS)N�r!r)
Zconnectr>r�sys�exc_info�hasattrr!ZEINPROGRESSZEWOULDBLOCKZEALREADY)r(ZaddressZty�vZv_errrrr
�_connect;s
r_cCs|j�}t|||||�\}}	}t|tjd�}
d}z�t|�}|
jd�tj�}|dk	r^|
j|�t	|
|	�t
|�}
tjd|
�|}t
|
||�t|
d|�}tjd|�\}
t|
|
|�}Wd|dkr�d}ntj�|}|
j�Xtjj||j|j|d�}||_|j|��st�|S)aReturn the response obtained after sending a query via TCP.

    @param q: the query
    @type q: dns.message.Message object
    @param where: where to send the message
    @type where: string containing an IPv4 or IPv6 address
    @param timeout: The number of seconds to wait before the query times out.
    If None, the default, wait forever.
    @type timeout: float
    @param port: The port to which to send the message.  The default is 53.
    @type port: int
    @param af: the address family to use.  The default is None, which
    causes the address family to use to be inferred from the form of where.
    If the inference attempt fails, AF_INET is used.
    @type af: int
    @rtype: dns.message.Message object
    @param source: source address.  The default is the wildcard address.
    @type source: string
    @param source_port: The port from which to send the message.
    The default is 0.
    @type source_port: int
    @param one_rr_per_rrset: Put each RR into its own RRset
    @type one_rr_per_rrset: bool
    rNz!HrZ)r9r:r;)r<r7r=r>�SOCK_STREAMrr@rrAr_rQ�struct�packrYrU�unpackrGrrCrDr9rErFr)rHr3rr4r,r5r6r;rJr/r(rKr"rX�tcpmsg�ldatarLrMrrr
�tcpIs8



rfTc&cs�t|t�rtjj|�}t|t�r,tjj|�}tjj|||�}|tjjkrltj	j|dddd|
�}|j
j|�|dk	r�|j|||d�|j
�}t|	||||�\}	}}|r�|tjjkr�td��t|	tjd�}nt|	tjd�}|jd�|dk	r�|j|�t|
�}t||�t|�}|�r*t||�|j|�ntjd|�|}t|||�d	}d
}d	}d}|�rj|}tjj}nd}|}d}d
}�x6|�s�t|�} | dk�s�|dk	�r�| |k�r�|} |�r�t||�|j d�\}}!n&t!|d| �}"tj"d|"�\}t!||| �}|tjjk}#tjj#||j$|j%d
||d
||#d
�	}$|$j&}d	}d}%|dk�r�|$j'�sV|$j'dj|k�rbtj(j)d��|$j'd}|j*tjj+k�r�tj(j)d��d}%|j,�}|tjjk�r�|dj-|
k�r�d
}nd
}x�|$j'|%d�D]�}|�r�tj(j)d��|j*tjj+k�rl|j|k�rl|�r&|dj-|
k�r tj(j)d��d	}n|tjjk�r:|}||k�r~|tjj.k�sf|tjjk�r~|�r~d
}n|�r�tjj.}d	}�q�W|�r�|j$�r�|$j/�r�tj(j)d��|$V�q~W|j0�dS)a�Return a generator for the responses to a zone transfer.

    @param where: where to send the message
    @type where: string containing an IPv4 or IPv6 address
    @param zone: The name of the zone to transfer
    @type zone: dns.name.Name object or string
    @param rdtype: The type of zone transfer.  The default is
    dns.rdatatype.AXFR.
    @type rdtype: int or string
    @param rdclass: The class of the zone transfer.  The default is
    dns.rdataclass.IN.
    @type rdclass: int or string
    @param timeout: The number of seconds to wait for each response message.
    If None, the default, wait forever.
    @type timeout: float
    @param port: The port to which to send the message.  The default is 53.
    @type port: int
    @param keyring: The TSIG keyring to use
    @type keyring: dict
    @param keyname: The name of the TSIG key to use
    @type keyname: dns.name.Name object or string
    @param relativize: If True, all names in the zone will be relativized to
    the zone origin.  It is essential that the relativize setting matches
    the one specified to dns.zone.from_xfr().
    @type relativize: bool
    @param af: the address family to use.  The default is None, which
    causes the address family to use to be inferred from the form of where.
    If the inference attempt fails, AF_INET is used.
    @type af: int
    @param lifetime: The total number of seconds to spend doing the transfer.
    If None, the default, then there is no limit on the time the transfer may
    take.
    @type lifetime: float
    @rtype: generator of dns.message.Message objects.
    @param source: source address.  The default is the wildcard address.
    @type source: string
    @param source_port: The port from which to send the message.
    The default is 0.
    @type source_port: int
    @param serial: The SOA serial number to use as the base for an IXFR diff
    sequence (only meaningful if rdtype == dns.rdatatype.IXFR).
    @type serial: int
    @param use_udp: Use UDP (only meaningful for IXFR)
    @type use_udp: bool
    @param keyalgorithm: The TSIG algorithm to use; defaults to
    dns.tsig.default_algorithm
    @type keyalgorithm: string
    r�IN�SOAz. . %u 0 0 0 0N)�	algorithmzcannot do a UDP AXFRz!HFTi��rZ)r9r:�xfr�origin�tsig_ctxZmulti�firstr;z No answer or RRset not for qnamezfirst RRset is not an SOArzanswers after final SOAzIXFR base serial mismatchzmissing TSIG)1�
isinstancerr�nameZ	from_text�	rdatatyperCZ
make_queryZIXFR�rrsetZ	authority�appendZuse_tsigr<r7�
ValueErrorr=r>r?r`r@rArr_rQr*rVrarbrY�emptyr)rBrUrcrDr9rErlZanswerr�	FormError�rdtyperh�copy�serial�AXFRZhad_tsigrG)&r3ZzonervZrdclassrr4r9ZkeynameZ
relativizer,Zlifetimer5r6rxZuse_udpZkeyalgorithmrHrqrJr/r(r"rXrdr#Zdelete_modeZ
expecting_SOAZ	soa_rrsetrkZonamerlrmZmexpirationr.reZis_ixfrrMZanswer_indexrrr
rj�s�5














rj)r)Nr8NNrFFF)Nr8NNrF)5rZ
__future__rr!rr>rar[rZ
dns.exceptionrZdns.inetZdns.nameZdns.messageZdns.rdataclassZ
dns.rdatatypeZ_compatrr�version_info�OSErrorrrr=rZDNSExceptionrrurrrrr%r'r]rr)r*r-r1r7rNrUrYr_rfrpryZ
rdataclassrgZtsigZdefault_algorithmrjrrrr
�<module>sX

	
I
?



?>