f\dZddlZddlZddlmZmZmZmZddlZ ddl Z ddl Z hdZ dhZ dZdZdZdZd Zd Zd ZGd d e j*j,ZGddZGddZy)zTokenize DNS zone file formatN)AnyListOptionalTuple>   "();r ceZdZdZy)UngetBufferFullzDAn attempt was made to unget a token when the unget buffer was full.N)__name__ __module__ __qualname____doc__V/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/dns/tokenizer.pyrr(sNrrc eZdZdZ ddedededeefdZ defd Z defd Z defd Z defd Z defd ZdefdZdefdZdefdZdZdZdZddZddZy)TokenzA DNS zone file format token. ttype: The token type value: The token value has_escape: Does the token value contain escapes? Nttypevalue has_escapecommentc<||_||_||_||_y)zInitialize a token instance.N)rr r!r")selfrr r!r"s r__init__zToken.__init__4s   $ rreturnc(|jtk(SN)rEOFr$s ris_eofz Token.is_eofBzzS  rc(|jtk(Sr()rEOLr*s ris_eolz Token.is_eolEr,rc(|jtk(Sr()r WHITESPACEr*s r is_whitespacezToken.is_whitespaceHzzZ''rc(|jtk(Sr()r IDENTIFIERr*s r is_identifierzToken.is_identifierKr3rc(|jtk(Sr()r QUOTED_STRINGr*s ris_quoted_stringzToken.is_quoted_stringNszz]**rc(|jtk(Sr()rCOMMENTr*s r is_commentzToken.is_commentQszzW$$rc(|jtk(Sr()r DELIMITERr*s r is_delimiterzToken.is_delimiterTszzY&&rcR|jtk(xs|jtk(Sr()rr.r)r*s r is_eol_or_eofzToken.is_eol_or_eofWszzS 5DJJ#$55rct|tsy|j|jk(xr|j|jk(S)NF isinstancerrr r$others r__eq__z Token.__eq__Zs4%'zzU[[(FTZZ5;;-FFrct|tsy|j|jk7xs|j|jk7S)NTrCrEs r__ne__z Token.__ne___s4%'zzU[[(EDJJ%++,EErc8d|j|jfzS)Nz%d "%s")rr r*s r__str__z Token.__str__dsDJJ 333rc@|js|Sd}t|j}d}||kr\|j|}|dz }|dk(r6||k\rtjj |j|}|dz }|j r||k\rtjj |j|}|dz }||k\rtjj |j|}|dz }|j r|j stjjt|dzt|dzzt|z}|dkDrtjjt|}||z }||kr\t|j|S)Nrr\d ) r!lenr dns exception UnexpectedEndisdigit SyntaxErrorintchrrrr$ unescapedlicc2c3 codepoints runescapezToken.unescapegsbK  O !e 1 A FADy6--555JJqMQ99;Av!mm999ABFAAv!mm999ABFAJJLRZZ\!mm777 #A s2w| ;c"g EI 3!mm777IA NI/!e0TZZ++rcvd}t|j}d}||kr||j|}|dz }|dk(rH||k\rtjj|j|}|dz }|j r||k\rtjj|j|}|dz }||k\rtjj|j|}|dz }|j r|j stjj t|dzt|dzzt|z}|dkDrtjj |d|zz }n'||jz }n||jz }||kr|t|jt|S) NrrrrNrOrPrQs%c) rRr rSrTrUrVrWrXencoderrbytesrZs runescape_to_byteszToken.unescape_to_bytess}2  O !e 1 A FADy6--555JJqMQ99;Av!mm999ABFAAv!mm999ABFAJJLRZZ\!mm777 #A s2w| ;c"g EI 3!mm777)!44I+IQXXZ' ?!e@TZZy!122r)rMFN)r&r)rrrrrXrboolrstrr%r+r/r2r6r9r<r?rArGrIrKrbrfrrrrr,s !%     # !!!!(t((t(+$+%D%'d'6t6G F 4,@<3rrc eZdZdZej ddfdedeedee jjfdZ defdZ deeeffd Zd eddfd Zdefd Zd)d ededefdZdeddfdZdZeZdZd*dedefdZdefdZd*dedefdZd*dedefdZd*dedefdZd+deedefdZdefdZ d+deede!efdZ"d,dedefd Z# d-ded!ee jjHd"ed#ee jjHde jjHf d$Z% d-d!ee jjHd"ed#ee jjHde jjHfd%Z&defd&Z'defd'Z(defd(Z)y). TokenizeraA 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. Nffilename idna_codecct|trtj|}|Td}nQt|tr(tj|j }|d}n||t jurd}nd}||_d|_ d|_ d|_ d|_ d|_ t|_d|_|J||_| t$j&j(|_y||_y)aInitialize 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. NzzzrFr)rDrhioStringIOredecodesysstdinfile ungotten_charungotten_token multilinequotingeof _DELIMITERS delimiters line_numberrlrSname IDNA_2003rm)r$rkrlrms rr%zTokenizer.__init__s( a  AA% 5 ! AHHJ'A% >(H'H ,0/3 %###   25((2D2DDO(DOrr&c|jU|jrd}|S|jjd}|dk(r d|_|S|dk(r|xjdz c_|S|j}d|_|S)zRead a character from input.NrMrTr)ruryrtreadr|r$r^s r _get_charzTokenizer._get_chars    %xxIINN1%7#DH  $Y$$)$""A!%D rc2|j|jfS)zReturn 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. )rlr|r*s rwherezTokenizer.where)s t//00rr^c6|jt||_y)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)rurrs r _unget_charzTokenizer._unget_char2s    )! !rcd} |j}|dk7r)|dk7r$|dk7s |js|j||S|dz }D)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)rrwr)r$skippedr^s rskip_whitespacezTokenizer.skip_whitespaceBsS ACxAIIdnn$$Q'"N qLG r want_leading want_commentc|j=|j}d|_|jr|r|S|jr|r|S|S|j}|r|dkDrt t dSd}t }d} |j}|dk(s||jvr|dk(r&|jrtjj|dk(r|tk7r|dk(r&|xjdz c_|j|d k(rO|jdkrtjj|xjdzc_|j|d k(rJ|jsd|_ t |_t} d|_ t"|_|j.|d k(rt t$d S|d k(r |j}|d k(s|dk(rn||z }!|r!|j'|t t(|S|dk(r<|jrtjjd t t*|S|jr|jd}t t$d |S|}t,}n|j'|n|jr$|d k(rtjjd|dk(rG||z }d}|j}|dk(s|d k(r&|jstjj||z }|dk(r:|tk7r1|jrtjjd t*}t |||S)aGet 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 rMFTr rr r rr zunbalanced parentheses)r"znewline in quoted stringrN)rvr2r<rrr1r5rr{rxrSrTrUr8rwrW_QUOTING_DELIMITERSrzr.rr;r)r>) r$rrutokenrtokenrr!r^s rgetz Tokenizer.getVs    *((F"&D ##%!M""$!M &&( GaKS) )  ABw!t.7t||--555B;5M#9Cx!+,,. c>>Q."%--";";;!+,,. c#||+/DL.ADO$1E$+0DL.9DO 002$d$S$//c $ 0A DyAG %!QJE  ( ,,Q/#(%#88"W#~~&)mm&?&?$<'"!"$)e#<<!^^ 002$&E$#(dE#BB !" )$$Q'!t)mm//0JKKd  ! NN$7qDy--555 QJEOP B;5M1~~mm//0HIIEUE:..rrc6|jt||_y)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)rvrr$rs rungetzTokenizer.ungets    *! !#rcR|j}|jrt|S)zHReturn the next item in an iteration. Returns a Token. )rr+ StopIterationrs rnextzTokenizer.nexts#   <<>  rc|Sr(rr*s r__iter__zTokenizer.__iter__s rbasec:|jj}|jstjj d|j jstjj dt|j |S)zRead 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) rrbr6rSrTrWr rVrX)r$rrs rget_intzTokenizer.get_intsq ##%""$--++,EF F{{""$--++,BC C5;;%%rc~|j}|dks|dkDr"tjjd|z|S)zRead 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. rrQz#%d is not an unsigned 8-bit integerrrSrTrW)r$r s r get_uint8zTokenizer.get_uint8sB  19 --++5=  rc|j|}|dks|dkDrI|dk(r"tjjd|ztjjd|z|S)zRead 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. rriz*%o is not an octal unsigned 16-bit integerz$%d is not an unsigned 16-bit integerrr$rr s r get_uint16zTokenizer.get_uint16so $ ' 19 qymm//@5Hmm//:UB rc|j|}|dks|dkDr"tjjd|z|S)zRead 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. rrlz$%d is not an unsigned 32-bit integerrrs r get_uint32zTokenizer.get_uint32sH $ ' 19 *--++6>  rc|j|}|dks|dkDr"tjjd|z|S)zRead 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. rrlz$%d is not an unsigned 48-bit integerrrs r get_uint48zTokenizer.get_uint48+sH $ ' 19/--++6>  r max_lengthcF|jj}|js/|jstj j d|r7t|j|kDrtj j d|jS)zRead 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) rrbr6r9rSrTrWrRr )r$rrs r get_stringzTokenizer.get_string;sx ##%##%)?)?)A--++,@A A #ekk*Z7--++,=> >{{rc|jj}|jstjj d|j S)zRead the next token, which should be an identifier. Raises dns.exception.SyntaxError if not an identifier. Returns a string. r)rrbr6rSrTrWr rs rget_identifierzTokenizer.get_identifierLsD ##%""$--++,EF F{{r max_tokenscg} |j}|jr|j| |S|j|t ||k(r |SW)zReturn 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. )rrArappendrR)r$rtokensrs r get_remainingzTokenizer.get_remainingYs`HHJE""$ 5!  MM% 6{j( r allow_emptycFd} |jj}|jr|j|n:|j st j j||jz }z|s!|st j jd|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. rMzexpecting another identifier) rrbrArr6rSrTrWr )r$rsrs r!concatenate_remaining_identifiersz+Tokenizer.concatenate_remaining_identifiersls HHJ'')E""$ 5!&&(mm///  Aq--++,JK Krorigin relativize relativize_toc|jstjjdtjj |j ||j}|j|xs||S)zTry to interpret the token as a DNS name. Raises dns.exception.SyntaxError if not a name. Returns a dns.name.Name. r) r6rSrTrWr} from_textr rmchoose_relativity)r$rrrrr}s ras_namezTokenizer.as_names^""$--++,EF Fxx!!%++vtG%%m&=vzJJrcJ|j}|j||||S)zRead 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$rrrrs rget_namezTokenizer.get_names$ ||E6:}EErc|j}|js8tjj d|j |j fz|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")rrArSrTrWrr rs rget_eol_as_tokenzTokenizer.get_eol_as_tokensN ""$--++2ekk5;;5OO  rc6|jjSr()rr r*s rget_eolzTokenizer.get_eols$$&,,,rc|jj}|jstjj dtj j|jS)zRead 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. r) rrbr6rSrTrWttlrr rs rget_ttlzTokenizer.get_ttlsS ##%""$--++,EF Fww  --r)FF)rPr()F)NFN)*rrrrrrrsrrrhrSr} IDNACodecr%rrrXrrrrgrrrr__next__rrrrrrrrrrrNamerrrrrrrrrjrjs`D"&37 /) /)3-/)SXX//0 /)b3"1uS#X1ST (m/m/Dm/Um/^$5$T$ H &C & &3 sC*sC sC Xc]c"   e&Tc8+/ 15 KK'K K   . K  K(+/ 15 F'FF  . F  F % -- . .rrj)rrorrtypingrrrr dns.exceptionrSdns.namedns.ttlrzrr)r.r1r5r8r;r>rT DNSExceptionrrrjrrrrs$$ --3 e     Ocmm00OW3W3t~.~.r