관리-도구
편집 파일: tokenizer.cpython-39.opt-1.pyc
a �����M�e\����������������������@���s����d�Z�ddlZddlZddlmZmZmZmZ�ddlZ ddl Z ddlZ h�d�ZdhZ dZdZdZdZd Zd ZdZG�dd ��d e jj�ZG�dd��d�ZG�dd��d�ZdS�)zTokenize DNS zone file format�����N)�Any�List�Optional�Tuple>���� �"� �(�;� �)r���������������������������c�������������������@���s���e�Zd�ZdZdS�)�UngetBufferFullzDAn attempt was made to unget a token when the unget buffer was full.N)�__name__� __module__�__qualname__�__doc__��r���r����1/usr/lib/python3.9/site-packages/dns/tokenizer.pyr���(���s���r���c�������������������@���s����e�Zd�ZdZd#eeeee�d�dd�Z ed�d d �Z ed�dd�Zed�d d�Zed�dd�Z ed�dd�Zed�dd�Zed�dd�Zed�dd�Zdd��Zdd��Zdd��Zd�d�dd �Zd�d�d!d"�ZdS�)$�Tokenz�A DNS zone file format token. ttype: The token type value: The token value has_escape: Does the token value contain escapes? ��FN��ttype�value� has_escape�commentc�����������������C���s���||�_�||�_||�_||�_dS�)zInitialize a token instance.Nr���)�selfr���r���r���r ���r���r���r����__init__4���s���� zToken.__init__��returnc�����������������C���s ���|�j�tkS��N)r����EOF�r!���r���r���r����is_eofB���s����zToken.is_eofc�����������������C���s ���|�j�tkS�r%���)r����EOLr'���r���r���r����is_eolE���s����zToken.is_eolc�����������������C���s ���|�j�tkS�r%���)r���� WHITESPACEr'���r���r���r���� is_whitespaceH���s����zToken.is_whitespacec�����������������C���s ���|�j�tkS�r%���)r���� IDENTIFIERr'���r���r���r���� is_identifierK���s����zToken.is_identifierc�����������������C���s ���|�j�tkS�r%���)r���� QUOTED_STRINGr'���r���r���r����is_quoted_stringN���s����zToken.is_quoted_stringc�����������������C���s ���|�j�tkS�r%���)r����COMMENTr'���r���r���r���� is_commentQ���s����zToken.is_commentc�����������������C���s ���|�j�tkS�r%���)r���� DELIMITERr'���r���r���r����is_delimiterT���s����zToken.is_delimiterc�����������������C���s���|�j�tkp|�j�tkS�r%���)r���r)���r&���r'���r���r���r���� is_eol_or_eofW���s����zToken.is_eol_or_eofc�����������������C���s&���t�|t�sdS�|�j|jko$|�j|jkS�)NF�� isinstancer���r���r����r!����otherr���r���r����__eq__Z���s���� zToken.__eq__c�����������������C���s&���t�|t�sdS�|�j|jkp$|�j|jkS�)NTr6���r8���r���r���r����__ne___���s���� zToken.__ne__c�����������������C���s���d|�j�|�jf�S�)Nz%d "%s")r���r���r'���r���r���r����__str__d���s����z Token.__str__c�����������������C���s��|�j�s |�S�d}t|�j�}d}||k��r|�j|�}|d7�}|dkr�||krPtjj�|�j|�}|d7�}|���r�||krztjj�|�j|�}|d7�}||kr�tjj�|�j|�}|d7�}|���r�|���s�tjj�t|�d�t|�d��t|��}|dkr�tjj�t |�}||7�}qt |�j|�S�)Nr���r���r ����\�d���� �������)r����lenr����dns� exception� UnexpectedEnd�isdigit�SyntaxError�int�chrr���r����r!���Z unescaped�l�i�cZc2Zc3Z codepointr���r���r����unescapeg���s<���� zToken.unescapec�����������������C���s(��d}t�|�j�}d}||k��r|�j|�}|d7�}|dk�r ||krHtjj�|�j|�}|d7�}|���r�||krrtjj�|�j|�}|d7�}||kr�tjj�|�j|�}|d7�}|���r�|���s�tjj�t|�d�t|�d��t|��}|dkr�tjj�|d|�7�}n||���7�}q||���7�}qt |�j t|��S�) N�����r���r ���r=���r>���r?���r@���s���%c)rA���r���rB���rC���rD���rE���rF���rG����encoder���r����bytesrI���r���r���r����unescape_to_bytes����s:���� zToken.unescape_to_bytes)r���FN)r���r���r���r���rG���r����boolr����strr"���r(���r*���r,���r.���r0���r2���r4���r5���r:���r;���r<���rM���rQ���r���r���r���r���r���,���s.��� ����� r���c�������������������@���s���e�Zd�ZdZejddfeee�ee j j�d�dd�Zed�dd�Z eeef�d�d d �Zedd�dd �Zed�dd�Zd>eeed�dd�Zedd�dd�Zdd��ZeZdd��Zd?eed�dd�Zed�dd �Zd@eed�d!d"�ZdAeed�d#d$�ZdBeed�d%d&�ZdCee�ed'�d(d)�Zed�d*d+�Z dDee�e!e�d,�d-d.�Z"dEeed/�d0d1�Z#dFeee j j$�eee j j$�e j j$d2�d3d4�Z%dGee j j$�eee j j$�e j j$d5�d6d7�Z&ed�d8d9�Z'ed�d:d;�Z(ed�d<d=�Z)dS�)H� 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. N)�f�filename� idna_codecc�����������������C���s����t�|t�r"t�|�}|du�rdd}nBt�|t�rHt�|����}|du�rdd}n|du�rd|tju�r`d}nd}||�_d|�_ d|�_ d|�_d|�_d|�_ t|�_d|�_||�_|du�r�tjj|�_n||�_dS�)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 ���)r7���rS����io�StringIOrP����decode�sys�stdin�file� ungotten_char�ungotten_token� multiline�quoting�eof�_DELIMITERS� delimiters�line_numberrV���rB����nameZ IDNA_2003rW���)r!���rU���rV���rW���r���r���r���r"�������s0���� zTokenizer.__init__r#���c�����������������C���sZ���|�j�du�rJ|�jrd}qV|�j�d�}|dkr2d|�_qV|dkrV|��jd7��_n|�j�}d|�_�|S�)zRead a character from input.Nr���r ���Tr���)r^���rb���r]����readre����r!���rL���r���r���r���� _get_char��s���� zTokenizer._get_charc�����������������C���s���|�j�|�jfS�)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. )rV���re���r'���r���r���r����where)��s����zTokenizer.where)rL���r$���c�����������������C���s���|�j�durt�||�_�dS�)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)r^���r���rh���r���r���r����_unget_char2��s���� zTokenizer._unget_charc�����������������C���sF���d}|�����}|dkr8|dkr8|dks*|�js8|��|��|S�|d7�}qdS�)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���r���r���r���r ���N)ri���r`���rk���)r!����skippedrL���r���r���r����skip_whitespaceB��s���� zTokenizer.skip_whitespaceF)�want_leading�want_commentr$���c����������� ������C���s���|�j�dur>|�j�}d|�_�|���r(|r>|S�n|���r:|r>|S�n|S�|����}|r\|dkr\ttd�S�d}t}d}|����}|dks�||�jv��r|dkr�|�j r�t jj�|dk�r|t k�r|dkr�|��jd7��_|�����qh�q|dk�r |�jdkr�t jj�|��jd8��_|�����qh�q|d k�rH|�j �s0d |�_ t|�_t }qhnd|�_ t|�_|�����qhn�|dk�r\ttd�S�|dk�r�|����}|dk�s�|dk�r��q�||7�}�qf|�r�|��|��tt|�S�|dk�r�|�j�r�t j�d ��tt|d�S�|�j�r�|�����d}qhnttd|d�S�n|}t}n |��|���q�nb|�j �r8|dk�r8t j�d��nB|dk�rz||7�}d }|����}|dk�sr|dk�rz|�j �szt jj�||7�}qh|dk�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���Fr ���r ���r���r���Tr���r ���zunbalanced parentheses)r ���znewline in quoted stringr=���)r_���r,���r2���rm���r���r+���r-���ri���rd���ra���rB���rC���rD���r/���r`���rF����_QUOTING_DELIMITERSrc���r)���rk���r1���r&���r3���) r!���rn���ro���Zutokenrl����tokenr���r���rL���r���r���r����getV��s����� � z Tokenizer.get)rq���r$���c�����������������C���s���|�j�durt�||�_�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. token: the token to unget Raises UngetBufferFull: there is already an ungotten token N)r_���r����r!���rq���r���r���r����unget���s���� zTokenizer.ungetc�����������������C���s���|�����}|���rt�|S�)zHReturn the next item in an iteration. Returns a Token. )rr���r(���� StopIterationrs���r���r���r����next���s����zTokenizer.nextc�����������������C���s���|�S�r%���r���r'���r���r���r����__iter__���s����zTokenizer.__iter__r?���)�baser$���c�����������������C���sB���|��������}|���s tj�d��|j���s6tj�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 identifierzexpecting an integer) rr���rM���r.���rB���rC���rF���r���rE���rG���)r!���rx���rq���r���r���r����get_int���s���� zTokenizer.get_intc�����������������C���s,���|�����}|dk�s|dkr(tj�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�rz���rB���rC���rF���)r!���r���r���r���r���� get_uint8���s���� �zTokenizer.get_uint8c�����������������C���sJ���|�j�|d�}|dk�s|dkrF|dkr6tj�d|���ntj�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. �rx���r���i��������z*%o is not an octal unsigned 16-bit integerz$%d is not an unsigned 16-bit integerr{����r!���rx���r���r���r���r���� get_uint16��s���� ��zTokenizer.get_uint16c�����������������C���s0���|�j�|d�}|dk�s|dkr,tj�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��s���� �zTokenizer.get_uint32c�����������������C���s0���|�j�|d�}|dk�s|dkr,tj�d|���|S�)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+��s���� �zTokenizer.get_uint48)� max_lengthr$���c�����������������C���sL���|��������}|���s(|���s(tj�d��|rFt|j�|krFtj�d��|jS�)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. zexpecting a stringzstring too long) rr���rM���r.���r0���rB���rC���rF���rA���r���)r!���r����rq���r���r���r���� get_string;��s���� zTokenizer.get_stringc�����������������C���s&���|��������}|���s tj�d��|jS�)z�Read the next token, which should be an identifier. Raises dns.exception.SyntaxError if not an identifier. Returns a string. ry���)rr���rM���r.���rB���rC���rF���r���rs���r���r���r����get_identifierL��s����zTokenizer.get_identifier)� max_tokensr$���c�����������������C���s>���g�}|�����}|���r |��|��q:|�|��t|�|krq:q|S�)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. )rr���r5���rt����appendrA���)r!���r�����tokensrq���r���r���r���� get_remainingY��s���� zTokenizer.get_remaining)�allow_emptyr$���c�����������������C���sX���d}|��������}|���r$|��|��q@|���s4tjj�||j7�}q|sT|sTtj�d��|S�)a��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���zexpecting another identifier) rr���rM���r5���rt���r.���rB���rC���rF���r���)r!���r�����srq���r���r���r����!concatenate_remaining_identifiersl��s���� z+Tokenizer.concatenate_remaining_identifiers)rq����origin� relativize� relativize_tor$���c�����������������C���s8���|����stj�d��tj�|j||�j�}|�|p2||�S�)z�Try to interpret the token as a DNS name. Raises dns.exception.SyntaxError if not a name. Returns a dns.name.Name. ry���) r.���rB���rC���rF���rf���� from_textr���rW���Zchoose_relativity)r!���rq���r����r����r����rf���r���r���r����as_name���s���� zTokenizer.as_name)r����r����r����r$���c�����������������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. )rr���r����)r!���r����r����r����rq���r���r���r����get_name���s���� zTokenizer.get_namec�����������������C���s,���|�����}|���s(tj�d|j|jf���|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")rr���r5���rB���rC���rF���r���r���rs���r���r���r����get_eol_as_token���s�����zTokenizer.get_eol_as_tokenc�����������������C���s ���|�����jS�r%���)r����r���r'���r���r���r����get_eol���s����zTokenizer.get_eolc�����������������C���s.���|��������}|���s tj�d��tj�|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���) rr���rM���r.���rB���rC���rF���Zttlr����r���rs���r���r���r����get_ttl���s���� zTokenizer.get_ttl)FF)r?���)r?���)r?���)r?���)N)N)F)NFN)NFN)*r���r���r���r���r[���r\���r���r���rS���rB���rf���Z IDNACodecr"���ri���r���rG���rj���rk���rm���rR���r���rr���rt���rv����__next__rw���rz���r|���r����r����r����r����r����r���r����r�����Namer����r����r����r����r����r���r���r���r���rT�������sb���"� �1 o ���� ����� �rT���)r���rX���r[����typingr���r���r���r���Z dns.exceptionrB���Zdns.nameZdns.ttlrc���rp���r&���r)���r+���r-���r/���r1���r3���rC���ZDNSExceptionr���r���rT���r���r���r���r����<module>���s&����