o
    2³cpW  ã                   @   sŠ   d Z ddlZddlZddlZddlZddlZh d£ZdhZdZ	dZ
dZdZdZd	Zd
ZG dd„ dejjƒZG dd„ dƒZG dd„ dƒZdS )zTokenize DNS zone file formaté    N>   Ú
ú	ú ú"ú(ú)ú;r   é   é   é   é   é   é   c                   @   s   e Zd ZdZdS )ÚUngetBufferFullzDAn attempt was made to unget a token when the unget buffer was full.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úC/var/www/html/gps/gps/lib/python3.10/site-packages/dns/tokenizer.pyr   '   s    r   c                   @   s‚   e Zd ZdZd!dd„Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ ZdS )"ÚTokenzŽA DNS zone file format token.

    ttype: The token type
    value: The token value
    has_escape: Does the token value contain escapes?
    Ú FNc                 C   s   || _ || _|| _|| _dS )zInitialize a token instance.N)ÚttypeÚvalueÚ
has_escapeÚcomment)Úselfr   r   r   r   r   r   r   Ú__init__3   s   
zToken.__init__c                 C   ó
   | j tkS ©N)r   ÚEOF©r   r   r   r   Úis_eof;   ó   
zToken.is_eofc                 C   r   r   )r   ÚEOLr!   r   r   r   Úis_eol>   r#   zToken.is_eolc                 C   r   r   )r   Ú
WHITESPACEr!   r   r   r   Úis_whitespaceA   r#   zToken.is_whitespacec                 C   r   r   )r   Ú
IDENTIFIERr!   r   r   r   Úis_identifierD   r#   zToken.is_identifierc                 C   r   r   )r   ÚQUOTED_STRINGr!   r   r   r   Úis_quoted_stringG   r#   zToken.is_quoted_stringc                 C   r   r   )r   ÚCOMMENTr!   r   r   r   Ú
is_commentJ   r#   zToken.is_commentc                 C   r   r   )r   Ú	DELIMITERr!   r   r   r   Úis_delimiterM   r#   zToken.is_delimiterc                 C   s   | j tkp	| j tkS r   )r   r$   r    r!   r   r   r   Úis_eol_or_eofP   s   zToken.is_eol_or_eofc                 C   s&   t |tƒsdS | j|jko| j|jkS )NF©Ú
isinstancer   r   r   ©r   Úotherr   r   r   Ú__eq__S   ó
   

ÿzToken.__eq__c                 C   s&   t |tƒsdS | j|jkp| j|jkS )NTr1   r3   r   r   r   Ú__ne__Y   r6   zToken.__ne__c                 C   s   d| j | jf S )Nz%d "%s")r   r   r!   r   r   r   Ú__str___   s   zToken.__str__c                 C   s  | j s| S d}t| jƒ}d}||k r†| j| }|d7 }|dkr~||kr'tjj‚| j| }|d7 }| ¡ r~||kr<tjj‚| j| }|d7 }||krMtjj‚| j| }|d7 }| ¡ r^| ¡ sbtjj‚t|ƒd t|ƒd  t|ƒ }|dkrztjj‚t	|ƒ}||7 }||k st
| j|ƒS )Nr   r   r	   ú\éd   é
   éÿ   )r   Úlenr   ÚdnsÚ	exceptionÚUnexpectedEndÚisdigitÚSyntaxErrorÚintÚchrr   r   ©r   Ú	unescapedÚlÚiÚcÚc2Úc3Ú	codepointr   r   r   Úunescapeb   s>   




 ézToken.unescapec                 C   s*  d}t | jƒ}d}||k r| j| }|d7 }|dkrƒ||kr"tjj‚| j| }|d7 }| ¡ r|||kr7tjj‚| j| }|d7 }||krHtjj‚| j| }|d7 }| ¡ rY| ¡ s]tjj‚t|ƒd t|ƒd  t|ƒ }|dkrutjj‚|d| 7 }n|| ¡ 7 }n|| ¡ 7 }||k st	| j
t|ƒƒS )	Nó    r   r	   r9   r:   r;   r<   s   %c)r=   r   r>   r?   r@   rA   rB   rC   Úencoder   r   ÚbytesrE   r   r   r   Úunescape_to_bytes‚   s<   




 á zToken.unescape_to_bytes)r   FN)r   r   r   r   r   r"   r%   r'   r)   r+   r-   r/   r0   r5   r7   r8   rM   rQ   r   r   r   r   r   +   s     
 r   c                   @   sè   e Zd ZdZejddfdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
