o
    heo                     @   s  d Z ddlZddlZddlmZmZmZmZmZm	Z	 ddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZG dd dejjZG dd dejjZdd	 ZeejjejjdB ejjdB edB e e!e e!f Z"d
d Z#G dd dZ$G dd dej%j&Z'G dd dej%j(Z)ddej*j+ej*j+dddejj,df	dedejje-B dB de dB dej*j.e-B dB dej*j.e-B dej/j0e-B dB de e-B dB dejj1dB dejje-B dB de!deej2j3 fddZ4dS ) z
DNS Zones.    N)AnyIterableListSetTuplecastc                   @      e Zd ZdZdS )UnknownOriginzUnknown originN__name__
__module____qualname____doc__ r   r   N/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/dns/zonefile.pyr	   &       r	   c                   @   r   )CNAMEAndOtherDataz!A node has a CNAME and other dataNr
   r   r   r   r   r   *   r   r   c                 C   s|   t jj|}| |}|d u rd S | }|t jjjkr(|t jjjkr(td|t jjjkr:|t jjjkr<tdd S d S )Nz1rdataset type is not compatible with a CNAME nodez9CNAME rdataset is not compatible with a regular data node)	dnsnodeNodeKindclassify_rdatasetget_nodeclassifyCNAMEREGULARr   )txnnamerdatasetrdataset_kindr   	node_kindr   r   r   _check_cname_and_other_data.   s   
r    c                 C   s   |   } | dsd|  } | S )N$)upper
startswith)sr   r   r   _upper_dollarizeQ   s   
r%   c                   @   s   e Zd ZdZ							ddejjdejjdej	j
ded	eee B d
ejjdB dedB dejjdB dejjdB dedB fddZdd Zdd Zdd Zdedeeeeeef fddZdd Zd ddZdS )!Readerz(Read a DNS zone file into a transaction.FTNtokrdclassr   allow_includeallow_directives
force_name	force_ttlforce_rdclassforce_rdtypedefault_ttlc                 C   s   || _ |j \| _| _}| j| _d| _d| _|d ur|}
|
d u r(d| _d| _	n|
| _d| _	| j| _
|| _|| _g | _d | _|  |du rRh d| _|rQ| jd n|du r[t | _n
tdd |D | _|| _|| _|| _|	| _| jt d S )Nr   FT>   $TTL$ORIGIN	$GENERATE$INCLUDEc                 s   s    | ]}t |V  qd S N)r%   ).0dr   r   r   	<genexpr>   s    z"Reader.__init__.<locals>.<genexpr>)r'   managerorigin_informationzone_origin
relativizecurrent_originlast_ttllast_ttl_knownr/   default_ttl_known	last_namezone_rdclassr   saved_statecurrent_fileallowed_directivesaddsetr+   r,   r-   r.   check_put_rdatasetr    )selfr'   r(   r   r)   r*   r+   r,   r-   r.   r/   _r   r   r   __init__[   s>   

zReader.__init__c                 C   s   	 | j  }| rd S qr4   )r'   getis_eol_or_eofrH   tokenr   r   r   	_eat_line   s
   
zReader._eat_linec                 C   s   | j  }| stjj|S r4   )r'   rK   is_identifierr   	exceptionSyntaxErrorrM   r   r   r   _get_identifier   s   
zReader._get_identifierc           
   
   C   sj  d}| j dur| j }nV| jdu rt| jjdd}| s'| j|| j| _n| j }| r2dS | j	| | j}|du rEt
