
    Eqgm                        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	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ej        j                  Z G d dej        j                  Zd Ze	ej        j        eej        j                  eej        j                  ee         e!e"e!e"f         Z#d	 Z$ G d
 d          Z% G d dej&        j'                  Z( G 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e
ej        j         e.f                  dee!         dee
ej+        j/        e.f                  de
ej+        j/        e.f         dee
ej0        j1        e.f                  dee
e!e.f                  deej        j2                 dee
ej        j         e.f                  de"deej3        j4                 fdZ5dS )z
DNS Zones.    N)AnyIterableListOptionalSetTupleUnionc                       e Zd ZdZdS )UnknownOriginzUnknown originN__name__
__module____qualname____doc__     >/var/www/html/env/lib/python3.11/site-packages/dns/zonefile.pyr   r   &   s        r   r   c                       e Zd ZdZdS )CNAMEAndOtherDataz!A node has a CNAME and other dataNr   r   r   r   r   r   *   s        ++++r   r   c                    t           j        j                            |          }|                     |          }|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_kinds         r   _check_cname_and_other_datar$   .   s    H%77AAM<<D|ISX&,,,SX.666 STTTSX&...SX.444G
 
 	
 	/.44r   c                 b    |                                  } |                     d          sd| z   } | S )N$)upper
startswith)ss    r   _upper_dollarizer*   Q   s1    			A<< !GHr   c                   h   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e         f         d
eej        j                 dee         deej        j                 deej        j                 dee         fdZd Zd Zd Zdedeeeeeef         fdZd Z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                 f   || _         |j                                        \  | _        | _        }| j        | _        d| _        d| _        ||}
|
d| _        d| _	        n|
| _        d| _	        | j        | _
        || _        || _        g | _        d | _        |  |du r&h d| _        |r| j                            d           n6|du rt#                      | _        nt#          d |D                       | _        || _        || _        || _        |	| _        | j                            t.                     d S )Nr   FT>   $TTL$ORIGIN	$GENERATE$INCLUDEc              3   4   K   | ]}t          |          V  d S N)r*   ).0ds     r   	<genexpr>z"Reader.__init__.<locals>.<genexpr>   s+      )X)X!*:1*=*=)X)X)X)X)X)Xr   )r-   managerorigin_informationzone_origin
relativizecurrent_originlast_ttllast_ttl_knownr5   default_ttl_known	last_namezone_rdclassr   saved_statecurrent_fileallowed_directivesaddsetr1   r2   r3   r4   check_put_rdatasetr$   )selfr-   r.   r   r/   r0   r1   r2   r3   r4   r5   _s               r   __init__zReader.__init__[   sY    141O1O1Q1Q.	4?A".# #K D%*D""*D%)D",#13+/)t##&F&F&FD# 8'++J777&& '*eeD## '*)X)XGW)X)X)X&X&XD#$"*(##$?@@@@@r   c                 d    	 | j                                         }|                                rd S 0r<   )r-   getis_eol_or_eofrP   tokens     r   	_eat_linezReader._eat_line   s4    	HLLNNE""$$ 	r   c                     | j                                         }|                                st          j        j        |S r<   )r-   rT   is_identifierr   	exceptionSyntaxErrorrV   s     r   _get_identifierzReader._get_identifier   s5    ""$$ 	,-++r   c           	      t	   d}| j         	| j         }n| j        t          | j                            d          }|                                s&| j                            || j                  | _        nI| j                                        }|                                rdS | j        	                    |           | j        }|
                    | j                  s|                                  dS | j        r|                    | j                  }| j        | j        }|| _        d| _        n|                                 }d}	 t$          j                            |j                  }|| _        d| _        d}n4# t$          j        j        $ r | j        	                    |           Y nw xY w| j        | j        }n|                                 }	 t$          j                            |j                  }nE# t$          j        j        $ r  t6          $ r$ | j        }| j        	                    |           Y nw xY w|| j        k    rt$          j                            d          ||                                 }d}	 t$          j                            |j                  }|| _        d| _        d}nQ# t$          j        j        $ r: | j        r| j        }n| j        r| j        }| j        	                    |           Y nw xY w| j        | j        }np|                                 }	 t$          j                             |j                  }n6# t6          $ r) t$          j                            d|j         d          w xY w	 t$          j!                            ||| j        | j        | j        | j                  }n# t$          j        j        $ r  t6          $ r^ tE          j#                    dd         \  }}t$          j                            dtI          |           d	tI          |                     w xY w| j        s1|t$          j         j%        k    r|j&        | _        d| _        ||j&        }|t$          j                            d
          | j'        (                    |||           dS )z&Process one line from a DNS zone file.NT)want_leadingRR class is not zone's classunknown rdatatype ''   caught exception : Missing default TTL value))r1   rD   r   r-   rT   is_whitespaceas_namerH   rU   ungetis_subdomainrB   rX   rC   r2   rE   rF   r]   r   ttl	from_textvalueBadTTLr3   
