
    *DCf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j0                  j2                        Z G d dej0                  j2                        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jL                  jN                        Z( G d dejL                  jR                        Z*ddejV                  jX                  ejV                  jX                  dddej>                  jZ                  df	dedee
ej>                  j@                  e.f      dee!   dee
ejV                  j^                  e.f      de
ejV                  j^                  e.f   dee
ej`                  jb                  e.f      dee
e!e.f      deej>                  jd                     dee
ej>                  j@                  e.f      de"deejf                  jh                     fdZ5y)z
DNS Zones.    N)AnyIterableListOptionalSetTupleUnionc                       e Zd ZdZy)UnknownOriginzUnknown originN__name__
__module____qualname____doc__     L/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/dns/zonefile.pyr   r   &   s    r   r   c                       e Zd ZdZy)CNAMEAndOtherDataz!A node has a CNAME and other dataNr   r   r   r   r   r   *   s    +r   r   c                    t         j                  j                  j                  |      }| j	                  |      }|y |j                         }|t         j                  j                  j                  k(  r2|t         j                  j                  j                  k(  rt        d      |t         j                  j                  j                  k(  r3|t         j                  j                  j                  k(  rt        d      y y )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    HH%%77AM<<D|ISXX&&,,,SXX..666 STTSXX&&...SXX..444G
 	
 5 	/r   c                 R    | j                         } | j                  d      sd| z   } | S )N$)upper
startswith)ss    r   _upper_dollarizer*   Q   s'    		A<<!GHr   c                      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y)Readerz(Read a DNS zone file into a transaction.Ntokrdclassr   allow_includeallow_directives
force_name	force_ttlforce_rdclassforce_rdtypedefault_ttlc                 f   || _         |j                  j                         \  | _        | _        }| j                  | _        d| _        d| _        ||}
|
d| _        d| _	        n|
| _        d| _	        | j
                  | _
        || _        || _        g | _        d | _        |  |du r'h d| _        |rG| j                  j!                  d       n+|du rt#               | _        nt#        d |D              | _        || _        || _        || _        |	| _        | j                  j-                  t.               y )Nr   FT>   $TTL$ORIGIN	$GENERATE$INCLUDEc              3   2   K   | ]  }t        |        y wN)r*   ).0ds     r   	<genexpr>z"Reader.__init__.<locals>.<genexpr>   s     )X!*:1*=)Xs   )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__[   s(    141O1O1Q.	4?A"..# #K D%*D"*D%)D",,#13+/t#&FD#''++J7& '*eD# '*)XGW)X&XD#$"*(##$?@r   c                 \    	 | j                   j                         }|j                         ry ,r<   )r-   getis_eol_or_eofrP   tokens     r   	_eat_linezReader._eat_line   s(    HHLLNE""$ r   c                     | j                   j                         }|j                         st        j                  j
                  |S r<   )r-   rT   is_identifierr   	exceptionSyntaxErrorrV   s     r   _get_identifierzReader._get_identifier   s2    ""$--+++r   c           	      
   d}| j                   | j                   }n| j                  t        | j                  j	                  d      }|j                         s,| j                  j                  || j                        | _        nF| j                  j	                         }|j                         ry| j                  j                  |       | j                  }|j                  | j                        s| j                          y| j                  r|j                  | j                        }| j                  | j                  }|| _        d| _        nL| j#                         }d}	 t$        j&                  j)                  |j*                        }|| _        d| _        d}| j.                  | j.                  }nh| j#                         }	 t$        j0                  j)                  |j*                        }|| j8                  k7  rt$        j2                  j5                  d      |L| j#                         }d}	 t$        j&                  j)                  |j*                        }|| _        d| _        d}| j>                  | j>                  }n:| j#                         }	 t$        j@                  j)                  |j*                        }	 t$        jB                  j)                  ||| j                  | j                  | j                  | j                        }| j:                  sC|t$        j@                  jL                  k(  r&|jN                  | _        d| _        ||jN                  }|t$        j2                  j5                  d      | jP                  jS                  |||       y# t$        j&                  j,                  $ r | j                  j                  |       Y 8w xY w# t$        j2                  j4                  $ r  t6        $ r+ | j8                  }| j                  j                  |       Y 9w xY w# t$        j&                  j,                  $ rP | j:                  r| j<                  }n| j                   r| j                  }| j                  j                  |       Y -w xY w# t6        $ r- t$        j2                  j5                  d|j*                  z        w xY w# t$        j2                  j4                  $ r  t6        $ r\ tE        jF                         dd \  }}t$        j2                  j5                  djI                  tK        |      tK        |                  w xY w)	z&Process one line from a DNS zone file.NT)want_leadingRR class is not zone's classunknown rdatatype '%s'   z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formatstrSOAminimumr   rM   )	rP   rW   r    rh   r.   rdtyperdtyvas	            r   _rr_linezReader._rr_line   sB   ??&??D""*##HHLLdL3E&&(!%!1!1%9L9L!M&&(u%>>D$$T%5%56 t'7'78 >>%..CDM"&D((*EC&gg''4 #&*#
 )((G((*E&..225;;? $+++mm//0NOO;((*EC
&gg''4 #&*# (&&F((*EX00=	$$##  B, %%&CMM4E4E*E  "zzD%)D"{jj ;--++,GHHT3#e 77>> &u%& ==,,  &++u%& 77>> &))**C((--Cu%&  Xmm//0H5;;0VWWX }}(( 	 		 ||~bq)HR--++)00R#b'B 		sR   &9N 	)O 59P/ )R AS 8OOAP,+P,/A)RR6SBUsidereturnc                    t        j                  d      }t        j                  d      }t        j                  d      }|j                  |      }|r|j                         \  }}}}	}
|dk(  rd}|j                  |      }|r|j                         \  }}}|dk(  rd}d}	d}
|j                  |      }|r|j                         \  }}}}	|dk(  rd}d}
|s|s|s
d}d}d}d}	d}
t	              }t	        	      }	dvr"t
        j                  j                  d	|z        
d
vr"t
        j                  j                  d|
z        |||	|
fS )Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$ +r   r>   )r   -zinvalid offset sign %s)r>   oxXnNzinvalid type %s)recompilematchgroupsintr   r[   r\   )rP   r{   is_generate1is_generate2is_generate3g1modsignoffsetwidthbaseg2g3s                r   _parse_modifyzReader._parse_modify  se    zz"GHzz"=>zz"CD %-/YY[*Cvudrz% "		CvrzED%')yy{$CvurzDbBCDFEDVE
z!--++,Dt,KLL55--++,=,DEED&%--r   c           
      |   | j                   t        | j                  j                         }	 t        j
                  j                  |j                        \  }}}| j                  j                         }|j                         st        j                  j                  	 	 |j                  }| j                  j                         }|j                         st        j                  j                  	 	 t        j                  j                  |j                        }|| _        d| _        | j                  j                         }|j                         st        j                  j                  	 	 t        j$                  j                  |j                        }| j                  j                         }|j                         st        j                  j                  	 || j&                  k7  rt        j                  j                  d      	 t        j(                  j                  |j                        }| j                  j                         }|j                         st        j                  j                  	 |j                  }	dt*        dt,        dt*        d	t*        fd
}
dt*        dt,        dt*        d	t,        ffd| j/                  |      \  }}}}}| j/                  |	      \  }}}}}t1        ||dz   |      D ]Y  } |
|||      } |
|||      } |||      } |||      }|j3                  d|z  |      }|	j3                  d|z  |      }t        j4                  j                  || j                   | j                  j6                        | _        | j8                  }|j;                  | j<                        s| j?                           y| j@                  r|jA                  | j<                        }	 t        jB                  j                  |||| j                   | j@                  | j<                        }| jH                  jK                  ||       \ y# t        $ r t        j                  j                  w xY w# t        $ r t        j                  j                  w xY w# t        j                  j                  $ rl | j                  s+| j                   st        j                  j                  d      | j                   r| j"                  }n| j                  r| j                  }Y w xY w# t        j                  j                  $ r t        j                  j                  t        $ r | j&                  }Y w xY w# t        $ r- t        j                  j                  d|j                  z        w xY w# t        j                  j                  $ r  t        $ rR tE        jF                         dd \  }}t        j                  j                  dt-        |      dt-        |            w xY w)zPProcess one line containing the GENERATE statement from a DNS
        zone file.NTrc   r`   ra   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        | |      j                  |      S  | d|      }dj                  |ddd         d| }|dk(  r|j                         }|S )zVFormat the index with the given base, and zero-fill it
            to the given width.)r>   r   r   r   r   .Nr   r   )rr   zfilljoinr'   )r   r   r   hexanibbles_format_indexs        r   r   z,Reader._generate_line.<locals>._format_index  sj     ++eT*0077 !U3DhhtDbDz*6E2Gs{!--/Nr      z$%srb   zcaught exception z: )&rD   r   r-   rT   r   grangeri   rj   rZ   r[   r\   rm   rh   rE   rF   rk   rG   r5   rl   rI   rn   r   rs   r   rangereplacer    
