AlkantarClanX12

Your IP : 18.225.72.161


Current Path : /lib/python3.6/site-packages/dns/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/dns/__pycache__/tokenizer.cpython-36.pyc

3

�b�W�G�@s�dZddlmZddlZddlZddlZddlZddlm	Z	m
Z
mZdddddddd�ZddiZ
dZdZd	Zd
ZdZdZd
ZGdd�dejj�ZGdd�de�ZGdd�de�ZdS)zTokenize DNS master file format�)�StringION�)�long�	text_type�binary_typeT)� �	�
�;�(�)�"r
�����c@seZdZdZdS)�UngetBufferFullzDAn attempt was made to unget a token when the unget buffer was full.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib/python3.6/tokenizer.pyr.src@s�eZdZdZd%dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)&�Tokenz�A DNS master file format token.

    @ivar ttype: The token type
    @type ttype: int
    @ivar value: The token value
    @type value: string
    @ivar has_escape: Does the token value contain escapes?
    @type has_escape: bool
    �FcCs||_||_||_dS)aInitialize a token instance.

        @param ttype: The token type
        @type ttype: int
        @param value: The token value
        @type value: string
        @param has_escape: Does the token value contain escapes?
        @type has_escape: bool
        N)�ttype�value�
has_escape)�selfrrrrrr�__init__?s
zToken.__init__cCs
|jtkS)N)r�EOF)rrrr�is_eofMszToken.is_eofcCs
|jtkS)N)r�EOL)rrrr�is_eolPszToken.is_eolcCs
|jtkS)N)r�
WHITESPACE)rrrr�
is_whitespaceSszToken.is_whitespacecCs
|jtkS)N)r�
IDENTIFIER)rrrr�
is_identifierVszToken.is_identifiercCs
|jtkS)N)r�
QUOTED_STRING)rrrr�is_quoted_stringYszToken.is_quoted_stringcCs
|jtkS)N)r�COMMENT)rrrr�
is_comment\szToken.is_commentcCs
|jtkS)N)r�	DELIMITER)rrrr�is_delimiter_szToken.is_delimitercCs|jtkp|jtkS)N)rr#r!)rrrr�
is_eol_or_eofbszToken.is_eol_or_eofcCs&t|t�sdS|j|jko$|j|jkS)NF)�
isinstancerrr)r�otherrrr�__eq__es
zToken.__eq__cCs&t|t�sdS|j|jkp$|j|jkS)NT)r0rrr)rr1rrr�__ne__ks
zToken.__ne__cCsd|j|jfS)Nz%d "%s")rr)rrrr�__str__qsz
Token.__str__cCs|js
|Sd}t|j�}d}x�||kr�|j|}|d7}|dkr�||krPtjj�|j|}|d7}|j�r�||krztjj�|j|}|d7}||kr�tjj�|j|}|d7}|j�o�|j�s�tjj�tt	|�dt	|�dt	|��}||7}qWt
|j|�S)Nrrr�\�d�
)r�lenr�dns�	exception�
UnexpectedEnd�isdigit�SyntaxError�chr�intrr)rZ	unescaped�l�i�c�c2�c3rrr�unescapets6





$zToken.unescapecCsdS)Nrr)rrrr�__len__�sz
Token.__len__cCst|j|jf�S)N)�iterrr)rrrr�__iter__�szToken.__iter__cCs$|dkr|jS|dkr|jSt�dS)Nrr)rr�
IndexError)rrArrr�__getitem__�s
zToken.__getitem__N)rF)rrrrr r"r$r&r(r*r,r.r/r2r3r4rErFrHrJrrrrr3s"