d3dd„Zdd„ Zdd„ ZeZdd„ Zd4dd„Zdd„ Zd4dd„Zd4dd„Zd4dd „Zd5d!d"„Zd#d$„ Zd5d%d&„Zd'd(„ Zd6d)d*„Zd6d+d,„Zd-d.„ Zd/d0„ Zd1d2„ ZdS )7Ú	Tokenizeraî  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.
    Nc                 C   s´   t |tƒrt |¡}|du rd}n!t |tƒr$t | ¡ ¡}|du r#d}n|du r2|tju r0d}nd}|| _d| _	d| _
d| _d| _d| _t| _d| _|| _|du rUtjj}|| _dS )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	   )r2   ÚstrÚioÚStringIOrP   ÚdecodeÚsysÚstdinÚfileÚungotten_charÚungotten_tokenÚ	multilineÚquotingÚeofÚ_DELIMITERSÚ
delimitersÚline_numberÚfilenamer>   ÚnameÚ	IDNA_2003Ú
idna_codec)r   Úfrb   re   r   r   r   r   â   s4   

€
€

zTokenizer.__init__c                 C   s`   | j du r(| jrd}|S | j d¡}|dkrd| _|S |dkr&|  jd7  _|S | j }d| _ |S )z%Read a character from input.
        Nr   r	   Tr   )rZ   r^   rY   Úreadra   ©r   rI   r   r   r   Ú	_get_char  s   

øûþzTokenizer._get_charc                 C   s   | j | jfS )z·Return 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.
        )rb   ra   r!   r   r   r   Úwhere  s   zTokenizer.wherec                 C   ó   | j durt‚|| _ dS )a%  Unget 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)rZ   r   rh   r   r   r   Ú_unget_char'  s   

zTokenizer._unget_charc                 C   sD   d}	 |   ¡ }|dkr|dkr|dks| js|  |¡ |S |d7 }q)aF  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   Tr   r   r   r	   )ri   r\   rl   )r   ÚskippedrI   r   r   r   Úskip_whitespace7  s   
úzTokenizer.skip_whitespaceFc                 C   sŠ  | j dur| j }d| _ | ¡ r|r|S n| ¡ r|r|S n|S |  ¡ }|r.|dkr.ttdƒS d}t}d}	 |  ¡ }|dksB|| jv rô|dkrM| j	rMt
jj‚|dkrî|tkrî|dkre|  jd7  _|  ¡  q4|d	kr~| jdkrrt
jj‚|  jd8  _|  ¡  q4|d
kr™| j	sŽd| _	t| _t}q4d| _	t| _|  ¡  q4|dkr¢ttdƒS |dkré	 |  ¡ }|dks³|dkr´n||7 }q§|rÅ|  |¡ tt|ƒS |dkrØ| jrÒt
j d¡‚tt|dS | jrâ|  ¡  d}q4ttd|dS |}t}n|  |¡ n5| j	r|dkrt
j d¡‚|dkr$||7 }d}|  ¡ }|dks |dkr$| j	s$t
jj‚||7 }q5|dkr?|tkr?| jr=t
j d¡‚t}t|||ƒS )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 stringr9   )r[   r'   r-   rn   r   r&   r(   ri   r`   r]   r>   r?   r@   r*   r\   rB   Ú_QUOTING_DELIMITERSr_   r$   rl   r,   r    r.   )r   Úwant_leadingÚwant_commentÚtokenrm   r   r   rI   r   r   r   ÚgetK  s¬   
ÿÿ


ü

ÿ

ºGzTokenizer.getc                 C   rk   )a  Unget 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   rr   r   r   r   Úunget¹  s   

zTokenizer.ungetc                 C   s   |   ¡ }| ¡ r
t‚|S )zHReturn the next item in an iteration.

        Returns a Token.
        )rs   r"   ÚStopIterationrt   r   r   r   ÚnextÉ  s   zTokenizer.nextc                 C   s   | S r   r   r!   r   r   r   Ú__iter__Ö  s   zTokenizer.__iter__r;   c                 C   sB   |   ¡  ¡ }| ¡ stj d¡‚|j ¡ stj d¡‚t|j|ƒS )z¤Read 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)	rs   rM   r)   r>   r?   rB   r   rA   rC   )r   Úbaserr   r   r   r   Úget_intÛ  s   