idna_codecrH   rg   rB   rX   rC   ro   rp   rq   r   rM   ) rP   rW   startstopsteplhsrh   r.   rv   rhsr   lmodlsignloffsetlwidthlbasermodrsignroffsetrwidthrbaseilindexrindexlzfindexrzfindexr    ro   rw   rx   ry   r   s                                   @r   _generate_linezReader._generate_line@  s    &	, #

 4 4U[[ AE4HHLLNE&&(mm/// )	,++CHHLLNE&&(mm/// )	$''##EKK0CDM"&DHHLLNE&&(mm/// )	(nn..u{{;GHHLLNE&&(mm/// ) d'''--++,JKK	T]],,U[[9FHHLLNE&&(mm/// ) kk	$c 	$ 	$S 	$S 	$	 	C 	 	 	 /3.@.@.E+eWfe.2.@.@.E+eWfeudQh- -	(A &a8F%a8F$VUF;H$VUF;H;;u~x8DKK9E XX//d))488+>+>DN >>D$$T%5%56 t'7'78YY((''OO$$, HHLLsB'[-	(Q  	,--+++	,  	,--+++	, ww~~ 	$''4+A+Amm//0KLL%%&&$$mm	$ }}(( 	,--+++ 	(''G	(  	T--++,Du{{,RSS	Tt ==,,  	 <<>"1-Rmm//14R#b'B 	s\   A1Q "AR 4A;R, 1A-T8 A-V
 ;AW$R$R),BT54T58AVV
6W A8X;c           
      v
   	 	 | j                   j                  dd      }|j                         r| j                  | j                  j	                          t        | j                        dkD  rM| j                  j                  d      \  | _         | _        | _	        | _        | _
        | _        | _        | _        y|j                         r|j                         r| j                   j!                          |j"                  d   dk(  rpt        | j$                        dkD  rW|j"                  j'                         }|| j$                  vr#t(        j*                  j-                  d| d      |dk(  r| j                   j                         }|j/                         st(        j*                  j-                  d	      t(        j0                  j3                  |j"                        | _        d| _        | j                   j!                          nk|d
k(  r}| j                   j5                         | _        | j                   j!                          | j6                  | j                  | _        | j8                  j;                  | j                         n|dk(  r| j                   j                         }|j"                  }| j                   j                         }|j/                         rdt(        j<                  j3                  |j"                  | j                  | j                   j>                        }| j                   j!                          n;|jA                         st(        j*                  j-                  d      | j                  }| j                  jC                  | j                   | j                  | j                  | j                  | j                  | j                  | j                  | j                  f       tE        |d      | _        t(        jF                  jI                  | j                  |      | _         || _        n9|dk(  r| jK                          n#t(        j*                  j-                  d| d      x| j                   jM                  |       | jO                          # t(        j*                  j,                  $ rt}| j                   jQ                         \  }}|d}t(        j*                  j-                  d|||fz        }tS        jT                         d   }|jW                  |      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
        TNr   r   r&   zzone file directive 'z' is not allowedr7   zbad $TTLr8   r:   zbad origin in $INCLUDErr9   zUnknown zone file directive ''zsyntax errorz	%s:%d: %srb   ),r-   rT   is_eofrK   closelenrJ   poprD   rH   rE   rF   r5   rG   is_eol
is_commentget_eolrj   rL   r'   r   r[   r\   rZ   rh   ri   get_namerB   r   _set_originr    r   rU   appendopen	tokenizer	Tokenizerr   rf   rz   whererp   rq   with_traceback)	rP   rW   cfilename
new_origindetailline_numberextbs	            r   readzReader.read  s   [	2T40<<>((4))//14++,q0 !,,004	 H / N - M / , 2 \\^%%'HH$$&[[^s*s43J3J/Ka/O ))+A 7 77!mm773A36FG  F{ $$224"%--";";J"GG+.77+<+<U[[+I(15.((*i.2hh.?.?.A+((*++3/3/B/BD,,,T-@-@Aj $#(;; $ ..0),);); %T-@-@$((BUBU*J !HH,,.!&!4!4!6"%--";";<T"UU)-)<)<J((// $ $ 3 3 $ $ 1 1 $ $ 3 3 $ 0 0 $ 6 6	 -13,?)#&==#:#:4;L;Lh#W.8+k)++-!mm77;A3a@  u%c d }}(( 	2&*hhnn&6#X{~'**xf==B "B##B'T1	2s    B8R' ;O,R' 'T8A/T33T8)FTNNNNN)r|   N)r   r   r   r   r   r   r   rl   
RdataClasstransactionTransactionboolr	   r   rs   r   r    Namer   rn   	RdataTyperR   rX   r]   rz   r   r   r   r   r   r   r   r,   r,   X   s0   2 $7;.2#'=A:>%)0A]]$$0A **0A __((	0A
 0A  hsm 340A SXX]]+0A C=0A   9 9:0A s}}6670A c]0Adx$t+.# +.%S#sC0G*H +.ZC(J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                 >    |rJ t         |   |||       i | _        y r<   )superrR   	rdatasets)rP   r@   replacement	read_only	__class__s       r   rR   z RRsetsReaderTransaction.__init__+  s#    }+y9r   c                 >    | j                   j                  |||f      S r<   )r   rT   rP   r    rv   coverss       r   _get_rdatasetz%RRsetsReaderTransaction._get_rdataset0  s    ~~!!4"899r   c                     g }| j                   j                         D ]   \  \  }}}}||k(  s|j                  |       " t        |      dk(  ry t        j
                  j                         }||_         |S Nr   )r   itemsr   r   r   r   Node)rP   r    r   rdataset_namerQ   r!   r   s          r   	_get_nodez!RRsetsReaderTransaction._get_node3  sq    	/3~~/C/C/E 	++!]Aq8}$  *	+ y>Qxx}}"r   c                 P    || j                   ||j                  |j                  f<   y r<   )r   rv   r   )rP   r    r!   s      r   _put_rdatasetz%RRsetsReaderTransaction._put_rdataset>  s    CKhoox?@r   c                     g }| j                   D ]  }|d   |k(  s|j                  |        t        |      dkD  r|D ]  }| j                   |=  y y r   )r   r   r   )rP   r    removekeys       r   _delete_namez$RRsetsReaderTransaction._delete_nameA  s^    >> 	#C1v~c"	# v;? (NN3'( r   c                 D    	 | j                   |||f= y # t        $ r Y y w xY wr<   )r   KeyErrorr   s       r   _delete_rdatasetz(RRsetsReaderTransaction._delete_rdatasetK  s,    	ff56 		s    	c                 <    | j                   D ]  \  }}}||k(  s y yNTF)r   )rP   r    r   rQ   s       r   _name_existsz$RRsetsReaderTransaction._name_existsQ  s*    ~~ 	GAq!Dy	 r   c                 2    t        | j                        dkD  S r   )r   r   rP   s    r   _changedz RRsetsReaderTransaction._changedW  s    4>>"Q&&r   c                 v   |r| j                         rg }| j                  j                         D ]k  \  \  }}}}t        j                  j                  ||j                  |j                  |j                        }|j                  |       |j                  |       m | j                  j                  |       y y y r<   )r   r   r   r   rrsetRRsetr.   rv   r   updater   r@   
