
    g\                         S r SSKrSSKrSSKJrJrJrJr  SSKr	SSK
r	SSKr	1 SkrS1rSrSrSrSrS	rS
rSr " S S\	R*                  R,                  5      r " S S5      r " S S5      rg)zTokenize DNS zone file format    N)AnyListOptionalTuple>   	
 "();r
                     c                       \ rS rSrSrSrg)UngetBufferFull(   zDAn attempt was made to unget a token when the unget buffer was full. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       F/home/matz/Project1/venv/lib/python3.13/site-packages/dns/tokenizer.pyr   r   (   s    Nr   r   c            
           \ rS rSrSr   SS\S\S\S\\	   4S jjr
S	\4S
 jrS	\4S jrS	\4S jrS	\4S jrS	\4S jrS	\4S jrS	\4S jrS	\4S jrS rS rS rSS jrSS jrSrg)Token,   z~A DNS zone file format token.

ttype: The token type
value: The token value
has_escape: Does the token value contain escapes?
Nttypevalue
has_escapecommentc                 4    Xl         X l        X0l        X@l        g)zInitialize a token instance.N)r#   r$   r%   r&   )selfr#   r$   r%   r&   s        r   __init__Token.__init__4   s     

$r   returnc                 (    U R                   [        :H  $ N)r#   EOFr(   s    r   is_eofToken.is_eofB       zzS  r   c                 (    U R                   [        :H  $ r-   )r#   EOLr/   s    r   is_eolToken.is_eolE   r2   r   c                 (    U R                   [        :H  $ r-   )r#   
WHITESPACEr/   s    r   is_whitespaceToken.is_whitespaceH       zzZ''r   c                 (    U R                   [        :H  $ r-   )r#   
IDENTIFIERr/   s    r   is_identifierToken.is_identifierK   r;   r   c                 (    U R                   [        :H  $ r-   )r#   QUOTED_STRINGr/   s    r   is_quoted_stringToken.is_quoted_stringN   s    zz]**r   c                 (    U R                   [        :H  $ r-   )r#   COMMENTr/   s    r   
is_commentToken.is_commentQ   s    zzW$$r   c                 (    U R                   [        :H  $ r-   )r#   	DELIMITERr/   s    r   is_delimiterToken.is_delimiterT   s    zzY&&r   c                 \    U R                   [        :H  =(       d    U R                   [        :H  $ r-   )r#   r4   r.   r/   s    r   is_eol_or_eofToken.is_eol_or_eofW   s    zzS 5DJJ#$55r   c                     [        U[        5      (       d  gU R                  UR                  :H  =(       a    U R                  UR                  :H  $ )NF
isinstancer!   r#   r$   r(   others     r   __eq__Token.__eq__Z   s7    %''zzU[[(FTZZ5;;-FFr   c                     [        U[        5      (       d  gU R                  UR                  :g  =(       d    U R                  UR                  :g  $ )NTrP   rR   s     r   __ne__Token.__ne___   s7    %''zzU[[(EDJJ%++,EEr   c                 8    SU R                   U R                  4-  $ )Nz%d "%s")r#   r$   r/   s    r   __str__Token.__str__d   s    DJJ

333r   c                 l   U R                   (       d  U $ Sn[        U R                  5      nSnX2:  Gam  U R                  U   nUS-  nUS:X  GaF  X2:  a  [        R                  R
                  eU R                  U   nUS-  nUR                  5       (       a  X2:  a  [        R                  R
                  eU R                  U   nUS-  nX2:  a  [        R                  R
                  eU R                  U   nUS-  nUR                  5       (       a  UR                  5       (       d  [        R                  R                  e[        U5      S-  [        U5      S-  -   [        U5      -   nUS:  a  [        R                  R                  e[        U5      nX-  nX2:  a  GMm  [        U R                  U5      $ )N r   r   \d   
      )r%   lenr$   dns	exceptionUnexpectedEndisdigitSyntaxErrorintchrr!   r#   r(   	unescapedlicc2c3	codepoints           r   unescapeToken.unescapeg   s\   K	

Oe

1AFADy6--555JJqMQ99;;v!mm999ABFAv!mm999ABFAJJLLRZZ\\!mm777 #As2w| ;c"g EI 3!mm777IANI/ e0 TZZ++r   c                    Sn[        U R                  5      nSnX2:  Ga  U R                  U   nUS-  nUS:X  GaW  X2:  a  [        R                  R                  eU R                  U   nUS-  nUR                  5       (       a  X2:  a  [        R                  R                  eU R                  U   nUS-  nX2:  a  [        R                  R                  eU R                  U   nUS-  nUR                  5       (       a  UR                  5       (       d  [        R                  R                  e[        U5      S-  [        U5      S-  -   [        U5      -   nUS:  a  [        R                  R                  eUSU-  -  nO%XR                  5       -  nOXR                  5       -  nX2:  a  GM  [        U R                  [        U5      5      $ )	Nr   r   r   r^   r_   r`   ra   s   %c)rb   r$   rc   rd   re   rf   rg   rh   encoder!   r#   bytesrj   s           r   unescape_to_bytesToken.unescape_to_bytes   su   2 	

Oe

1AFADy6--555JJqMQ99;;v!mm999ABFAv!mm999ABFAJJLLRZZ\\!mm777 #As2w| ;c"g EI 3!mm777)!44I +IXXZ'	? e@ TZZy!122r   )r&   r%   r#   r$   )r]   FN)r+   r!   )r   r   r   r   r   rh   r   boolr   strr)   r0   r5   r9   r>   rB   rF   rJ   rM   rT   rW   rZ   rr   rw   r   r   r   r   r!   r!   ,   s      !%  	
 #! !! !(t ((t (+$ +%D %'d '6t 6G
F
4,@<3r   r!   c                   H   \ rS rSrSr\R                  SS4S\S\\	   S\\
R                  R                     4S jjrS\	4S	 jrS\\	\4   4S
 jrS\	SS4S jrS\4S jrS+S\S\S\4S jjrS\SS4S jrS r\rS rS,S\S\4S jjrS\4S jrS,S\S\4S jjrS,S\S\4S jjrS,S\S\4S jjrS-S\\   S\	4S jjr S\	4S jr!S-S\\   S\"\   4S jjr#S.S \S\	4S! jjr$   S/S\S"\\
R                  RJ                     S#\S$\\
R                  RJ                     S\
R                  RJ                  4
S% jjr&   S/S"\\
R                  RJ                     S#\S$\\
R                  RJ                     S\
R                  RJ                  4S& jjr'S\4S' jr(S\	4S( jr)S\4S) jr*S*r+g)0	Tokenizer   a  A DNS zone file format tokenizer.

A token object is basically a (type, value) tuple.  The valid
types are EOF, EOL, WHITESPACE, IDENTIFIER, QUOTED_STRING,
COMMENT, and DELIMITER.

file: The file to tokenize

ungotten_char: The most recently ungotten character, or None.

ungotten_token: The most recently ungotten token, or None.

multiline: The current multiline level.  This value is increased
by one every time a '(' delimiter is read, and decreased by one every time
a ')' delimiter is read.

quoting: This variable is true if the tokenizer is currently
reading a quoted string.

eof: This variable is true if the tokenizer has encountered EOF.

delimiters: The current delimiter dictionary.

line_number: The current line number

filename: A filename that will be returned by the where() method.

idna_codec: A dns.name.IDNACodec, specifies the IDNA
encoder/decoder.  If None, the default IDNA 2003
encoder/decoder is used.
Nffilename
idna_codecc                    [        U[        5      (       a  [        R                  " U5      nUc  SnOZ[        U[        5      (       a*  [        R                  " UR                  5       5      nUc  SnOUc  U[        R                  L a  SnOSnXl        SU l	        SU l
        SU l        SU l        SU l        [        U l        SU l        Uc   eX l        Uc   [$        R&                  R(                  U l        gX0l        g)a  Initialize a tokenizer instance.

f: The file to tokenize.  The default is sys.stdin.
This parameter may also be a string, in which case the tokenizer
will take its input from the contents of the string.

filename: the name of the filename that the where() method
will return.

idna_codec: A dns.name.IDNACodec, specifies the IDNA
encoder/decoder.  If None, the default IDNA 2003
encoder/decoder is used.
Nz<string>z<stdin>z<file>r   Fr   )rQ   rz   ioStringIOrv   decodesysstdinfileungotten_charungotten_token	multilinequotingeof_DELIMITERS
delimitersline_numberr   rc   name	IDNA_2003r   )r(   r~   r   r   s       r   r)   Tokenizer.__init__   s    ( aAA%5!!AHHJ'A%		>(H'H	,0/3%### 25((2D2DDO(Or   r+   c                     U R                   c\  U R                  (       a  SnU$ U R                  R                  S5      nUS:X  a	  SU l        U$ US:X  a  U =R                  S-  sl        U$ U R                   nSU l         U$ )zRead a character from input.Nr]   r   Tr   )r   r   r   readr   r(   rn   s     r   	_get_charTokenizer._get_char  s     %xx  IINN1%7#DH  $Y$$)$  ""A!%Dr   c                 2    U R                   U R                  4$ )zReturn the current location in the input.

Returns a (string, int) tuple.  The first item is the filename of
the input, the second is the current line number.
)r   r   r/   s    r   whereTokenizer.where)  s     t//00r   rn   c                 6    U R                   b  [        eXl         g)zUnget a character.

The unget buffer for characters is only one character large; it is
an error to try to unget a character when the unget buffer is not
empty.

c: the character to unget
raises UngetBufferFull: there is already an ungotten char
N)r   r   r   s     r   _unget_charTokenizer._unget_char2  s     )!!r   c                     Sn U R                  5       nUS:w  a0  US:w  a*  US:w  d  U R                  (       d  U R                  U5        U$ US-  nMM  )a  Consume input until a non-whitespace character is encountered.

The non-whitespace character is then ungotten, and the number of
whitespace characters consumed is returned.

If the tokenizer is in multiline mode, then newlines are whitespace.

Returns the number of characters skipped.
r   r	   r   r   r   )r   r   r   )r(   skippedrn   s      r   skip_whitespaceTokenizer.skip_whitespaceB  sS      ACxAIIdnn$$Q'"NqLG r   want_leadingwant_commentc                 v   U R                   bS  U R                   nSU l         UR                  5       (       a
  U(       a  U$ O!UR                  5       (       a
  U(       a  U$ OU$ U R                  5       nU(       a  US:  a  [	        [
        S5      $ Sn[        nSn U R                  5       nUS:X  d  XR                  ;   Ga  US:X  a+  U R                  (       a  [        R                  R                  eUS:X  Ga  U[        :w  Ga  US:X  a'  U =R                  S-  sl        U R                  5         M  US	:X  aQ  U R                  S::  a  [        R                  R                  eU =R                  S-  sl        U R                  5         M  US
:X  aQ  U R                  (       d  SU l	        [         U l        [        nGM   SU l	        ["        U l        U R                  5         GME  US:X  a  [	        [$        S5      $ US:X  a   U R                  5       nUS:X  d  US:X  a  OXX-  nM#  U(       a!  U R'                  U5        [	        [(        U5      $ US:X  a>  U R                  (       a  [        R                  R                  S5      e[	        [*        US9$ U R                  (       a  U R                  5         SnGM  [	        [$        SUS9$ Un[,        nOU R'                  U5        OU R                  (       a%  US:X  a  [        R                  R                  S5      eUS:X  aM  XX-  nSnU R                  5       nUS:X  d  US:X  a+  U R                  (       d  [        R                  R                  eXX-  nGM  US:X  a@  U[        :w  a6  U R                  (       a  [        R                  R                  S5      e[*        n[	        XeU5      $ )a}  Get the next token.

want_leading: If True, return a WHITESPACE token if the
first character read is whitespace.  The default is False.

want_comment: If True, return a COMMENT token if the
first token read is a comment.  The default is False.

Raises dns.exception.UnexpectedEnd: input ended prematurely

Raises dns.exception.SyntaxError: input was badly formed

Returns a Token.
Nr   r	   r]   FTr   r   r   r
   r   r   zunbalanced parentheses)r&   znewline in quoted stringr^   )r   r9   rF   r   r!   r8   r=   r   r   r   rc   rd   re   rA   r   rg   _QUOTING_DELIMITERSr   r4   r   rE   r.   rI   )	r(   r   r   utokenr   tokenr#   r%   rn   s	            r   getTokenizer.getV  s     *((F"&D##%%!M  ""$$!M   &&(GaKS))
 ABw!.7t||--555B;5M#9Cx!+,,. c>>Q."%--";";;!+,,. c#||+/DL.ADO$1E$+0DL.9DO 002$d$S$//c $ 0A DyAG %!JE	  
 ( ,,Q/#(%#88"W#~~&)mm&?&?$<'" !" $)e#<<!^^ 002$&E$#(dE#BB
 !" )$$Q'!t)mm//0JKKd
 
!
NN$7qDy--555JEO P B;5M1~~mm//0HIIEU:..r   r   c                 6    U R                   b  [        eXl         g)zUnget a token.

The unget buffer for tokens is only one token large; it is
an error to try to unget a token when the unget buffer is not
empty.

token: the token to unget

Raises UngetBufferFull: there is already an ungotten token
N)r   r   r(   r   s     r   ungetTokenizer.unget  s     *!!#r   c                 \    U R                  5       nUR                  5       (       a  [        eU$ )z8Return the next item in an iteration.

Returns a Token.
)r   r0   StopIterationr   s     r   nextTokenizer.next  s%     
<<>>r   c                     U $ r-   r   r/   s    r   __iter__Tokenizer.__iter__  s    r   basec                 N   U R                  5       R                  5       nUR                  5       (       d  [        R                  R                  S5      eUR                  R                  5       (       d  [        R                  R                  S5      e[        UR                  U5      $ )zRead the next token and interpret it as an unsigned integer.

Raises dns.exception.SyntaxError if not an unsigned integer.

Returns an int.
expecting an identifierzexpecting an integer)	r   rr   r>   rc   rd   rg   r$   rf   rh   )r(   r   r   s      r   get_intTokenizer.get_int  sw     
##%""$$--++,EFF{{""$$--++,BCC5;;%%r   c                     U R                  5       nUS:  d  US:  a"  [        R                  R                  SU-  5      eU$ )zRead the next token and interpret it as an 8-bit unsigned
integer.

Raises dns.exception.SyntaxError if not an 8-bit unsigned integer.

Returns an int.
r   ra   z#%d is not an unsigned 8-bit integerr   rc   rd   rg   )r(   r$   s     r   	get_uint8Tokenizer.get_uint8  sB     19--++5=  r   c                     U R                  US9nUS:  d  US:  aK  US:X  a#  [        R                  R                  US S35      e[        R                  R                  SU-  5      eU$ )zRead the next token and interpret it as a 16-bit unsigned
integer.

Raises dns.exception.SyntaxError if not a 16-bit unsigned integer.

Returns an int.
r   r   i     oz( is not an octal unsigned 16-bit integerz$%d is not an unsigned 16-bit integerr   r(   r   r$   s      r   
get_uint16Tokenizer.get_uint16  st     $'19qymm//QiGH  mm//:UB  r   c                     U R                  US9nUS:  d  US:  a"  [        R                  R                  SU-  5      eU$ )zRead the next token and interpret it as a 32-bit unsigned
integer.

Raises dns.exception.SyntaxError if not a 32-bit unsigned integer.

Returns an int.
r   r   l    z$%d is not an unsigned 32-bit integerr   r   s      r   
get_uint32Tokenizer.get_uint32  sH     $'19
*--++6>  r   c                     U R                  US9nUS:  d  US:  a"  [        R                  R                  SU-  5      eU$ )zRead the next token and interpret it as a 48-bit unsigned
integer.

Raises dns.exception.SyntaxError if not a 48-bit unsigned integer.

Returns an int.
r   r   l    z$%d is not an unsigned 48-bit integerr   r   s      r   
get_uint48Tokenizer.get_uint48+  sH     $'19/--++6>  r   
max_lengthc                 f   U R                  5       R                  5       nUR                  5       (       d4  UR                  5       (       d  [        R
                  R                  S5      eU(       a8  [        UR                  5      U:  a  [        R
                  R                  S5      eUR                  $ )zRead the next token and interpret it as a string.

Raises dns.exception.SyntaxError if not a string.
Raises dns.exception.SyntaxError if token value length
exceeds max_length (if specified).

Returns a string.
zexpecting a stringzstring too long)	r   rr   r>   rB   rc   rd   rg   rb   r$   )r(   r   r   s      r   
get_stringTokenizer.get_string;  s~     
##%##%%)?)?)A)A--++,@AA#ekk*Z7--++,=>>{{r   c                     U R                  5       R                  5       nUR                  5       (       d  [        R                  R                  S5      eUR                  $ )zRead the next token, which should be an identifier.

Raises dns.exception.SyntaxError if not an identifier.

Returns a string.
r   )r   rr   r>   rc   rd   rg   r$   r   s     r   get_identifierTokenizer.get_identifierL  sG     
##%""$$--++,EFF{{r   
max_tokensc                     / n U R                  5       nUR                  5       (       a  U R                  U5         U$ UR                  U5        [	        U5      U:X  a   U$ M^  )zReturn the remaining tokens on the line, until an EOL or EOF is seen.

max_tokens: If not None, stop after this number of tokens.

Returns a list of tokens.
)r   rM   r   appendrb   )r(   r   tokensr   s       r   get_remainingTokenizer.get_remainingY  sc     HHJE""$$

5!  MM% 6{j( r   allow_emptyc                 n   Sn U R                  5       R                  5       nUR                  5       (       a  U R                  U5        O?UR	                  5       (       d  [
        R                  R                  eX#R                  -  nM  U(       d&  U(       d  [
        R                  R                  S5      eU$ )aG  Read the remaining tokens on the line, which should be identifiers.

Raises dns.exception.SyntaxError if there are no remaining tokens,
unless `allow_empty=True` is given.

Raises dns.exception.SyntaxError if a token is seen that is not an
identifier.

Returns a string containing a concatenation of the remaining
identifiers.
r]   zexpecting another identifier)	r   rr   rM   r   r>   rc   rd   rg   r$   )r(   r   sr   s       r   !concatenate_remaining_identifiers+Tokenizer.concatenate_remaining_identifiersl  s     HHJ'')E""$$

5!&&((mm///A  q--++,JKKr   origin
relativizerelativize_toc                    UR                  5       (       d  [        R                  R                  S5      e[        R                  R                  UR                  X R                  5      nUR                  U=(       d    UU5      $ )zuTry to interpret the token as a DNS name.

Raises dns.exception.SyntaxError if not a name.

Returns a dns.name.Name.
r   )	r>   rc   rd   rg   r   	from_textr$   r   choose_relativity)r(   r   r   r   r   r   s         r   as_nameTokenizer.as_name  s_     ""$$--++,EFFxx!!%++vG%%m&=vzJJr   c                 F    U R                  5       nU R                  XAX#5      $ )zRead the next token and interpret it as a DNS name.

Raises dns.exception.SyntaxError if not a name.

Returns a dns.name.Name.
)r   r   )r(   r   r   r   r   s        r   get_nameTokenizer.get_name  s      
||E:EEr   c                     U R                  5       nUR                  5       (       d8  [        R                  R	                  SUR
                  UR                  4-  5      eU$ )zVRead the next token and raise an exception if it isn't EOL or
EOF.

Returns a string.
z expected EOL or EOF, got %d "%s")r   rM   rc   rd   rg   r#   r$   r   s     r   get_eol_as_tokenTokenizer.get_eol_as_token  sQ     
""$$--++2ekk5;;5OO  r   c                 6    U R                  5       R                  $ r-   )r   r$   r/   s    r   get_eolTokenizer.get_eol  s    $$&,,,r   c                     U R                  5       R                  5       nUR                  5       (       d  [        R                  R                  S5      e[        R                  R                  UR                  5      $ )zRead the next token and interpret it as a DNS TTL.

Raises dns.exception.SyntaxError or dns.ttl.BadTTL if not an
identifier or badly formed.

Returns an int.
r   )	r   rr   r>   rc   rd   rg   ttlr   r$   r   s     r   get_ttlTokenizer.get_ttl  sV     
##%""$$--++,EFFww  --r   )
r   r   r   r   r   r   r   r   r   r   )FF)r`   r-   )F)NFN),r   r   r   r   r   r   r   r   r   rz   rc   r   	IDNACodecr)   r   r   rh   r   r   r   ry   r!   r   r   r   __next__r   r   r   r   r   r   r   r   r   r   r   Namer   r   r   r   r   r   r   r   r   r|   r|      s`   D "&37	/)/) 3-/) SXX//0	/)b3 "1uS#X 1S T   (m/ m/D m/U m/^$5 $T $ 	 H
&C & &3  s C *s C  s C  Xc] c "  e &T c 8 +/ 15KK 'K 	K
  .K 
K( +/ 15	F'F F  .	F
 
F % - -. .r   r|   )r   r   r   typingr   r   r   r   dns.exceptionrc   dns.namedns.ttlr   r   r.   r4   r8   r=   rA   rE   rI   rd   DNSExceptionr   r!   r|   r   r   r   <module>r      s   $ $ 	 
 - -   3e 


	Ocmm00 OW3 W3t~. ~.r   