rdataclassr[   r\   	ExceptionrI   rG   r5   r4   	rdatatyperdatasysexc_infostrSOAminimumr   rM   )	rP   rW   r    rk   r.   rdtyperdtyvas	            r   _rr_linezReader._rr_line   s   ?&?DD"*##HLLdL33E&&(( &!%!1!1%9L!M!M&&(( Fu%%%>D$$T%566     9t'788 >%.CDM"&D((**EC&g''44 #&*#7> & & &u%%%%%& )(GG((**E&.225;??=,    & & &+u%%%%%& $+++m//0NOOO;((**EC
&g''44 #&*#7> & & &) (*CC( (-Cu%%%%%& (&FF((**EV00== V V Vm//0Tek0T0T0TUUUV	V$$#  BB }( 	 	 	 	V 	V 	V |~~bqb)HR-++,TB,T,T3r77,T,TUUU	V % 	!&CM4E*E*E  "zD%)D"{j ;-++,GHHHT3#####sP   4F   .F10F1$G= =?H?>H?4J: :ALL/$M 3N8O A<Q sidereturnc                    t          j        d          }t          j        d          }t          j        d          }d}d}d}d}d}	|                    |          }
|
r#|
                                \  }}}}}	|dk    rd}nv|                    |          }|r%|                                \  }}}|dk    rd}d}d}	n:|                    |          }|r#|                                \  }}}}|dk    rd}d}	t	          |          }t	          |          }|dvr"t
          j                            d	|           |	d
vr"t
          j                            d|	           |||||	fS )Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$ +0r>   )r   -zinvalid offset sign )r>   oxXnNzinvalid type )recompilematchgroupsintr   r[   r\   )rP   r}   is_generate1is_generate2is_generate3modsignoffsetwidthbaseg1g2g3ioffsetiwidths                  r   _parse_modifyzReader._parse_modify  s    z"GHHz"=>>z"CDD %% 	-/YY[[*Cvudrzz##D))B $&IIKK!T62::D!''-- /1yy{{,Cvurzz"Df++Uz!!-++,I4,I,IJJJ555-++,BD,B,BCCCD'64//r   c           
      Z   | j         t          | j                                        }	 t          j                            |j                  \  }}}| j                                        }|                                st          j	        j
        n# t          $ r t          j	        j
        w xY w	 |j        }| j                                        }|                                st          j	        j
        n# t          $ r t          j	        j
        w xY w	 t          j                            |j                  }|| _        d| _        | j                                        }|                                st          j	        j
        nd# t          j        j        $ rM | j        s&| j        st          j	        
                    d          | j        r| j        }n| j        r| j        }Y nw xY w	 t          j                            |j                  }| j                                        }|                                st          j	        j
        n;# t          j	        j
        $ r t          j	        j
        t          $ r
 | j        }Y nw xY w|| j        k    rt          j	        
                    d          	 t          j                            |j                  }| j                                        }|                                st          j	        j
        n6# t          $ r) t          j	        
                    d|j         d          w xY w|j        }	dt*          dt,          d	t*          d
