grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a àMÒe\ã@s¢dZddlZddlZddlmZmZmZmZddlZ ddl Z ddl Z hd£Z dhZ dZdZdZdZd Zd Zd ZGd d „d e jjƒZGdd„dƒZGdd„dƒZdS)zTokenize DNS zone file formatéN)ÚAnyÚListÚOptionalÚTuple>ú ú"Ú ú(ú;ú ú)rééééééc@seZdZdZdS)ÚUngetBufferFullzDAn attempt was made to unget a token when the unget buffer was full.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú1/usr/lib/python3.9/site-packages/dns/tokenizer.pyr(src@sÎeZdZdZd#eeeeedœdd„Z edœd d „Z edœd d „Z edœd d„Z edœdd„Z edœdd„Zedœdd„Zedœdd„Zedœdd„Zdd„Zdd„Zdd„Zddœdd „Zddœ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ÚcommentcCs||_||_||_||_dS)zInitialize a token instance.Nr)Úselfrrrr rrrÚ__init__4s zToken.__init__©ÚreturncCs |jtkS©N)rÚEOF©r!rrrÚis_eofBsz Token.is_eofcCs |jtkSr%)rÚEOLr'rrrÚis_eolEsz Token.is_eolcCs |jtkSr%)rÚ WHITESPACEr'rrrÚ is_whitespaceHszToken.is_whitespacecCs |jtkSr%)rÚ IDENTIFIERr'rrrÚ is_identifierKszToken.is_identifiercCs |jtkSr%)rÚ QUOTED_STRINGr'rrrÚis_quoted_stringNszToken.is_quoted_stringcCs |jtkSr%)rÚCOMMENTr'rrrÚ is_commentQszToken.is_commentcCs |jtkSr%)rÚ DELIMITERr'rrrÚ is_delimiterTszToken.is_delimitercCs|jtkp|jtkSr%)rr)r&r'rrrÚ is_eol_or_eofWszToken.is_eol_or_eofcCs&t|tƒsdS|j|jko$|j|jkS)NF©Ú isinstancerrr©r!ÚotherrrrÚ__eq__Zs z Token.__eq__cCs&t|tƒsdS|j|jkp$|j|jkS)NTr6r8rrrÚ__ne___s z Token.__ne__cCsd|j|jfS)Nz%d "%s")rrr'rrrÚ__str__dsz Token.__str__cCs|js |Sd}t|jƒ}d}||k�r|j|}|d7}|dkrþ||krPtjj‚|j|}|d7}| ¡rþ||krztjj‚|j|}|d7}||krœtjj‚|j|}|d7}| ¡r¾| ¡sÆtjj‚t|ƒdt|ƒdt|ƒ}|dkrötjj‚t |ƒ}||7}qt |j |ƒS)Nrrr ú\édé éÿ) rÚlenrÚdnsÚ exceptionÚ UnexpectedEndÚisdigitÚ SyntaxErrorÚintÚchrrr©r!Z unescapedÚlÚiÚcZc2Zc3Z codepointrrrÚunescapegs<        zToken.unescapecCs(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|ƒdt|ƒdt|ƒ}|dkrîtjj‚|d|7}n || ¡7}q|| ¡7}qt |j t |ƒƒS) Nórr r=r>r?r@s%c) rArrBrCrDrErFrGÚencoderrÚbytesrIrrrÚunescape_to_bytes‡s:        zToken.unescape_to_bytes)rFN)rrrrrGrÚboolrÚstrr"r(r*r,r.r0r2r4r5r:r;r<rMrQrrrrr,s. ûû  rc@sØeZdZdZejddfeeeee j j dœdd„Z edœdd„Z eeefdœd d „Zedd œd d „Zedœdd„Zd>eeedœdd„Zeddœdd„Zdd„ZeZdd„Zd?eedœdd„Zedœdd „Zd@eedœd!d"„ZdAeedœd#d$„ZdBeedœd%d&„ZdCeeed'œd(d)„Zedœd*d+„Z dDeee!ed,œ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œdzzrFr )r7rSÚioÚStringIOrPÚdecodeÚsysÚstdinÚfileÚ ungotten_charÚungotten_tokenÚ multilineÚquotingÚeofÚ _DELIMITERSÚ delimitersÚ line_numberrVrBÚnameZ IDNA_2003rW)r!rUrVrWrrrr"çs0     zTokenizer.__init__r#cCsZ|jdurJ|jrd}qV|j d¡}|dkr2d|_qV|dkrV|jd7_n |j}d|_|S)zRead a character from input.Nrr Tr)r^rbr]Úreadre©r!rLrrrÚ _get_chars  zTokenizer._get_charcCs |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. )rVrer'rrrÚwhere)szTokenizer.where)rLr$cCs|jdurt‚||_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^rrhrrrÚ _unget_char2s zTokenizer._unget_charcCsFd}| ¡}|dkr8|dkr8|dks*|js8| |¡|S|d7}qdS)aFConsume 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. rr rrr N)rir`rk)r!ÚskippedrLrrrÚskip_whitespaceBs  zTokenizer.skip_whitespaceF)Ú want_leadingÚ want_commentr$c Cs¼|jdur>|j}d|_| ¡r(|r>|Sn| ¡r:|r>|Sn|S| ¡}|r\|dkr\ttdƒSd}t}d}| ¡}|dks„||jv�r|dkrš|j ršt j j ‚|dk�r|t k�r|dkrÒ|jd7_| ¡qh�q|dk�r |jdkrît j j‚|jd8_| ¡qh�q|d k�rH|j �s0d |_ t|_t }qhnd|_ t|_| ¡qhn¾|d k�r\ttd ƒS|d k�rþ| ¡}|d k�s’|dk�r†�q’||7}�qf|�r¬| |¡tt|ƒS|dk�rÖ|j�rÊt j  d ¡‚tt|d�S|j�rî| ¡d}qhnttd |d�Sn|}t}n | |¡�q„nb|j �r8|d k�r8t j  d¡‚nB|dk�rz||7}d }| ¡}|dk�sr|d k�rz|j �szt j j ‚||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. Nrr rFr r r rTrr zunbalanced parentheses)r znewline in quoted stringr=)r_r,r2rmrr+r-rirdrarBrCrDr/r`rFÚ_QUOTING_DELIMITERSrcr)rkr1r&r3) r!rnroZutokenrlÚtokenrrrLrrrÚgetVs              ÿ     z Tokenizer.get)rqr$cCs|jdurt‚||_dS)aUnget 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!rqrrrÚungetÅs zTokenizer.ungetcCs| ¡}| ¡rt‚|S)zHReturn the next item in an iteration. Returns a Token. )rrr(Ú StopIterationrsrrrÚnextÕszTokenizer.nextcCs|Sr%rr'rrrÚ__iter__âszTokenizer.__iter__r?)Úbaser$cCsB| ¡ ¡}| ¡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) rrrMr.rBrCrFrrErG)r!rxrqrrrÚget_intçs     zTokenizer.get_intcCs,| ¡}|dks|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. rr@z#%d is not an unsigned 8-bit integer©rzrBrCrF)r!rrrrÚ get_uint8ös ÿzTokenizer.get_uint8cCsJ|j|d�}|dks|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. ©rxriÿÿéz*%o is not an octal unsigned 16-bit integerz$%d is not an unsigned 16-bit integerr{©r!rxrrrrÚ get_uint16s ÿÿzTokenizer.get_uint16cCs0|j|d�}|dks|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}rlÿÿz$%d is not an unsigned 32-bit integerr{rrrrÚ get_uint32s ÿzTokenizer.get_uint32cCs0|j|d�}|dks|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}rlÿÿÿz$%d is not an unsigned 48-bit integerr{rrrrÚ get_uint48+s ÿzTokenizer.get_uint48)Ú max_lengthr$cCsL| ¡ ¡}| ¡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) rrrMr.r0rBrCrFrAr)r!rƒrqrrrÚ get_string;s   zTokenizer.get_stringcCs&| ¡ ¡}| ¡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)rrrMr.rBrCrFrrsrrrÚget_identifierLs  zTokenizer.get_identifier)Ú max_tokensr$cCs>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. )rrr5rtÚappendrA)r!r†ÚtokensrqrrrÚ get_remainingYs   zTokenizer.get_remaining)Ú allow_emptyr$cCsXd}| ¡ ¡}| ¡r$| |¡q@| ¡s4tjj‚||j7}q|sT|sTtj d¡‚|S)aRead 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. rzexpecting another identifier) rrrMr5rtr.rBrCrFr)r!rŠÚsrqrrrÚ!concatenate_remaining_identifiersls     z+Tokenizer.concatenate_remaining_identifiers)rqÚoriginÚ relativizeÚ relativize_tor$cCs8| ¡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.rBrCrFrfÚ from_textrrWZchoose_relativity)r!rqr�rŽr�rfrrrÚas_name…s  zTokenizer.as_name)r�rŽr�r$cCs| ¡}| ||||¡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. )rrr‘)r!r�rŽr�rqrrrÚget_name—s zTokenizer.get_namecCs,| ¡}| ¡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")rrr5rBrCrFrrrsrrrÚget_eol_as_token§s ÿzTokenizer.get_eol_as_tokencCs | ¡jSr%)r“rr'rrrÚget_eolµszTokenizer.get_eolcCs.| ¡ ¡}| ¡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) rrrMr.rBrCrFZttlr�rrsrrrÚget_ttl¸s  zTokenizer.get_ttl)FF)r?)r?)r?)r?)N)N)F)NFN)NFN)*rrrrr[r\rrrSrBrfZ IDNACodecr"rirrGrjrkrmrRrrrrtrvÚ__next__rwrzr|r€r�r‚r„r…rr‰rŒÚNamer‘r’r“r”r•rrrrrTÆsb"ü ü 1 o  û  ú ü  û rT)rrXr[ÚtypingrrrrZ dns.exceptionrBZdns.nameZdns.ttlrcrpr&r)r+r-r/r1r3rCZ DNSExceptionrrrTrrrrÚs&