509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
¢báW‰G  ã               @   s´   d Z ddlmZ ddlZddlZddlZddlZddlm	Z	m
Z
mZ ddddddddœZddi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eƒZG dd„ deƒZdS )zTokenize DNS master file formaté    )ÚStringIONé   )ÚlongÚ	text_typeÚbinary_typeT)ú ú	Ú
ú;ú(ú)ú"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   ú/usr/lib/python3.6/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 d!„ Zd"d#„ Zd$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
    Ú Fc             C   s   || _ || _|| _dS )a  Initialize 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)Úselfr   r   r   r   r   r   Ú__init__?   s    
zToken.__init__c             C   s
   | j tkS )N)r   ÚEOF)r   r   r   r   Úis_eofM   s    zToken.is_eofc             C   s
   | j tkS )N)r   ÚEOL)r   r   r   r   Úis_eolP   s    zToken.is_eolc             C   s
   | j tkS )N)r   Ú
WHITESPACE)r   r   r   r   Úis_whitespaceS   s    zToken.is_whitespacec             C   s
   | j tkS )N)r   Ú
IDENTIFIER)r   r   r   r   Úis_identifierV   s    zToken.is_identifierc             C   s
   | j tkS )N)r   ÚQUOTED_STRING)r   r   r   r   Úis_quoted_stringY   s    zToken.is_quoted_stringc             C   s
   | j tkS )N)r   ÚCOMMENT)r   r   r   r   Ú
is_comment\   s    zToken.is_commentc             C   s
   | j tkS )N)r   Ú	DELIMITER)r   r   r   r   Úis_delimiter_   s    zToken.is_delimiterc             C   s   | j tkp| j tkS )N)r   r#   r!   )r   r   r   r   Úis_eol_or_eofb   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__e   s    
zToken.__eq__c             C   s&   t |tƒsdS | j|jkp$| j|jkS )NT)r0   r   r   r   )r   r1   r   r   r   Ú__ne__k   s    
zToken.__ne__c             C   s   d| j | jf S )Nz%d "%s")r   r   )r   r   r   r   Ú__str__q   s    zToken.__str__c             C   s  | j s
| S d}t| jƒ}d}xØ||k rô| j| }|d7 }|dkrê||krPtjj‚| j| }|d7 }|jƒ rê||krztjj‚| j| }|d7 }||krœtjj‚| j| }|d7 }|jƒ o¼|jƒ sÆtjj‚tt	|ƒd t	|ƒd  t	|ƒ ƒ}||7 }qW t
| j|ƒS )Nr   r   r   ú\éd   é
   )r   Úlenr   ÚdnsÚ	exceptionÚUnexpectedEndÚisdigitÚSyntaxErrorÚchrÚintr   r   )r   Z	unescapedÚlÚiÚcÚc2Úc3r   r   r   Úunescapet   s6    





$zToken.unescapec             C   s   dS )Nr   r   )r   r   r   r   Ú__len__“   s    zToken.__len__c             C   s   t | j| jfƒS )N)Úiterr   r   )r   r   r   r   Ú__iter__–   s    zToken.__iter__c             C   s$   |dkr| j S |dkr| jS t‚d S )Nr   r   )r   r   Ú
IndexError)r   rA   r   r   r   Ú__getitem__™   s
    zToken.__getitem__N)r   F)r   r   r   r   r    r"   r$   r&   r(   r*   r,   r.   r/   r2   r3   r4   rE   rF   rH   rJ   r   r   r   r   r   3   s"   

