
    xF                         S r SSKJr  SSKrSSKrSSKrSSKrSSKJ	r	J
r
Jr  SSSSSSSS.rSS0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 master file format    )StringION   )long	text_typebinary_typeT) 	
;()"r                  c                       \ rS rSrSrSrg)UngetBufferFull0   zDAn attempt was made to unget a token when the unget buffer was full. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r        lib/third_party/dns/tokenizer.pyr   r   0   s    Nr   r   c                   |    \ rS rSrSrSS jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)Token4   zA DNS master file format token.

ttype: The token type
value: The token value
has_escape: Does the token value contain escapes?
c                 (    Xl         X l        X0l        g)zInitialize a token instance.N)ttypevalue
has_escape)selfr$   r%   r&   s       r   __init__Token.__init__<   s     

$r   c                 (    U R                   [        :H  $ N)r$   EOFr'   s    r   is_eofToken.is_eofC       zzS  r   c                 (    U R                   [        :H  $ r+   )r$   EOLr-   s    r   is_eolToken.is_eolF   r0   r   c                 (    U R                   [        :H  $ r+   )r$   
WHITESPACEr-   s    r   is_whitespaceToken.is_whitespaceI       zzZ''r   c                 (    U R                   [        :H  $ r+   )r$   
IDENTIFIERr-   s    r   is_identifierToken.is_identifierL   r9   r   c                 (    U R                   [        :H  $ r+   )r$   QUOTED_STRINGr-   s    r   is_quoted_stringToken.is_quoted_stringO   s    zz]**r   c                 (    U R                   [        :H  $ r+   )r$   COMMENTr-   s    r   
is_commentToken.is_commentR   s    zzW$$r   c                 (    U R                   [        :H  $ r+   )r$   	DELIMITERr-   s    r   is_delimiterToken.is_delimiterU   s    zzY&&r   c                 \    U R                   [        :H  =(       d    U R                   [        :H  $ r+   )r$   r2   r,   r-   s    r   is_eol_or_eofToken.is_eol_or_eofX   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__[   s<    %''

ekk) *

ekk)	+r   c                     [        U[        5      (       d  gU R                  UR                  :g  =(       d    U R                  UR                  :g  $ )NTrN   rP   s     r   __ne__Token.__ne__a   s<    %''

ekk) *

ekk)	+r   c                 8    SU R                   U R                  4-  $ )Nz%d "%s")r$   r%   r-   s    r   __str__Token.__str__g   s    DJJ

333r   c                 (   U R                   (       d  U $ Sn[        U R                  5      nSnX2:  GaK  U R                  U   nUS-  nUS:X  Ga$  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      -   5      nX-  nX2:  a  GMK  [        U R                  U5      $ )N r   r   \d   
   )r&   lenr%   dns	exceptionUnexpectedEndisdigitSyntaxErrorchrintr!   r$   )r'   	unescapedlicc2c3s          r   unescapeToken.unescapej   sA   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CFSL3r7R<7#b'ABANI) e* TZZ++r   c                     g)Nr   r   r-   s    r   __len__Token.__len__   s    r   c                 D    [        U R                  U R                  45      $ r+   )iterr$   r%   r-   s    r   __iter__Token.__iter__   s    TZZ,--r   c                 V    US:X  a  U R                   $ US:X  a  U R                  $ [        e)Nr   r   )r$   r%   
IndexError)r'   ri   s     r   __getitem__Token.__getitem__   s*    6::!V::r   )r&   r$   r%   N)r[   F)r   r   r   r   r   r(   r.   r3   r7   r<   r@   rD   rH   rK   rR   rU   rX   rm   rp   rt   rx   r   r   r   r   r!   r!   4   sW    %!!((+%'6++4,>.r   r!   c                       \ rS rSrSr\R                  S4S jrS rS r	S r
S rSS	 jrS
 rS r\rS rSS jrS rSS jrS rSS jrSS jrSS jrS rS rSrg)	Tokenizer   a$  A DNS master 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.