set_rrsets)rP   commitrrsetsr    rQ   r!   r  s          r   _end_transactionz(RRsetsReaderTransaction._end_transactionZ  s    dmmoF*...*>*>*@ %&q!h		(**HOOX__ X&e$% LL##F+ &6r   c                      y r<   r   )rP   origins     r   r   z#RRsetsReaderTransaction._set_origine  s    r   c                     t         r<   NotImplementedErrorr   s    r   _iterate_rdatasetsz*RRsetsReaderTransaction._iterate_rdatasetsh      !!r   c                     t         r<   r  r   s    r   _iterate_namesz&RRsetsReaderTransaction._iterate_namesk  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('	,""r   r   c                       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y)
RRSetsReaderManagerFc                 <    || _         || _        || _        g | _        y r<   )r	  rC   r.   r  )rP   r	  rC   r.   s       r   rR   zRRSetsReaderManager.__init__p  s      $r   c                     t         r<   r  r   s    r   readerzRRSetsReaderManager.readerx  r  r   c                 (    |du sJ t        | dd      S r   )r   )rP   r   s     r   writerzRRSetsReaderManager.writer{  s    d"""&tT5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  s4    ??IIT__i88r   c                     || _         y r<   )r  )rP   r  s     r   r  zRRSetsReaderManager.set_rrsets  s	    r   N)F)r   r   r   r   r    rootrl   INrR   r  r  r  rA   r  r   r   r   r  r  o  s9    XX]]ucnn>O>O":9r   r  Ftextr    rh   r.   default_rdclassrv   r5   r   r	  rC   r|   c
                    t        |t              r9t        j                  j	                  |t        j                  j
                  |      }t        |t              r!t        j                  j	                  |||      }t        |t              rt        j                  j	                  |      }t        |t              rt        j                  j	                  |      }|*t        j                  j                  j                  |      }nd}t        j                  j                  j                  |      }|*t        j                  j                  j                  |      }nd}t        ||	|      }
|
j                  d      5 }t        j                  j                  | d|      }t!        |||d|||||	      }|j#                          ddd       |
j$                  S # 1 sw Y   |
j$                  S xY w)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   )
isinstancers   r   r    ri   r  rh   rl   r   makern   r   r  r  r   r   r,   r   r  )r!  r    rh   r.   r"  rv   r5   r   r	  rC   r@   r   r-   r  s                 r   read_rrsetsr&    s   z &###FCHHMM:F$xx!!$
;#sgg$+s#gg''4..++009nn//44_EO((--f5!&*oFG		 mm%%dI*%M"!#

 	 >> >>s   <AGG+)6r   r   rp   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  rl   r   r  rs   r   rn   r   	IDNACodecr  r  r&  r   r   r   <module>r8     sV  $  	 
 C C C            CMM.. ,22 ,
. MMSXX]]SXX]]SM
	O2 O2dB"coo99 B"J#//<< @ 15?B~~?P?P=@^^=N=N<@-1/325((--]
]
5+,
-] 
#] eCNN55s:;<	]
 3>>44c9:] U3==22C789] %S/*] ++,] U388==#-./] ] 
#))//]r   