zTokenizer.get_intc                 C   s,   |   ¡ }|dk s|dkrtj d| ¡‚|S )z¸Read 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   r<   z#%d is not an unsigned 8-bit integer©r{   r>   r?   rB   )r   r   r   r   r   Ú	get_uint8ê  s   	ÿzTokenizer.get_uint8c                 C   sH   | j |d}|dk s|dkr"|dkrtj d| ¡‚tj d| ¡‚|S )z¸Read 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.
        ©rz   r   iÿÿ  é   z*%o is not an octal unsigned 16-bit integerz$%d is not an unsigned 16-bit integerr|   ©r   rz   r   r   r   r   Ú
get_uint16ù  s   	ÿÿzTokenizer.get_uint16c                 C   ó0   | j |d}|dk s|dkrtj d| ¡‚|S )z¸Read 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€   r   r   r   Ú
get_uint32  ó   	ÿzTokenizer.get_uint32c                 C   r‚   )z¸Read 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€   r   r   r   Ú
get_uint48  r„   zTokenizer.get_uint48c                 C   sL   |   ¡  ¡ }| ¡ s| ¡ stj d¡‚|r#t|jƒ|kr#tj d¡‚|jS )zúRead 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)	rs   rM   r)   r+   r>   r?   rB   r=   r   )r   Ú
max_lengthrr   r   r   r   Ú
get_string*  s   
zTokenizer.get_stringc                 C   s&   |   ¡  ¡ }| ¡ stj d¡‚|jS )z—Read the next token, which should be an identifier.

        Raises dns.exception.SyntaxError if not an identifier.

        Returns a string.
        ry   )rs   rM   r)   r>   r?   rB   r   rt   r   r   r   Úget_identifier;  s   zTokenizer.get_identifierc                 C   sD   g }	 |   ¡ }| ¡ r|  |¡ 	 |S | |¡ t|ƒ|kr!	 |S q)zµReturn 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.
        )rs   r0   ru   Úappendr=   )r   Ú
max_tokensÚtokensrr   r   r   r   Úget_remainingH  s   

ýøzTokenizer.get_remainingc                 C   sF   d}	 |   ¡  ¡ }| ¡ r|  |¡ 	 |S | ¡ stjj‚||j7 }q)a  Read the remaining tokens on the line, which should be identifiers.

        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   )	rs   rM   r0   ru   r)   r>   r?   rB   r   )r   Úsrr   r   r   r   Ú!concatenate_remaining_identifiers[  s   	
ý
ùz+Tokenizer.concatenate_remaining_identifiersc                 C   s8   |  ¡ s
tj d¡‚tj |j|| j¡}| |p||¡S )zTry to interpret the token as a DNS name.

        Raises dns.exception.SyntaxError if not a name.

        Returns a dns.name.Name.
        ry   )	r)   r>   r?   rB   rc   Ú	from_textr   re   Úchoose_relativity)r   rr   ÚoriginÚ
relativizeÚrelativize_torc   r   r   r   Úas_nameo  s   zTokenizer.as_namec                 C   s   |   ¡ }|  ||||¡S )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.
        )rs   r”   )r   r‘   r’   r“   rr   r   r   r   Úget_name{  s   zTokenizer.get_namec                 C   s,   |   ¡ }| ¡ stj d|j|jf ¡‚|S )znRead 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")rs   r0   r>   r?   rB   r   r   rt   r   r   r   Úget_eol_as_token†  s   ÿÿzTokenizer.get_eol_as_tokenc                 C   s
   |   ¡ jS r   )r–   r   r!   r   r   r   Úget_eol”  r#   zTokenizer.get_eolc                 C   s.   |   ¡  ¡ }| ¡ stj d¡‚tj |j¡S )z¾Read 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.
        ry   )	rs   rM   r)   r>   r?   rB   Úttlr   r   rt   r   r   r   Úget_ttl—  s   	zTokenizer.get_ttl)FF)r;   r   )NFN)r   r   r   r   rW   rX   r   ri   rj   rl   rn   rs   ru   rw   Ú__next__rx   r{   r}   r   rƒ   r…   r‡   rˆ   rŒ   rŽ   r”   r•   r–   r—   r™   r   r   r   r   rR   Á   s4     *	
n







rR   )r   rT   rW   Údns.exceptionr>   Údns.nameÚdns.ttlr_   ro   r    r$   r&   r(   r*   r,   r.   r?   ÚDNSExceptionr   r   rR   r   r   r   r   Ú<module>   s&    