t*          fd}
dt*          dt,          dt*          d
t,          ffd|                     |          \  }}}}}|                     |	          \  }}}}}t1          ||dz   |          D ]} |
|||          } |
|||          } |||          } |||          }|                    d| |          }|	                    d| |          }t          j                            || j         | j        j                  | _        | j        }|                    | j                  s|                                   dS | j         r|                     | j                  }	 t          j!                            |||| j         | j         | j                  }n# t          j	        j
        $ r  t          $ r^ tE          j#                    dd         \  }}t          j	        
                    dt-          |           dt-          |                     w xY w| j$        %                    |||           dS )zPProcess one line containing the GENERATE statement from a DNS
        zone file.NTrf   r`   ra   rb   counteroffset_signr   r~   c                 "    |dk    r|dz  }| |z   S )z0Calculate the index from the counter and offset.r   r   )r   r   r   s      r   _calculate_indexz/Reader._generate_line.<locals>._calculate_index  s!    c!!"V##r   indexr   r   c                     |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.)r>   r   r   r   r   .Nr   r   )formatzfilljoinr'   )r   r   r   hexanibbles_format_indexs        r   r   z,Reader._generate_line.<locals>._format_index  s     +++eT**00777 !=U33DhhtDDbDz**6E62Gs{{!--//Nr      r&   rc   rd   re   )&rD   r   r-   rT   r   grangerl   rm   rZ   r[   r\   rp   rk   rE   rF   rn   rG   r5   ro   rI   rq   r   ru   r   rangereplacer    
idna_codecrH   rj   rB   rX   rC   rr   rs   rt   r   rM   ) rP   rW   startstopsteplhsrk   r.   rx   rhsr   lmodlsignloffsetlwidthlbasermodrsignroffsetrwidthrbaseilindexrindexlzfindexrzfindexr    rr   ry   rz   r{   r   s                                   @r   _generate_linezReader._generate_line>  s    &	, #
 4 4U[ A AE4HLLNNE&&(( 0m//0 	, 	, 	,-++	,	,+CHLLNNE&&(( 0m//0 	, 	, 	,-++	,	$'##EK00CDM"&DHLLNNE&&(( 0m//0w~ 	$ 	$ 	$' M4+A Mm//0KLLL% $&$ $m	$	(n..u{;;GHLLNNE&&(( 0m//0}( 	, 	, 	,-++ 	( 	( 	('GGG	(d'''-++,JKKK	R],,U[99FHLLNNE&&(( 0m//0 	R 	R 	R-++,P%+,P,P,PQQQ	R k	$c 	$ 	$S 	$S 	$ 	$ 	$ 	$	 	C 	 	 	 	 	 	 	 	 /3.@.@.E.E+eWfe.2.@.@.E.E+eWfeudQh-- -	( -	(A &%a88F%%a88F$}VUF;;H$}VUF;;H;;z4zz844DKK
D

H55E X//d)48+> DN >D$$T%566     9t'788Y(('O$  =,    	 	 	 <>>"1"-Rm//<B<<3r77<<  	 HLLsB''''[-	( -	(sZ   A&B B-1AC7 7DA0F AG)(G)-A"I 5JJ6A"L 3M3TA<V
c           
      	   	 	 | j                             dd          }|                                r| j        | j                                         t          | j                  dk    rL| j                            d          \  | _         | _        | _	        | _        | _
        | _        | _        | _        dS |                                r|                                r| j                                          |j        d         dk    rt          | j                  dk    r |j                                        }|| j        vr#t(          j                            d| d          |d	k    r| j                                         }|                                st(          j                            d
          t(          j                            |j                  | _        d| _        | j                                          n|dk    rk| j                                         | _        | j                                          | j        | j        | _        | j                            | j                   n|dk    rf| j                                         }|j        }| j                                         }|                                rOt(          j                            |j        | j        | j         j                  }| j                                          n:|                                 st(          j                            d          | j        }| j        !                    | j         | j        | j	        | j        | j
        | j        | j        | j        f           tE          |          | _        t(          j#        $                    | j        |          | _         || _        n>|dk    r| %                                 n#t(          j                            d| d          $| j         &                    |           | '                                 S# t(          j        j        $ ry}| j         (                                \  }}|d}t(          j                            d|||fz            }tS          j*                    d         }|+                    |          dd}~ww xY 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 allowedr7   zbad $TTLr8   r:   zbad origin in $INCLUDEr9   zUnknown zone file directive 'rb   zsyntax errorz	%s:%d: %src   ),r-   rT   is_eofrK   closelenrJ   poprD   rH   rE   rF   r5   rG   is_eol
is_commentget_eolrm   rL   r'   r   r[   r\   rZ   rk   rl   get_namerB   r   _set_originr    r   rU   appendopen	tokenizer	Tokenizerr   ri   r|   wherers   rt   with_traceback)	rP   rW   cfilename
new_origindetailline_numberextbs	            r   readzReader.read  s   [	2Q T400<<>> M(4)//1114+,,q00 !,0044	 H / N - M / , 2 E\\^^ =%%'' ;H$$&&&[^s**s43J/K/Ka/O/O ))++A 777!m77GAGGG   F{{ $$2244 H"%-";";J"G"GG+.7+<+<U[+I+I(15.((****i.2h.?.?.A.A+((***+3/3/BD,,,T-@AAAAj $#(; $ ..00 =),);); %T-@$(BU* *J !H,,....!&!4!4!6!6 ="%-";";<T"U"UU)-)<J(// $ $ 3 $ $ 1 $ $ 3 $ 0 $ 6	   -1NN)#&=#:#:4;Lh#W#W.8++k))++----!m77@A@@@   u%%%cQ d }( 	2 	2 	2&*hnn&6&6#X{~'**xf== B "B##B''T1	2s    B4Q 8NQ S#*A4SS#)FTNNNNN)r~   N)r   r   r   r   r   r   r   ro   
RdataClasstransactionTransactionboolr	   r   ru   r   r    Namer   rq   	RdataTyperR   rX   r]   r|   r   r   r   r   r   r   r   r,   r,   X   s       22 $7;.2#'=A:>%)0A 0A]$0A *0A _(	0A
 0A  hsm 340A SX]+0A C=0A   9:0A s}670A c]0A 0A 0A 0Ad    v$ v$ v$p+0# +0%S#sC0G*H +0 +0 +0 +0ZC( C( C(Jb2 b2 b2 b2 b2 b2r   r,   c                   `     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z xZS )RRsetsReaderTransactionc                 d    |rJ t                                          |||           i | _        d S r<   )superrR   	rdatasets)rP   r@   replacement	read_only	__class__s       r   rR   z RRsetsReaderTransaction.__init__)  s5    }+y999r   c                 <    | j                             |||f          S r<   )r   rT   rP   r    rx   coverss       r   _get_rdatasetz%RRsetsReaderTransaction._get_rdataset.  s    ~!!4"8999r   c                     g }| j                                         D ]$\  \  }}}}||k    r|                    |           %t          |          dk    rd S t          j                                        }||_         |S Nr   )r   itemsr   r   r   r   Node)rP   r    r   rdataset_namerQ   r!   r   s          r   	_get_nodez!RRsetsReaderTransaction._get_node1  s    	/3~/C/C/E/E 	+ 	++!]Aq8}$$  ***y>>Q4x}}"r   c                 4    || j         ||j        |j        f<   d S r<   )r   rx   r   )rP   r    r!   s      r   _put_rdatasetz%RRsetsReaderTransaction._put_rdataset<  s    CKhox?@@@r   c                     g }| j         D ]#}|d         |k    r|                    |           $t          |          dk    r|D ]}| j         |= d S d S r   )r   r   r   )rP   r    removekeys       r   _delete_namez$RRsetsReaderTransaction._delete_name?  st    > 	# 	#C1v~~c"""v;;?? ( (N3'' ?( (r   c                 @    	 | j         |||f= d S # t          $ r Y d S w xY wr<   )r   KeyErrorr   s       r   _delete_rdatasetz(RRsetsReaderTransaction._delete_rdatasetI  s@    	ff5666 	 	 	DD	s    