r   c               @   s´   e Zd ZdZejdfdd„Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
d(dd„Zdd„ Zdd„ ZeZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd)dd„Zd*d d!„Zd+d"d#„Zd$d%„ Zd&d'„ ZdS ),Ú	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
    Nc             C   sš   t |tƒr t|ƒ}|dkr`d}n@t |tƒrDt|jƒ ƒ}|dkr`d}n|dkr`|tjkr\d}nd}|| _d| _d| _	d| _
d| _d| _t| _d| _|| _dS )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>r   Fr   )r0   r   r   r   ÚdecodeÚsysÚstdinÚfileÚungotten_charÚungotten_tokenÚ	multilineÚquotingÚeofÚ_DELIMITERSÚ
delimitersÚline_numberÚfilename)r   ÚfrX   r   r   r   r    Á   s*    


zTokenizer.__init__c             C   sZ   | j dkrJ| jrd}qV| jjdƒ}|dkr2d| _qV|dkrV|  jd7  _n| j }d| _ |S )z<Read a character from input.
        @rtype: string
        Nr   r   Tr	   )rP   rT   rO   ÚreadrW   )r   rB   r   r   r   Ú	_get_charå   s    
zTokenizer._get_charc             C   s   | j | jfS )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.
        )rX   rW   )r   r   r   r   Úwhereø   s    zTokenizer.wherec             C   s   | j dk	rt‚|| _ dS )aE  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.

        @param c: the character to unget
        @type c: string
        @raises UngetBufferFull: there is already an ungotten char
        N)rP   r   )r   rB   r   r   r   Ú_unget_char  s    
zTokenizer._unget_charc             C   sL   d}xB| j ƒ }|dkr<|dkr<|dks.| j r<| j|ƒ |S |d7 }qW dS )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
        r   r   r   r	   r   N)r[   rR   r]   )r   ÚskippedrB   r   r   r   Úskip_whitespace  s    
zTokenizer.skip_whitespaceFc       
      C   sT  | j dk	r>| j }d| _ |jƒ r(|r>|S n|jƒ r:|r>|S n|S | jƒ }|r\|dkr\ttdƒS d}t}d}�x°| jƒ }|dksˆ|| jk�r|dkrž| j	ržt
jj‚|dko¬|tk�r|dkrÔ|  jd7  _| jƒ  ql�q|dk�r
| jdkrðt
jj‚|  jd8  _| jƒ  qlnö|d	k�rH| j	�s0d
| _	t| _t}qlnd| _	t| _| jƒ  qln¸|dk�r\ttdƒS |dk�røx,| jƒ }|dk�s„|dk�r†P ||7 }�qhW |�r®| j|ƒ tt|ƒS |dk�rÔ| j�rÌt
jjdƒ‚ttƒS | j�rì| jƒ  d}qln
ttdƒS n|}t}n
| j|ƒ P � nþ| j	�rÖ|dk�r¾| jƒ }|dk�r>t
jj‚|jƒ �rÔ| jƒ }|dk�rbt
jj‚| jƒ }	|dk�r|t
jj‚|jƒ �oŒ|	jƒ �s˜t
jj‚tt|ƒd t|ƒd  t|	ƒ ƒ}n|dk�rt
jjdƒ‚n:|dk�r||7 }d
}| jƒ }|dk�s|dk�rt
jj‚||7 }qlW |dk�rH|tk�rH| j�rDt
jjdƒ‚t}t|||ƒS )a  Get 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
        Nr   r   r   Fr   r   r   r   Tr	   r
   zunbalanced parenthesesr5   r6   r7   znewline in quoted string)rQ   r&   r,   r_   r   r%   r'   r[   rV   rS   r9   r:   r;   r)   rR   r=   Ú_QUOTING_DELIMITERSrU   r#   r]   r+   r!   r-   r<   r>   r?   )
r   Zwant_leadingZwant_commentÚtokenr^   r   r   rB   rC   rD   r   r   r   Úget%  sÀ    
















&

zTokenizer.getc             C   s   | j dk	rt‚|| _ dS )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)rQ   r   )r   ra   r   r   r   Úunget   s    
zTokenizer.ungetc             C   s   | j ƒ }|jƒ rt‚|S )zLReturn the next item in an iteration.
        @rtype: (int, string)
        )rb   r"   ÚStopIteration)r   ra   r   r   r   Únext°  s    zTokenizer.nextc             C   s   | S )Nr   )r   r   r   r   rH   ¼  s    zTokenizer.__iter__c             C   s@   | j ƒ jƒ }|jƒ s tjjdƒ‚|jjƒ s6tjjdƒ‚t|jƒS )z|Read the next token and interpret it as an integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        zexpecting an identifierzexpecting an integer)	rb   rE   r(   r9   r:   r=   r   r<   r?   )r   ra   r   r   r   Úget_intÁ  s    
zTokenizer.get_intc             C   s,   | j ƒ }|dk s|dkr(tjjd| ƒ‚|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)rf   r9   r:   r=   )r   r   r   r   r   Ú	get_uint8Ï  s
    
zTokenizer.get_uint8c             C   s,   | j ƒ }|dk s|dkr(tjjd| ƒ‚|S )z“Read the next token and interpret it as a 16-bit unsigned
        integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        r   iÿÿ  z$%d is not an unsigned 16-bit integer)rf   r9   r:   r=   )r   r   r   r   r   Ú
get_uint16Ý  s
    
zTokenizer.get_uint16c             C   sh   | j ƒ jƒ }|jƒ s tjjdƒ‚|jjƒ s6tjjdƒ‚t|jƒ}|dk sT|tdƒkrdtjjd| ƒ‚|S )z“Read the next token and interpret it as a 32-bit unsigned
        integer.

        @raises dns.exception.SyntaxError:
        @rtype: int
        zexpecting an identifierzexpecting an integerr   l        z$%d is not an unsigned 32-bit integer)	rb   rE   r(   r9   r:   r=   r   r<   r   )r   ra   r   r   r   r   Ú
get_uint32ë  s    


zTokenizer.get_uint32c             C   s.   | j ƒ jƒ }|jƒ p|jƒ s(tjjdƒ‚|jS )z}Read the next token and interpret it as a string.

        @raises dns.exception.SyntaxError:
        @rtype: string
        zexpecting a string)rb   rE   r(   r*   r9   r:   r=   r   )r   Úoriginra   r   r   r   Ú
get_stringþ  s    zTokenizer.get_stringc             C   s&   | j ƒ jƒ }|jƒ s tjjdƒ‚|jS )z’Read the next token and raise an exception if it is not an identifier.

        @raises dns.exception.SyntaxError:
        @rtype: string
        zexpecting an identifier)rb   rE   r(   r9   r:   r=   r   )r   rk   ra   r   r   r   Úget_identifier
  s    zTokenizer.get_identifierc             C   s,   | j ƒ }|jƒ stjjdƒ‚tjj|j|ƒS )z„Read the next token and interpret it as a DNS name.

        @raises dns.exception.SyntaxError:
        @rtype: dns.name.Name objectzexpecting an identifier)rb   r(   r9   r:   r=   ÚnameÚ	from_textr   )r   rk   ra   r   r   r   Úget_name  s    zTokenizer.get_namec             C   s.   | j ƒ }|jƒ s(tjjd|j|jf ƒ‚|jS )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")rb   r/   r9   r:   r=   r   r   )r   ra   r   r   r   Úget_eol!  s    zTokenizer.get_eolc             C   s.   | j ƒ jƒ }|jƒ s tjjdƒ‚tjj|jƒS )Nzexpecting an identifier)	rb   rE   r(   r9   r:   r=   Zttlro   r   )r   ra   r   r   r   Úget_ttl0  s    zTokenizer.get_ttl)FF)N)N)N)r   r   r   r   rM   rN   r    r[   r\   r]   r_   rb   rc   re   Ú__next__rH   rf   rh   ri   rj   rl   rm   rp   rq   rr   r   r   r   r   rK   ¢   s(   $	
{



rK   )r   Úior   rM   Zdns.exceptionr9   Zdns.nameZdns.ttlZ_compatr   r   r   rU   r`   r!   r#   r%   r'   r)   r+   r-   r:   ZDNSExceptionr   Úobjectr   rK   r   r   r   r   Ú<module>   s0   o