jd| jdusLJ || jsX|   dS | jra|| j}| jdurp| j}|| _d| _n)|  }d}zt
j|j}|| _d| _d}W n t
jjy   | j	| Y nw | jdur| j}n4|  }z	t
j|j}W n t
jjy     ty   | j}| j	| Y nw || jkrt
jd|du r|  }d}zt
j|j}|| _d| _d}W n! t
jjy   | jr| j}n| jr| j}| j	| Y nw | jdur| j}n!|  }z	t
j |j}W n ty>   t
jd|j dw zt
j!||| j| j| j| j}W n, t
jjy[     ty|   t"# dd \}}t
jd	t$| d
t$| w | js|t
j j%krt&t
j'j(j%j%|}	|	j)| _d| _|du r|	j)}|du rt
jd| j*+||| dS )z&Process one line from a DNS zone file.NT)want_leadingzthe last used name is undefinedRR class is not zone's classunknown rdatatype ''   caught exception : Missing default TTL value),r+   r<   r	   r'   rK   is_whitespaceas_namer@   rL   ungetr   rQ   rR   r:   is_subdomainrO   r;   r,   r=   r>   rS   ttl	from_textvalueBadTTLr-   
rdataclass	ExceptionrA   r?   r/   r.   	rdatatyperdatasysexc_infostrSOAr   rdtypesANYminimumr   rE   )
rH   rN   r   r`   r(   rdtyperdtyvasoa_rdr   r   r   _rr_line   s   






 	

zReader._rr_linesidereturnc                 C   s  t d}t d}t d}d}d}d}d}d}	||}
|
r0|
 \}}}}}	|dkr/d}n0||}|rI| \}}}|dkrDd}d}d}	n||}|r`| \}}}}|dkr^d}d}	t|}t|}|dvrutjd	| |	d
vrtjd|	 |||||	fS )Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$ +0r6   )rx   -zinvalid offset sign )r6   oxXnNzinvalid type )recompilematchgroupsintr   rQ   rR   )rH   ru   is_generate1is_generate2is_generate3modsignoffsetwidthbaseg1g2g3ioffsetiwidthr   r   r   _parse_modify  sD   





zReader._parse_modifyc                    s  | j du rt| j }ztj|j\}}}| j }| s$tj	j
W n ty0   tj	j
w z|j}| j }| sBtj	j
W n tyN   tj	j
w ztj|j}|| _d| _| j }| sjtj	j
W n+ tjjy   | js| jstj	
d| jr| j}n| jr| j}ntj	
dY nw ztj|j}| j }| stj	j
W n tj	j
y   tj	j
 ty   | j}Y nw || jkrtj	
dztj|j}| j }| stj	j
W n ty   tj	
d|j dw |j}	dtdtd	td
tfdd}
dtdtdtd
tf fdd | |\}}}}}| |	\}}}}}t||d |D ]}|
|||}|
|||} |||} |||}|d| |}|	d| |}tj|| j | jj| _| j}| jdusxJ || js|    dS | j r| | j}ztj!|||| j | j | j}W n, tj	j
y     ty   t"# dd \}}tj	
dt| dt| w | j$%||| q5dS )zPProcess one line containing the GENERATE statement from a DNS
        zone file.NTr[   rU   rV   rW   counteroffset_signr   rv   c                 S   s   |dkr|d9 }| | S )z0Calculate the index from the counter and offset.rz   r   )r   r   r   r   r   r   _calculate_index  s   z/Reader._generate_line.<locals>._calculate_indexindexr   r   c                    sT   |dv rt | ||S  | d|}d|ddd d| }|dkr(| }|S )zVFormat the index with the given base, and zero-fill it
            to the given width.)r6   r{   r|   r}   r|   .Nr   r   )formatzfilljoinr"   )r   r   r   hexanibbles_format_indexr   r   r     s   z,Reader._generate_line.<locals>._format_index   r!   rX   rY   rZ   )&r<   r	   r'   rK   r   grangera   rb   rP   rQ   rR   re   r`   r=   r>   rc   r?   r/   rd   rA   rf   r   rj   r   rangereplacer   
idna_codecr@   r:   r_   rO   r;   rg   rh   ri   r   rE   )rH   rN   startstopsteplhsr`   r(   ro   rhsr   lmodlsignloffsetlwidthlbasermodrsignroffsetrwidthrbaseilindexrindexlzfindexrzfindexr   rg   rp   rq   rr   r   r   r   _generate_lineB  s   








zReader._generate_linec           	   
   C   s  z-	 | j dd}| r9| jdur| j  t| jdkr6| jd\| _ | _| _	| _| _
| _| _| _qW dS | r>q| rH| j   q|jd dkr$t| jdkr$|j }|| jvrltjd| d|d	kr| j  }| stjd
tj|j| _d| _| j   n|dkr| j  | _| j   | jdu r| j| _| j| j ns|dkr| j  }|j}| j  }| rtj|j| j| j j}| j   n|  stjd| j}| j!| j | j| j	| j| j
| j| j| jf t"|dd| _tj#$| j|| _ || _n|dkr| %  n
tjd| dq| j &| | '  q tjjye } z(| j ( \}}|du rGd}tj| d| d| }t)* d }|+|dd}~ww )zRead a DNS zone file and build a zone object.

        @raises dns.zone.NoSOA: No SOA RR was found at the zone origin
        @raises dns.zone.NoNS: No NS RRset was found at the zone origin
        r   TNr   r   r!   zzone file directive 'z' is not allowedr0   zbad $TTLr1   r3   zbad origin in $INCLUDEzutf-8)encodingr2   zUnknown zone file directive 'rW   zsyntax error:rZ   rX   ),r'   rK   is_eofrC   closelenrB   popr<   r@   r=   r>   r/   r?   is_eol
is_commentget_eolrb   rD   r"   r   rQ   rR   rP   r`   ra   get_namer:   r   _set_originr   r   rL   appendopen	tokenizer	Tokenizerr   r^   rt   whererh   ri   with_traceback)	rH   rN   cfilename
new_origindetailline_numberextbr   r   r   read  s   




 