Nc                 p   [        U[        5      (       a  [        U5      nUc  SnOO[        U[        5      (       a  [        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        X l        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.
Nz<string>z<stdin>z<file>r   Fr   )rO   r   r   r   decodesysstdinfileungotten_charungotten_token	multilinequotingeof_DELIMITERS
delimitersline_numberfilename)r'   fr   s      r   r(   Tokenizer.__init__   s     a##A%;''$A%		>(H'H	!"% 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'   rj   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   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_char   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'   skippedrj   s      r   skip_whitespaceTokenizer.skip_whitespace  sS      ACxAIIdnn$$Q'"NqLG r   c                 	   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  XpR                  ;   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X7-  nM#  U(       a!  U R'                  U5        [	        [(        U5      $ US:X  a?  U R                  (       a  [        R                  R                  S5      e[	        [*        5      $ U R                  (       a  U R                  5         SnGM  [	        [$        S5      $ Un[,        nOU R'                  U5        GOU R                  (       GaI  US:X  Ga  U R                  5       nUS:X  a  [        R                  R                  eUR/                  5       (       a  U R                  5       nUS:X  a  [        R                  R                  eU R                  5       n	US:X  a  [        R                  R                  eUR/                  5       (       a  U	R/                  5       (       d  [        R                  R                  e[1        [3        U5      S-  [3        U5      S-  -   [3        U	5      -   5      nOhUS:X  a  [        R                  R                  S5      eOBUS:X  a<  X7-  nSnU R                  5       nUS:X  d  US:X  a  [        R                  R                  eX7-  nGM  US:X  a@  U[        :w  a6  U R                  (       a  [        R                  R                  S5      e[*        n[	        XSU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 parenthesesr\   r]   r^   znewline in quoted string)r   r7   rD   r   r!   r6   r;   r   r   r   r`   ra   rb   r?   r   rd   _QUOTING_DELIMITERSr   r2   r   rC   r,   rG   rc   re   rf   )
r'   want_leadingwant_commenttokenr   r$   r&   rj   rk   rl   s
             r   getTokenizer.get  s     *''E"&D""$$ L  !!## L   &&(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&?&?$<'> !>#(:-!^^ 002$&E$#(d#33
 !" )$$Q'9(ABw!mm999yy{{!^^-8"%--"="==!^^-7"%--"="== "

"%--";";;As2w| ;c"g EF$Y--334NOO d
 
!
NN$7a4i--555JEk l B;5M1~~mm//0HIIEU:..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   r.   StopIterationr   s     r   nextTokenizer.next  s%     
<<>>r   c                     U $ r+   r   r-   s    r   rt   Tokenizer.__iter__  s    r   c                 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      $ )zzRead the next token and interpret it as an integer.

Raises dns.exception.SyntaxError if not an integer.

Returns an int.
expecting an identifierexpecting an integer)	r   rm   r<   r`   ra   rd   r%   rc   rf   )r'   baser   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      z#%d is not an unsigned 8-bit integerr   r`   ra   rd   )r'   r%   s     r   	get_uint8Tokenizer.get_uint8  s@     19--++5=? ?r   c                     U R                  US9nUS:  d  US:  aJ  US:X  a"  [        R                  R                  SU-  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     z*%o 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  sq     $'19qymm//@5HJ J mm//:UBD Dr   c                    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                  5      nUS:  d  U[        S5      :  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   r   l        z$%d is not an unsigned 32-bit integer)	r   rm   r<   r`   ra   rd   r%   rc   r   )r'   r   r%   s      r   
get_uint32Tokenizer.get_uint32  s     
##%""$$--++,EFF{{""$$--++,BCCU[[!19Z 00--++6>@ @r   c                     U R                  5       R                  5       nUR                  5       (       d4  UR                  5       (       d  [        R
                  R                  S5      eUR                  $ )zxRead the next token and interpret it as a string.

Raises dns.exception.SyntaxError if not a string.

Returns a string.
zexpecting a string)r   rm   r<   r@   r`   ra   rd   r%   r'   originr   s      r   
get_stringTokenizer.get_string  sU     
##%##%%)?)?)A)A--++,@AA{{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   rm   r<   r`   ra   rd   r%   r   s      r   get_identifierTokenizer.get_identifier  sG     
##%""$$--++,EFF{{r   c                     U R                  5       nUR                  5       (       d  [        R                  R	                  S5      e[        R
                  R                  UR                  U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`   ra   rd   name	from_textr%   r   s      r   get_nameTokenizer.get_name  sO     
""$$--++,EFFxx!!%++v66r   c                     U R                  5       nUR                  5       (       d8  [        R                  R	                  SUR
                  UR                  4-  5      eUR                  $ )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   rK   r`   ra   rd   r$   r%   r   s     r   get_eolTokenizer.get_eol!  s_     
""$$--++2ekk6;kk6C CD D {{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   rm   r<   r`   ra   rd   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   )FF)r^   r+   )r   r   r   r   r   r   r   r(   r   r   r   r   r   r   r   __next__rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r{   r{      sv    8 T !!F$1({/z$ 	 H
&&(7.r   r{   )r   ior   r   dns.exceptionr`   dns.namedns.ttl_compatr   r   r   r   r   r,   r2   r6   r;   r?   rC   rG   ra   DNSExceptionr   objectr!   r{   r   r   r   <module>r      s   $ &  
    1 1 


				 Dk 


	Ocmm00 OaF aHc. c.r   