a àMÒemã @sèdZddlZddlZddlmZmZmZmZmZm Z m Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ ddlZ Gdd„de jjƒZGdd„de jjƒZdd „Ze e jjee jj ee jj eee!e"e!e"fZ#d d „Z$Gd d „d ƒZ%Gdd„de j&j'ƒZ(Gdd„de j&j)ƒZ*dde j+j,e j+j,ddde jj-df eee e jj e.fee!ee e j+j/e.fe e j+j/e.fee e j0j1e.fee e!e.fee jj2ee e jj e.fe"ee j3j4dœ dd„Z5dS)z DNS Zones.éN)ÚAnyÚIterableÚListÚOptionalÚSetÚTupleÚUnionc@seZdZdZdS)Ú UnknownOriginzUnknown originN©Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú0/usr/lib/python3.9/site-packages/dns/zonefile.pyr &sr c@seZdZdZdS)ÚCNAMEAndOtherDataz!A node has a CNAME and other dataNr rrrrr*srcCsztjj |¡}| |¡}|dur$dS| ¡}|tjjjkrR|tjjjkrRtdƒ‚n$|tjjjkrv|tjjjkrvtdƒ‚dS)Nz1rdataset type is not compatible with a CNAME nodez9CNAME rdataset is not compatible with a regular data node) ÚdnsÚnodeZNodeKindZclassify_rdatasetZget_nodeZclassifyZCNAMEZREGULARr)ÚtxnÚnameÚrdatasetZ rdataset_kindrZ node_kindrrrÚ_check_cname_and_other_data.s"  ÿ þ  ÿ þÿrcCs| ¡}| d¡sd|}|S)Nú$)ÚupperÚ startswith)ÚsrrrÚ_upper_dollarizeQs rc @s¶eZdZdZdejjejjej j e e e e efeejjeeeejjeejjeedœ dd„Zdd „Zd d „Zd d „Zeeeeeeefdœdd„Zdd„Zddœdd„ZdS)ÚReaderz(Read a DNS zone file into a transaction.FTN) ÚtokÚrdclassrÚ allow_includeÚallow_directivesÚ force_nameÚ force_ttlÚ force_rdclassÚ force_rdtypeÚ default_ttlc Csò||_|j ¡\|_|_} |j|_d|_d|_|dur:|} | durPd|_d|_ n | |_d|_ |j|_ ||_ ||_ g|_ d|_||dur¤hd£|_|rÊ|j d¡n&|dur¶tƒ|_ntdd„|Dƒƒ|_||_||_||_| |_|j  t¡dS)NrFT>ú $GENERATEú$TTLú$ORIGINú$INCLUDEcss|]}t|ƒVqdS©N)r)Ú.0ÚdrrrÚ †óz"Reader.__init__..)rÚmanagerÚorigin_informationÚ zone_originÚ relativizeÚcurrent_originÚlast_ttlÚlast_ttl_knownr&Údefault_ttl_knownÚ last_nameÚ zone_rdclassrÚ saved_stateÚ current_fileÚallowed_directivesÚaddÚsetr"r#r$r%Zcheck_put_rdatasetr) Úselfrrrr r!r"r#r$r%r&Ú_rrrÚ__init__[s<   zReader.__init__cCs|j ¡}| ¡rqqdSr+)rÚgetÚ is_eol_or_eof©r?ÚtokenrrrÚ _eat_lines zReader._eat_linecCs|j ¡}| ¡stjj‚|Sr+)rrBÚ is_identifierrÚ exceptionÚ SyntaxErrorrDrrrÚ_get_identifier“s zReader._get_identifierc CsHd}|jdur|j}nŠ|jdur$t‚|jjdd}| ¡sN|j ||j¡|_n"|j ¡}| ¡rddS|j  |¡|j}|  |j ¡sŽ|  ¡dS|j r |  |j ¡}|jdur¾|j}||_d|_nT| ¡}d}z"tj |j¡}||_d|_d}Wn$tjjy|j  |¡Yn0|jdur&|j}nr| ¡}ztj |j¡}Wn>tjjyZ‚Yn&ty~|j}|j  |¡Yn0||jkr˜tj d¡‚|dur| ¡}d}z"tj |j¡}||_d|_d}WnBtjjy|jrô|j}n|jr|j}|j  |¡Yn0|jdur(|j}nB| ¡}ztj  |j¡}Wn&tyhtj d|j¡‚Yn0z"tj! |||j|j|j |j ¡}Wn\tjjy¦‚YnDtyèt" #¡dd…\}}tj d $t%|ƒt%|ƒ¡¡‚Yn0|js|tj j&kr|j'|_d|_|dur|j'}|dur4tj d¡‚|j( )|||¡dS) z&Process one line from a DNS zone file.NT)Z want_leadingúRR class is not zone's classúunknown rdatatype '%s'ézcaught exception {}: {}úMissing default TTL value)*r"r4r rrBZ is_whitespaceZas_namer8rCÚungetÚ is_subdomainr2rFr3r#r5r6rJrÚttlÚ from_textÚvalueÚBadTTLr$Ú rdataclassrHrIÚ Exceptionr9r7r&r%Ú rdatatypeÚrdataÚsysÚexc_infoÚformatÚstrZSOAZminimumrr=) r?rErrQrÚrdtypeÚrdÚtyÚvarrrÚ_rr_line™s°            úÿ    zReader._rr_line)ÚsideÚreturnc Cst d¡}t d¡}t d¡}| |¡}|rJ| ¡\}}}} } |dkrJd}| |¡} | rz|  ¡\}}}|dkrrd}d} d} | |¡} | r¨|  ¡\}}}} |dkr¤d}d} |sÈ| sÈ| sÈd}d}d}d} d} t|ƒ}t| ƒ} |dvrðtj d |¡‚| d vr tj d | ¡‚|||| | fS) Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$Úú+rr-)reú-zinvalid offset sign %s)r-ÚoÚxÚXÚnÚNzinvalid type %s)ÚreÚcompileÚmatchÚgroupsÚintrrHrI) r?rbZ is_generate1Z is_generate2Z is_generate3Zg1ÚmodÚsignÚoffsetÚwidthÚbaseZg2Zg3rrrÚ _parse_modifysD        zReader._parse_modifyc s¬|jdurt‚|j ¡}z2tj |j¡\}}}|j ¡}| ¡sHtj j ‚Wnt ydtj j ‚Yn0z$|j}|j ¡}| ¡sˆtj j ‚Wnt y¤tj j ‚Yn0z8tj  |j¡}||_ d|_|j ¡}| ¡sÜtj j ‚WnRtj jy0|js|jstj   d¡‚|jr|j}n|jr,|j }Yn0z.tj |j¡}|j ¡}| ¡s^tj j ‚Wn8tj j y€tj j ‚Ynt y˜|j}Yn0||jkr²tj   d¡‚z.tj |j¡}|j ¡}| ¡sÞtj j ‚Wn&t ytj   d|j¡‚Yn0|j} ttttdœdd„} ttttd œ‡fd d „ ‰| |¡\} } } }}| | ¡\}}}}}t||d |ƒD]2}| || | ƒ}| |||ƒ}ˆ|||ƒ}ˆ|||ƒ}| d | |¡}|  d ||¡}tj ||j|jj¡|_|j}| |j¡s| ¡dS|j r|  |j¡}z tj! ||||j|j |j¡}Wn\tj j yP‚YnDt y’t" #¡dd…\}}tj   dt|ƒt|ƒf¡‚Yn0|j$ %|||¡qrdS)zPProcess one line containing the GENERATE statement from a DNS zone file.NTrNrKrL)ÚcounterÚ offset_signrsrccSs|dkr|d9}||S)z0Calculate the index from the counter and offset.rféÿÿÿÿr)rwrxrsrrrÚ_calculate_indexsz/Reader._generate_line.._calculate_index)ÚindexrurtrccsT|dvrt||ƒ |¡Sˆ|d|ƒ}d |ddd…¡d|…}|dkrP| ¡}|S)zVFormat the index with the given base, and zero-fill it to the given width.)r-rgrhrirhÚ.Nryrk)r[ÚzfillÚjoinr)r{rurtZhexaZnibbles©Ú _format_indexrrr€‡s z,Reader._generate_line.._format_indexéz$%srMzcaught exception %s: %s)&r4r rrBrZgrangerRrSrGrHrIrVrQr5r6rTr7r&rUr9rWrpr\rvÚrangeÚreplacerÚ idna_codecr8rPr2rFr3rXrYrZrr=)r?rEÚstartÚstopÚstepZlhsrQrr]ZrhsrzZlmodZlsignZloffsetZlwidthZlbaseZrmodZrsignZroffsetZrwidthZrbaseÚiZlindexÚrindexZlzfindexZrzfindexrrXr^r_r`rrrÚ_generate_line@s®                            ÿ úÿ zReader._generate_line)rcc Csîzr|j dd¡}| ¡rr|jdur.|j ¡t|jƒdkrj|j d¡\|_|_|_ |_|_ |_ |_ |_ qqrnê| ¡r€qnÜ| ¡r˜|j ¡qnÄ|jddkr\t|jƒdkr\|j ¡}||jvràtj d|›d¡‚|dkr,|j ¡}| ¡s tj d ¡‚tj |j¡|_ d|_ |j ¡q|d krp|j ¡|_|j ¡|jdur`|j|_|j |j¡q|d kr2|j ¡}|j}|j ¡}| ¡rÂtj |j|j|jj¡}|j ¡n|  ¡sÚtj d ¡‚n|j}|j !|j|j|j |j|j |j |j |j f¡t"|d ƒ|_tj# $|j|¡|_||_q|dkrF| %¡qtj d|›d¡‚q|j &|¡| '¡qWnttjjyè}zV|j (¡\}}|dur¦d}tj d|||f¡}t) *¡d}| +|¡d‚WYd}~n d}~00dS)zÆRead a DNS zone file and build a zone object. @raises dns.zone.NoSOA: No SOA RR was found at the zone origin @raises dns.zone.NoNS: No NS RRset was found at the zone origin TNrryrzzone file directive 'z' is not allowedr(zbad $TTLr)r*zbad origin in $INCLUDEÚrr'zUnknown zone file directive 'ú'z syntax errorz %s:%d: %srM),rrBZis_eofr;ÚcloseÚlenr:Úpopr4r8r5r6r&r7Zis_eolZ is_commentZget_eolrSr<rrrHrIrGrQrRZget_namer2rÚ _set_originrr„rCÚappendÚopenÚ tokenizerÚ TokenizerrŠrOraÚwhererYrZÚwith_traceback) r?rEÚcÚfilenameZ new_originZdetailZ line_numberÚexÚtbrrrÚreadÅsª   ÷     ÿ             ÿ  øÿ    ÿ   ÿ z Reader.read)FTNNNNN)r r r rrr“r”rUÚ RdataClassÚ transactionÚ TransactionÚboolrrr\rrÚNamerprWÚ RdataTyperArFrJrarrvrŠr›rrrrrXs6õ   õ 2z-rcsteZdZ‡fdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Z‡ZS)ÚRRsetsReaderTransactioncstƒ |||¡i|_dSr+)ÚsuperrAÚ rdatasets)r?r0Ú replacementZ read_only©Ú __class__rrrA+sz RRsetsReaderTransaction.__init__cCs|j |||f¡Sr+)r¤rB©r?rr]ÚcoversrrrÚ _get_rdataset0sz%RRsetsReaderTransaction._get_rdatasetcCsTg}|j ¡D] \\}}}}||kr| |¡qt|ƒdkr@dStj ¡}||_|S©Nr)r¤Úitemsr‘rŽrrZNode)r?rr¤Z rdataset_namer@rrrrrÚ _get_node3s   z!RRsetsReaderTransaction._get_nodecCs||j||j|jf<dSr+)r¤r]r©)r?rrrrrÚ _put_rdataset>sz%RRsetsReaderTransaction._put_rdatasetcCsHg}|jD]}|d|kr | |¡q t|ƒdkrD|D] }|j|=q6dSr«)r¤r‘rŽ)r?rÚremoveÚkeyrrrÚ _delete_nameAs    z$RRsetsReaderTransaction._delete_namecCs*z|j|||f=Wnty$Yn0dSr+)r¤ÚKeyErrorr¨rrrÚ_delete_rdatasetKs z(RRsetsReaderTransaction._delete_rdatasetcCs$|jD]\}}}||krdSqdS©NTF)r¤)r?rrjr@rrrÚ _name_existsQsz$RRsetsReaderTransaction._name_existscCst|jƒdkSr«)rŽr¤©r?rrrÚ_changedWsz RRsetsReaderTransaction._changedcCsf|rb| ¡rbg}|j ¡D]:\\}}}}tj ||j|j|j¡}|  |¡|  |¡q|j   |¡dSr+) r·r¤r¬rÚrrsetÚRRsetrr]r©Úupdater‘r0Ú set_rrsets)r?ZcommitÚrrsetsrr@rr¸rrrÚ_end_transactionZs ÿ  z(RRsetsReaderTransaction._end_transactioncCsdSr+r)r?Úoriginrrrresz#RRsetsReaderTransaction._set_origincCst‚dSr+©ÚNotImplementedErrorr¶rrrÚ_iterate_rdatasetshsz*RRsetsReaderTransaction._iterate_rdatasetscCst‚dSr+r¿r¶rrrÚ_iterate_namesksz&RRsetsReaderTransaction._iterate_names)r r r rArªr­r®r±r³rµr·r½rrÁrÂÚ __classcell__rrr¦rr¢*s    r¢c@sNeZdZejjdejjfdd„Zdd„Z ddd„Z dd „Z d d „Z d d „Z dS)ÚRRSetsReaderManagerFcCs||_||_||_g|_dSr+)r¾r3rr¼)r?r¾r3rrrrrApszRRSetsReaderManager.__init__cCst‚dSr+r¿r¶rrrÚreaderxszRRSetsReaderManager.readercCs t|ddƒSr´)r¢)r?r¥rrrÚwriter{szRRSetsReaderManager.writercCs|jSr+)rr¶rrrÚ get_classszRRSetsReaderManager.get_classcCs$|jrtjj}n|j}|j|j|fSr+)r3rrÚemptyr¾)r?Z effectiverrrr1‚s z&RRSetsReaderManager.origin_informationcCs ||_dSr+)r¼)r?r¼rrrr»‰szRRSetsReaderManager.set_rrsetsN)F)r r r rrÚrootrUÚINrArÅrÆrÇr1r»rrrrrÄosÿ  rÄF) ÚtextrrQrÚdefault_rdclassr]r&r„r¾r3rcc  Cst|tƒrtj |tjj|¡}t|tƒr8tj |||¡}t|tƒrNtj |¡}t|tƒrdtj |¡}|dur|tjj  |¡}nd}tjj  |¡}|dur¦tj j   |¡}nd}t || |ƒ} |   d¡D} tjj|d|d} t| || d|||||d } |  ¡Wdƒn1s 0Y| jS)a‘ Read one or more rrsets from the specified text, possibly subject to restrictions. *text*, a file object or a string, is the input to process. *name*, a string, ``dns.name.Name``, or ``None``, is the owner name of the rrset. If not ``None``, then the owner name is "forced", and the input must not specify an owner name. If ``None``, then any owner names are allowed and must be present in the input. *ttl*, an ``int``, string, or None. If not ``None``, the the TTL is forced to be the specified value and the input must not specify a TTL. If ``None``, then a TTL may be specified in the input. If it is not specified, then the *default_ttl* will be used. *rdclass*, a ``dns.rdataclass.RdataClass``, string, or ``None``. If not ``None``, then the class is forced to the specified value, and the input must not specify a class. If ``None``, then the input may specify a class that matches *default_rdclass*. Note that it is not possible to return rrsets with differing classes; specifying ``None`` for the class simply allows the user to optionally type a class as that may be convenient when cutting and pasting. *default_rdclass*, a ``dns.rdataclass.RdataClass`` or string. The class of the returned rrsets. *rdtype*, a ``dns.rdatatype.RdataType``, string, or ``None``. If not ``None``, then the type is forced to the specified value, and the input must not specify a type. If ``None``, then a type must be present for each RR. *default_ttl*, an ``int``, string, or ``None``. If not ``None``, then if the TTL is not forced and is not specified, then this value will be used. if ``None``, then if the TTL is not forced an error will occur if the TTL is not specified. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. Note that codecs only apply to the owner name; dnspython does not do IDNA for names in rdata, as there is no IDNA zonefile format. *origin*, a string, ``dns.name.Name``, or ``None``, is the origin for any relative names in the input, and also the origin to relativize to if *relativize* is ``True``. *relativize*, a bool. If ``True``, names are relativized to the *origin*; if ``False`` then any relative names in the input are made absolute by appending the *origin*. NTz)r„F)r!r"r#r$r%r&)Ú isinstancer\rrrRrÉrQrUrœZmakerWr¡rÄrÆr“r”rr›r¼)rËrrQrrÌr]r&r„r¾r3r0rrrÅrrrÚ read_rrsetss>=        ÷ (rÎ)6rrlrYÚtypingrrrrrrrZ dns.exceptionrZ dns.grangeZdns.nameZdns.nodeZ dns.rdataZdns.rdataclassZ dns.rdatatypeZdns.rdtypes.ANY.SOAZ dns.rrsetZ dns.tokenizerZdns.transactionZdns.ttlrHZ DNSExceptionr rrr“r”rr rprŸZSavedStateTyperrrržr¢ZTransactionManagerrÄrUrÊrÉr\rœrWr¡Z IDNACodecr¸r¹rÎrrrrÚst$  ùÿ UE ö  õ