R
zReader.read)FTNNNNN)rv   N)r   r   r   r   r   r   r   rd   
RdataClasstransactionTransactionboolr   rj   r   Namer   rf   	RdataTyperJ   rO   rS   rt   r   r   r   r   r   r   r   r   r&   X   sJ    


	


2 |- r&   c                       st   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Z  ZS )RRsetsReaderTransactionc                    s"   |rJ t  ||| i | _d S r4   )superrJ   	rdatasets)rH   r8   replacement	read_only	__class__r   r   rJ   2  s   
z RRsetsReaderTransaction.__init__c                 C   s   | j |||fS r4   )r   rK   rH   r   ro   coversr   r   r   _get_rdataset7  s   z%RRsetsReaderTransaction._get_rdatasetc                 C   sT   g }| j  D ]\\}}}}||kr|| qt|dkr d S tj }||_ |S Nr   )r   itemsr   r   r   r   Node)rH   r   r   rdataset_namerI   r   r   r   r   r   	_get_node:  s   

z!RRsetsReaderTransaction._get_nodec                 C   s   || j ||j|jf< d S r4   )r   ro   r   )rH   r   r   r   r   r   _put_rdatasetE  s   z%RRsetsReaderTransaction._put_rdatasetc                 C   sL   g }| j D ]}|d |kr|| qt|dkr"|D ]}| j |= qd S d S r   )r   r   r   )rH   r   removekeyr   r   r   _delete_nameH  s   


z$RRsetsReaderTransaction._delete_namec                 C   s*   z
| j |||f= W d S  ty   Y d S w r4   )r   KeyErrorr   r   r   r   _delete_rdatasetR  s
   z(RRsetsReaderTransaction._delete_rdatasetc                 C   s$   | j D ]\}}}||kr dS qdS NTF)r   )rH   r   r~   rI   r   r   r   _name_existsX  s
   z$RRsetsReaderTransaction._name_existsc                 C   s   t | jdkS r   )r   r   rH   r   r   r   _changed^  s   z RRsetsReaderTransaction._changedc                 C   sn   |r3|   r5g }| j D ]\\}}}}tj||j|j|j}|	| |
| q| j| d S d S d S r4   )r   r   r   r   rrsetRRsetr(   ro   r   updater   r8   
set_rrsets)rH   commitrrsetsr   rI   r   r   r   r   r   _end_transactiona  s   
z(RRsetsReaderTransaction._end_transactionc                 C   s   d S r4   r   )rH   originr   r   r   r   l     z#RRsetsReaderTransaction._set_originc                 C      t r4   NotImplementedErrorr   r   r   r   _iterate_rdatasetso  r   z*RRsetsReaderTransaction._iterate_rdatasetsc                 C   r   r4   r   r   r   r   r   _iterate_namesr  r   z&RRsetsReaderTransaction._iterate_names)r   r   r   rJ   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r   1  s    
r   c                   @   sz   e Zd ZejjdejjfdejjdB de	dejj
fddZdd	 Zdd
dZdd Zdd Zdeejj ddfddZdS )RRSetsReaderManagerFr   Nr;   r(   c                 C   s   || _ || _|| _g | _d S r4   )r   r;   r(   r   )rH   r   r;   r(   r   r   r   rJ   w  s   
zRRSetsReaderManager.__init__c                 C   r   r4   r   r   r   r   r   reader  r   zRRSetsReaderManager.readerc                 C   s   |du sJ t | ddS r   )r   )rH   r   r   r   r   writer  s   zRRSetsReaderManager.writerc                 C   s   | j S r4   )r(   r   r   r   r   	get_class  s   zRRSetsReaderManager.get_classc                 C   s$   | j rtjj}n| j}| j| j |fS r4   )r;   r   r   emptyr   )rH   	effectiver   r   r   r9     s   
z&RRSetsReaderManager.origin_informationr   rv   c                 C   s
   || _ d S r4   )r   )rH   r   r   r   r   r     s   