c                 4    | j         D ]\  }}}||k    r dS dS NTF)r   )rP   r    r   rQ   s       r   _name_existsz$RRsetsReaderTransaction._name_existsO  s3    ~ 	 	GAq!Dyytt ur   c                 2    t          | j                  dk    S r   )r   r   rP   s    r   _changedz RRsetsReaderTransaction._changedU  s    4>""Q&&r   c                 n   |r|                                  rg }| j                                        D ]d\  \  }}}}t          j                            ||j        |j        |j                  }|	                    |           |
                    |           e| j                            |           d S d S d S r<   )r  r   r   r   rrsetRRsetr.   rx   r   updater   r@   
set_rrsets)rP   commitrrsetsr    rQ   r!   r  s          r   _end_transactionz(RRsetsReaderTransaction._end_transactionX  s     	,dmmoo 	,F*..*>*>*@*@ % %&q!h	(*HOX_  X&&&e$$$$L##F+++++	, 	, 	, 	,r   c                     d S r<   r   )rP   origins     r   r   z#RRsetsReaderTransaction._set_originc  s    r   c                     t           r<   NotImplementedErrorr  s    r   _iterate_rdatasetsz*RRsetsReaderTransaction._iterate_rdatasetsf      !!r   c                     t           r<   r  r  s    r   _iterate_namesz&RRsetsReaderTransaction._iterate_namesi  r  r   )r   r   r   rR   r   r   r   r   r   r   r  r  r   r  r  __classcell__)r   s   @r   r   r   (  s            
: : :	 	 	L L L( ( (    ' ' '	, 	, 	,  " " "" " " " " " "r   r   c                   d    e Zd Zej        j        dej        j        fdZd Z	d	dZ
d Zd Zd ZdS )
RRSetsReaderManagerFc                 >    || _         || _        || _        g | _        d S r<   )r  rC   r.   r
  )rP   r  rC   r.   s       r   rR   zRRSetsReaderManager.__init__n  s$     $r   c                     t           r<   r  r  s    r   readerzRRSetsReaderManager.readerv  r  r   c                 0    |du sJ t          | dd          S r   )r   )rP   r   s     r   writerzRRSetsReaderManager.writery  s%    d""""&tT5999r   c                     | j         S r<   )r.   r  s    r   	get_classzRRSetsReaderManager.get_class}  s
    |r   c                 `    | j         rt          j        j        }n| j        }| j        | j         |fS r<   )rC   r   r    emptyr  )rP   	effectives     r   rA   z&RRSetsReaderManager.origin_information  s/    ? 	$IIIT_i88r   c                     || _         d S r<   )r
  )rP   r
  s     r   r  zRRSetsReaderManager.set_rrsets  s    r   N)F)r   r   r   r   r    rootro   INrR   r  r  r  rA   r  r   r   r   r  r  m  s        X]ucn>O   " " ": : : :  9 9 9    r   r  Ftextr    rk   r.   default_rdclassrx   r5   r   r  rC   r~   c
                    t          |t                    r0t          j                            |t          j        j        |          }t          |t                    r!t          j                            |||          }t          |t                    rt          j                            |          }t          |t                    rt          j                            |          }|%t          j        j        	                    |          }nd}t          j        j        	                    |          }|%t          j
        j        	                    |          }nd}t          ||	|          }
|
                    d          5 }t          j                            | d|          }t!          |||d|||||	  	        }|                                 ddd           n# 1 swxY w 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)r0   r1   r2   r3   r4   r5   )
isinstanceru   r   r    rl   r#  rk   ro   r   makerq   r   r  r  r   r   r,   r   r
  )r%  r    rk   r.   r&  rx   r5   r   r  rC   r@   r   r-   r  s                 r   read_rrsetsr*    s   z &# G##FCHM:FF$ <x!!$
;;#s %g$$+s## 5g''44.+0099n/44_EEO(--f55!&*oFFG			 m%%dI*%MM"!#

 

 

 	               >s    AGG"G)6r   r   rs   typingr   r   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.ttlr[   DNSExceptionr   r   r$   r   r   r    r   r   r   SavedStateTyper*   r,   r   r   r   TransactionManagerr  ro   r$  r#  ru   r   rq   r   	IDNACodecr  r  r*  r   r   r   <module>r<     s  $   				 



 C C C C C C C C C C C C C C C C C C                                           CM.   , , , , ,2 , , ,
 
 
. MSX]SX]SM
	  M2 M2 M2 M2 M2 M2 M2 M2`B" B" B" B" B"co9 B" B" B"J    #/<   @ 15?B~?P=@^=N<@-1/325(-] ]
]
5+,
-] 
#] eCN5s:;<	]
 3>4c9:] U3=2C789] %S/*] +,] U38=#-./] ] 
#)/] ] ] ] ] ]r   