rc@s�eZdZdZejdfdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d(dd�Zdd�Zdd�Z
e
Zdd�Zdd�Zdd�Zdd�Zdd�Zd)dd�Zd*d d!�Zd+d"d#�Zd$d%�Zd&d'�ZdS),�	Tokenizera�A DNS master file format tokenizer.

    A token is a (type, value) tuple, where I{type} is an int, and
    I{value} is a string.  The valid types are EOF, EOL, WHITESPACE,
    IDENTIFIER, QUOTED_STRING, COMMENT, and DELIMITER.

    @ivar file: The file to tokenize
    @type file: file
    @ivar ungotten_char: The most recently ungotten character, or None.
    @type ungotten_char: string
    @ivar ungotten_token: The most recently ungotten token, or None.
    @type ungotten_token: (int, string) token tuple
    @ivar 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.
    @type multiline: int
    @ivar quoting: This variable is true if the tokenizer is currently
    reading a quoted string.
    @type quoting: bool
    @ivar eof: This variable is true if the tokenizer has encountered EOF.
    @type eof: bool
    @ivar delimiters: The current delimiter dictionary.
    @type delimiters: dict
    @ivar line_number: The current line number
    @type line_number: int
    @ivar filename: A filename that will be returned by the L{where} method.
    @type filename: string
    NcCs�t|t�r t|�}|dkr`d}n@t|t�rDt|j��}|dkr`d}n|dkr`|tjkr\d}nd}||_d|_d|_	d|_
d|_d|_t
|_d|_||_dS)a�Initialize a tokenizer instance.

        @param 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.
        @type f: file or string
        @param filename: the name of the filename that the L{where} method
        will return.
        @type filename: string
        Nz<string>z<stdin>z<file>rFr)r0rrr�decode�sys�stdin�file�
ungotten_char�ungotten_token�	multiline�quoting�eof�_DELIMITERS�
delimiters�line_number�filename)r�frXrrrr �s*


zTokenizer.__init__cCsZ|jdkrJ|jrd}qV|jjd�}|dkr2d|_qV|dkrV|jd7_n|j}d|_|S)z<Read a character from input.
        @rtype: string
        NrrTr	)rPrTrO�readrW)rrBrrr�	_get_char�s
zTokenizer._get_charcCs|j|jfS)z�Return the current location in the input.

        @rtype: (string, int) tuple.  The first item is the filename of
        the input, the second is the current line number.
        )rXrW)rrrr�where�szTokenizer.wherecCs|jdk	rt�||_dS)aEUnget 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.

        @param c: the character to unget
        @type c: string
        @raises UngetBufferFull: there is already an ungotten char
        N)rPr)rrBrrr�_unget_chars
zTokenizer._unget_charcCsLd}xB|j�}|dkr<|dkr<|dks.|jr<|j|�|S|d7}qWdS)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.

        @rtype: int
        rrrr	rN)r[rRr])r�skippedrBrrr�skip_whitespaces
zTokenizer.skip_whitespaceFc
CsT|jdk	r>|j}d|_|j�r(|r>|Sn|j�r:|r>|Sn|S|j�}|r\|dkr\ttd�Sd}t}d}�x�|j�}|dks�||jk�r|dkr�|j	r�t
jj�|dko�|t
k�r|dkr�|jd7_|j�ql�q|dk�r
|jdkr�t
jj�|jd8_|j�qln�|d	k�rH|j	�s0d
|_	t|_t
}qlnd|_	t|_|j�qln�|dk�r\ttd�S|dk�r�x,|j�}|dk�s�|dk�r�P||7}�qhW|�r�|j|�tt|�S|dk�r�|j�r�t
jjd
��tt�S|j�r�|j�d}qln
ttd�Sn|}t}n
|j|�P�n�|j	�r�|dk�r�|j�}|dk�r>t
jj�|j��r�|j�}|dk�rbt
jj�|j�}	|dk�r|t
jj�|j��o�|	j��s�t
jj�tt|�dt|�dt|	��}n|dk�rt
jjd��n:|dk�r||7}d
}|j�}|dk�s|dk�rt
jj�||7}qlW|dk�rH|t
k�rH|j�rDt
jjd
��t}t|||�S)aGet the next token.

        @param want_leading: If True, return a WHITESPACE token if the
        first character read is whitespace.  The default is False.
        @type want_leading: bool
        @param want_comment: If True, return a COMMENT token if the
        first token read is a comment.  The default is False.
        @type want_comment: bool
        @rtype: Token object
        @raises dns.exception.UnexpectedEnd: input ended prematurely
        @raises dns.exception.SyntaxError: input was badly formed
        NrrrFrrrr
Tr	r
zunbalanced parenthesesr5r6r7znewline in quoted string)rQr&r,r_rr%r'r[rVrSr9r:r;r)rRr=�_QUOTING_DELIMITERSrUr#r]r+r!r-r<r>r?)
rZwant_leadingZwant_comment�tokenr^rrrBrCrDrrr�get%s�
















&

z
Tokenizer.getcCs|jdk	rt�||_dS)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.

        @param token: the token to unget
        @type token: Token object
        @raises UngetBufferFull: there is already an ungotten token
        N)rQr)rrarrr�unget�s
zTokenizer.ungetcCs|j�}|j�rt�|S)zLReturn the next item in an iteration.
        @rtype: (int, string)
        )rbr"�
StopIteration)rrarrr�next�szTokenizer.nextcCs|S)Nr)rrrrrH�szTokenizer.__iter__cCs@|j�j�}|j�s tjjd��|jj�s6tjjd��t|j�S)z|Read the next token and interpret it as an integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        zexpecting an identifierzexpecting an integer)	rbrEr(r9r:r=rr<r?)rrarrr�get_int�s
zTokenizer.get_intcCs,|j�}|dks|dkr(tjjd|��|S)z�Read the next token and interpret it as an 8-bit unsigned
        integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        r�z#%d is not an unsigned 8-bit integer)rfr9r:r=)rrrrr�	get_uint8�s

zTokenizer.get_uint8cCs,|j�}|dks|dkr(tjjd|��|S)z�Read the next token and interpret it as a 16-bit unsigned
        integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        ri��z$%d is not an unsigned 16-bit integer)rfr9r:r=)rrrrr�
get_uint16�s

zTokenizer.get_uint16cCsh|j�j�}|j�s tjjd��|jj�s6tjjd��t|j�}|dksT|td�krdtjjd|��|S)z�Read the next token and interpret it as a 32-bit unsigned
        integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        zexpecting an identifierzexpecting an integerrlz$%d is not an unsigned 32-bit integer)	rbrEr(r9r:r=rr<r)rrarrrr�
get_uint32�s


zTokenizer.get_uint32cCs.|j�j�}|j�p|j�s(tjjd��|jS)z}Read the next token and interpret it as a string.

        @raises dns.exception.SyntaxError:
        @rtype: string
        zexpecting a string)rbrEr(r*r9r:r=r)r�originrarrr�
get_string�szTokenizer.get_stringcCs&|j�j�}|j�s tjjd��|jS)z�Read the next token and raise an exception if it is not an identifier.

        @raises dns.exception.SyntaxError:
        @rtype: string
        zexpecting an identifier)rbrEr(r9r:r=r)rrkrarrr�get_identifier
szTokenizer.get_identifiercCs,|j�}|j�stjjd��tjj|j|�S)z�Read the next token and interpret it as a DNS name.

        @raises dns.exception.SyntaxError:
        @rtype: dns.name.Name objectzexpecting an identifier)rbr(r9r:r=�name�	from_textr)rrkrarrr�get_nameszTokenizer.get_namecCs.|j�}|j�s(tjjd|j|jf��|jS)z�Read the next token and raise an exception if it isn't EOL or
        EOF.

        @raises dns.exception.SyntaxError:
        @rtype: string
        z expected EOL or EOF, got %d "%s")rbr/r9r:r=rr)rrarrr�get_eol!szTokenizer.get_eolcCs.|j�j�}|j�s tjjd��tjj|j�S)Nzexpecting an identifier)	rbrEr(r9r:r=Zttlror)rrarrr�get_ttl0szTokenizer.get_ttl)FF)N)N)N)rrrrrMrNr r[r\r]r_rbrcre�__next__rHrfrhrirjrlrmrprqrrrrrrrK�s($	
{



rK)r�iorrMZ
dns.exceptionr9Zdns.nameZdns.ttlZ_compatrrrrUr`r!r#r%r'r)r+r-r:ZDNSExceptionr�objectrrKrrrr�<module>s0o