zRRSetsReaderManager.set_rrsets)F)r   r   r   r   r   rootrd   INr   r   r   rJ   r  r  r  r9   r   r   r   r   r   r   r   r   r  v  s     


r  Ftextr   r`   r(   default_rdclassro   r/   r   r   r;   rv   c
                 C   s  t |trtj|tjj|}t |trtj|||}t |tr'tj|}t |tr2tj|}|dur>tjj	|}nd}tjj	|}|durStj
j	|}nd}t||	|}
|
d$}tjj| d|d}t|||d|||||d	}|  W d   |
jS 1 sw   Y  |
jS )a	  Read one or more rrsets from the specified text, possibly subject
    to restrictions.

    *text*, a file object or a string, is the input to process.

    *name*, a string, ``dns.name.Name``, or ``None``, is the owner name of
    the rrset.  If not ``None``, then the owner name is "forced", and the
    input must not specify an owner name.  If ``None``, then any owner names
    are allowed and must be present in the input.

    *ttl*, an ``int``, string, or None.  If not ``None``, the the TTL is
    forced to be the specified value and the input must not specify a TTL.
    If ``None``, then a TTL may be specified in the input.  If it is not
    specified, then the *default_ttl* will be used.

    *rdclass*, a ``dns.rdataclass.RdataClass``, string, or ``None``.  If
    not ``None``, then the class is forced to the specified value, and the
    input must not specify a class.  If ``None``, then the input may specify
    a class that matches *default_rdclass*.  Note that it is not possible to
    return rrsets with differing classes; specifying ``None`` for the class
    simply allows the user to optionally type a class as that may be convenient
    when cutting and pasting.

    *default_rdclass*, a ``dns.rdataclass.RdataClass`` or string.  The class
    of the returned rrsets.

    *rdtype*, a ``dns.rdatatype.RdataType``, string, or ``None``.  If not
    ``None``, then the type is forced to the specified value, and the
    input must not specify a type.  If ``None``, then a type must be present
    for each RR.

    *default_ttl*, an ``int``, string, or ``None``.  If not ``None``, then if
    the TTL is not forced and is not specified, then this value will be used.
    if ``None``, then if the TTL is not forced an error will occur if the TTL
    is not specified.

    *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
    encoder/decoder.  If ``None``, the default IDNA 2003 encoder/decoder
    is used.  Note that codecs only apply to the owner name; dnspython does
    not do IDNA for names in rdata, as there is no IDNA zonefile format.

    *origin*, a string, ``dns.name.Name``, or ``None``, is the origin for any
    relative names in the input, and also the origin to relativize to if
    *relativize* is ``True``.

    *relativize*, a bool.  If ``True``, names are relativized to the *origin*;
    if ``False`` then any relative names in the input are made absolute by
    appending the *origin*.
    NTz<input>)r   F)r*   r+   r,   r-   r.   r/   )
isinstancerj   r   r   ra   r  r`   rd   r   makerf   r   r  r  r   r   r&   r   r   )r	  r   r`   r(   r
  ro   r/   r   r   r;   r8   r   r'   r  r   r   r   read_rrsets  sD   
=




r  )5r   r   rh   typingr   r   r   r   r   r   dns.exceptionr   
dns.grangedns.namedns.node	dns.rdatadns.rdataclassdns.rdatatypedns.rdtypes.ANY.SOA	dns.rrsetdns.tokenizerdns.transactiondns.ttlrQ   DNSExceptionr	   r   r    r   r   r   r   r   r   SavedStateTyper%   r&   r   r   r   TransactionManagerr  rd   r  r  rj   r   rf   r   	IDNACodecr   r   r  r   r   r   r   <module>   s    

   \E#


	

