آSc@s/dZddlZddlZddlZddlZejdkrTddlZnddlZ ddl Z dZ dZ dZ dZdZd e jjfd YZd e jjfd YZd e jjfdYZde jjfdYZde jjfdYZde jjfdYZde jjfdYZde jjfdYZde jjfdYZied6ed6ed6ed6ed6ed 6ed!6ed"6Zed#Z d$Z!d%e"fd&YZ#e#d'gZ$e#gZ%e$d(Z&e$d)Z'd*Z(dS(+sDNS Names. @var root: The DNS root name. @type root: dns.name.Name object @var empty: The empty DNS name. @type empty: dns.name.Name object iNiiiiiit EmptyLabelcBseZdZRS(sRaised if a label is empty.(t__name__t __module__t__doc__(((s./usr/lib64/python2.7/site-packages/dns/name.pyR)st BadEscapecBseZdZRS(s;Raised if an escaped code in a text format name is invalid.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR-st BadPointercBseZdZRS(sCRaised if a compression pointer points forward instead of backward.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR1st BadLabelTypecBseZdZRS(s:Raised if the label type of a wire format name is unknown.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR5stNeedAbsoluteNameOrOrigincBseZdZRS(s~Raised if an attempt is made to convert a non-absolute name to wire when there is also a non-absolute (or missing) origin.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR9st NameTooLongcBseZdZRS(s&Raised if a name is > 255 octets long.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR>st LabelTooLongcBseZdZRS(s&Raised if a label is > 63 octets long.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR BstAbsoluteConcatenationcBseZdZRS(sbRaised if an attempt is made to append anything other than the empty name to an absolute name.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR FstNoParentcBseZdZRS(sVRaised if an attempt is made to get the parent of the root name or the empty name.(RRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR Kst"t(t)t.t;s\t@t$cCsd}x|D]}|tkr0|d|7}q t|dkrat|dkra||7}q |rt|dkr||7}q |dt|7}q W|S(sEscape the characters in label which need it. @param unicode_mode: escapify only special and whitespace (<= 0x20) characters @returns: the escaped string @rtype: stringts\i is\%03d(t_escapedtord(tlabelt unicode_modettexttc((s./usr/lib64/python2.7/site-packages/dns/name.pyt _escapify[s  $  cCst|}d}d}d}xh|D]`}t|}||d7}|dkrZtn|dkr{|dkr{|}n|d7}q%W|dkrtn|dkr||dkrtndS(siCheck for empty labels in the middle of a label sequence, labels that are too long, and for too many labels. @raises NameTooLong: the name as a whole is too long @raises LabelTooLong: an individual label is too long @raises EmptyLabel: a label is empty (i.e. the root label) and appears in a position other than the end of the label sequenceiiii?RiN(tlenR RR(tlabelstlttotaltitjRtll((s./usr/lib64/python2.7/site-packages/dns/name.pyt_validate_labelsns         tNamecBsaeZdZdgZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZedZedZd$dZd$d$d$dZdZdZdZdZ dZ!dZ"dZ#d Z$d!Z%d$e&d"Z'd#Z(RS(%sA DNS name. The dns.name.Name class represents a DNS name as a tuple of labels. Instances of the class are immutable. @ivar labels: The tuple of labels in the name. Each label is a string of up to 63 octets.RcCs0tt|jdt|t|jdS(sInitialize a domain name from a list of labels. @param labels: the labels @type labels: any iterable whose values are strings RN(tsuperR#t __setattr__ttupleR"R(tselfR((s./usr/lib64/python2.7/site-packages/dns/name.pyt__init__scCstddS(Ns+object doesn't support attribute assignment(t TypeError(R'tnametvalue((s./usr/lib64/python2.7/site-packages/dns/name.pyR%scCs t|jS(N(R#R(R'((s./usr/lib64/python2.7/site-packages/dns/name.pyt__copy__scCsttj|j|S(N(R#tcopytdeepcopyR(R'tmemo((s./usr/lib64/python2.7/site-packages/dns/name.pyt __deepcopy__scCs&t|jdko%|jddkS(sXIs the most significant label of this name the root label? @rtype: bool iiR(RR(R'((s./usr/lib64/python2.7/site-packages/dns/name.pyt is_absolutescCs&t|jdko%|jddkS(s\Is this name wild? (I.e. Is the least significant label '*'?) @rtype: bool it*(RR(R'((s./usr/lib64/python2.7/site-packages/dns/name.pytis_wildscCsZd}x@|jD]5}x,|D]$}||d>t|j7}qWqWt|tjS(sHReturn a case-insensitive hash of the name. @rtype: int li(RRtlowertinttsystmaxint(R'thRR((s./usr/lib64/python2.7/site-packages/dns/name.pyt__hash__s  &c Cs|j}|j}||krG|r7tddfStddfSnt|j}t|j}||}|dkr|}n|}d}d} t} x|dkrd|d8}|d8}|d8}|j|j} |j|j} | | kr#d}| dkrt} n| || fS| | krWd}| dkrJt} n| || fS| d7} qW|}|dkrt} n|dkrt} nt} | || fS(sCompare two names, returning a 3-tuple (relation, order, nlabels). I{relation} describes the relation ship beween the names, and is one of: dns.name.NAMERELN_NONE, dns.name.NAMERELN_SUPERDOMAIN, dns.name.NAMERELN_SUBDOMAIN, dns.name.NAMERELN_EQUAL, or dns.name.NAMERELN_COMMONANCESTOR I{order} is < 0 if self < other, > 0 if self > other, and == 0 if self == other. A relative name is always less than an absolute name. If both names have the same relativity, then the DNSSEC order relation is used to order them. I{nlabels} is the number of significant labels that the two names have in common. iii( R1t NAMERELN_NONERRR4tNAMERELN_COMMONANCESTORtNAMERELN_SUPERDOMAINtNAMERELN_SUBDOMAINtNAMERELN_EQUAL( R'tothertsabstoabstl1tl2tldiffRtordertnlabelstnamerelntlabel1tlabel2((s./usr/lib64/python2.7/site-packages/dns/name.pyt fullcomparesN                      cCs8|j|\}}}|tks0|tkr4tStS(soIs self a subdomain of other? The notion of subdomain includes equality. @rtype: bool (RJR=R>tTruetFalse(R'R?tnrtotnl((s./usr/lib64/python2.7/site-packages/dns/name.pyt is_subdomainscCs8|j|\}}}|tks0|tkr4tStS(sqIs self a superdomain of other? The notion of subdomain includes equality. @rtype: bool (RJR<R>RKRL(R'R?RMRNRO((s./usr/lib64/python2.7/site-packages/dns/name.pytis_superdomainscCs&tg|jD]}|j^q S(sReturn a name which is equal to the current name, but is in DNSSEC canonical form. @rtype: dns.name.Name object (R#RR4(R'tx((s./usr/lib64/python2.7/site-packages/dns/name.pyt canonicalizescCs.t|tr&|j|ddkStSdS(Nii(t isinstanceR#RJRL(R'R?((s./usr/lib64/python2.7/site-packages/dns/name.pyt__eq__scCs.t|tr&|j|ddkStSdS(Nii(RTR#RJRK(R'R?((s./usr/lib64/python2.7/site-packages/dns/name.pyt__ne__ scCs.t|tr&|j|ddkStSdS(Nii(RTR#RJtNotImplemented(R'R?((s./usr/lib64/python2.7/site-packages/dns/name.pyt__lt__&scCs.t|tr&|j|ddkStSdS(Nii(RTR#RJRW(R'R?((s./usr/lib64/python2.7/site-packages/dns/name.pyt__le__,scCs.t|tr&|j|ddkStSdS(Nii(RTR#RJRW(R'R?((s./usr/lib64/python2.7/site-packages/dns/name.pyt__ge__2scCs.t|tr&|j|ddkStSdS(Nii(RTR#RJRW(R'R?((s./usr/lib64/python2.7/site-packages/dns/name.pyt__gt__8scCsd|jdS(Ns (t__str__(R'((s./usr/lib64/python2.7/site-packages/dns/name.pyt__repr__>scCs |jtS(N(tto_textRL(R'((s./usr/lib64/python2.7/site-packages/dns/name.pyR]AscCst|jdkrdSt|jdkrE|jddkrEdS|rg|jrg|jd }n |j}djtt|}|S(sConvert name to text format. @param omit_final_dot: If True, don't emit the final dot (denoting the root label) for absolute names. The default is False. @rtype: string iRiRRi(RRR1tjointmapR(R'tomit_final_dotRts((s./usr/lib64/python2.7/site-packages/dns/name.pyR_Ds( cCst|jdkrdSt|jdkrE|jddkrEdS|rg|jrg|jd }n |j}djg|D]!}ttjj|t^q}}|S(sConvert name to Unicode text format. IDN ACE lables are converted to Unicode. @param omit_final_dot: If True, don't emit the final dot (denoting the root label) for absolute names. The default is False. @rtype: string iu@iRu.i( RRR1R`Rt encodingstidnat ToUnicodeRK(R'RbRRRRc((s./usr/lib64/python2.7/site-packages/dns/name.pyt to_unicodeVs ( 7cCs|jsV|dks%|j r.tnt|j}|jt|jn |j}g|D](}dtt||jf^qf}dj |S(sConvert name to a format suitable for digesting in hashes. The name is canonicalized and converted to uncompressed wire format. @param origin: If the name is relative and origin is not None, then origin will be appended to it. @type origin: dns.name.Name object @raises NeedAbsoluteNameOrOrigin: All names in wire format are absolute. If self is a relative name, then an origin must be supplied; if it is missing, then this exception is raised @rtype: string s%s%sRN( R1tNoneRtlistRtextendtchrRR4R`(R'toriginRRRtdlabels((s./usr/lib64/python2.7/site-packages/dns/name.pyt to_digestableks   5c Cs|dkr!tj}t}nt}|js}|dksL|j rUtnt|j}|j t|jn |j}d}x|D]}t ||}|d7}|dk r|j |} nd} | dk rd| } t j d| } |j| Pq|dk rVt|dkrV|j} | dkrV| ||= 0 and <= the length of the name. @returns: the tuple (prefix, suffix) @rtype: tuple is0depth must be >= 0 and <= the length of the name(RRtdnsR*temptyt ValueErrorR#(R'tdepthR((s./usr/lib64/python2.7/site-packages/dns/name.pytsplits   cCsV|jr't|dkr'tnt|j}|jt|jt|S(sReturn a new name which is the concatenation of self and other. @rtype: dns.name.Name object @raises AbsoluteConcatenation: self is absolute and other is not the empty name i(R1RR RiRRjR#(R'R?R((s./usr/lib64/python2.7/site-packages/dns/name.pyRs  cCs8|dk r0|j|r0t|t| S|SdS(sIf self is a subdomain of origin, return a new name which is self relative to origin. Otherwise return self. @rtype: dns.name.Name object N(RhRPR#R(R'Rl((s./usr/lib64/python2.7/site-packages/dns/name.pyRscCs!|js|j|S|SdS(sIf self is a relative name, return a new name which is the concatenation of self and origin. Otherwise return self. @rtype: dns.name.Name object N(R1R(R'Rl((s./usr/lib64/python2.7/site-packages/dns/name.pyt derelativizes  cCs1|r)|r|j|S|j|Sn|SdS(sReturn a name with the relativity desired by the caller. If origin is None, then self is returned. Otherwise, if relativize is true the name is relativized, and if relativize is false the name is derelativized. @rtype: dns.name.Name object N(RR(R'RlR((s./usr/lib64/python2.7/site-packages/dns/name.pytchoose_relativitys  cCs2|tks|tkr!tnt|jdS(sReturn the parent of the name. @rtype: dns.name.Name object @raises NoParent: the name is either the root name or the empty name, and thus has no parent. i(trootRR R#R(R'((s./usr/lib64/python2.7/site-packages/dns/name.pytparents N()RRRt __slots__R(R%R,R0R1R3R9RJRPRQRSRURVRXRYRZR[R^R]RLR_RgRhRnR|R}RRRRRRRRRKRR(((s./usr/lib64/python2.7/site-packages/dns/name.pyR#sH       =            8       RcCst|tstdn|dkp6t|tsHtdng}d}t}d}d}|dkr{d}n|r;|dkrtdgSxQ|D]I}|rR|dkr|jrt|}|d7}qO||7}t}q|jstn|d 9}|t|7}|d7}|d krt}|t |7}qq|dks|d ks|d ks|d krt |dkrt n|j t jj|d}q|dkrt}d}d}q||7}qW|rtnt |dkr+|j t jj|q;|j dnt |dks]|ddkr|dk r|jt|jnt|S(sxConvert unicode text into a Name object. Lables are encoded in IDN ACE form. @rtype: dns.name.Name object s0input to from_unicode() must be a unicode stringsorigin must be a Name or Noneuiu@u.Rii iu。u.u。u\iN(RTtunicodeRRhR#RLtisdigitR5RRkRRtappendRdRetToASCIIRKRjRiR(RRlRRtescapingtedigitsRR((s./usr/lib64/python2.7/site-packages/dns/name.pyt from_unicode"sb                     .cCs{t|tsIt|tr:tjdkr:t||Stdn|d kpat|tsstdng}d}t }d}d}|dkrd}n|r*|dkrtdgSx!|D]}|r}|dkr|j r t |}|d7}qz||7}t }q|j s1t n|d 9}|t |7}|d7}|d krt }|t |7}qq|dkrt|dkrtn|j|d}q|d krt}d}d}q||7}qW|rt nt|dkr|j|q*|jdnt|dksL|d dkrq|d k rq|jt|jnt|S(sFConvert text into a Name object. @rtype: dns.name.Name object is%input to from_text() must be a stringsorigin must be a Name or NoneRiRRii is\iN(RTtstrRR6t hexversionRRRhR#RLRR5RRkRRRRKRjRiR(RRlRRRRRR((s./usr/lib64/python2.7/site-packages/dns/name.pyt from_text`sd                        .cCst|tstdntjj|}g}|}d}t||}|d7}d}x|dkrf|dkr|j||||!j||7}|dkr0||7}q0no|dkr*|d@dt||}|dkr|d7}n||krt n|}|d7}nt t||}|d7}|dkre|d7}qeqeW|jdt ||fS( s^Convert possibly compressed wire format into a Name. @param message: the entire DNS message @type message: string @param current: the offset of the beginning of the name from the start of the message @type current: int @raises dns.name.BadPointer: a compression pointer did not point backwards in the message @raises dns.name.BadLabelType: an invalid label type was encountered. @returns: a tuple consisting of the name that was read and the number of bytes of the wire format message which were consumed reading it @rtype: (dns.name.Name object, int) tuple s*input to from_wire() must be a byte stringiii@ii?iR( RTRRRtwiredatat maybe_wrapRRtunwrapRRR#(tmessagetcurrentRtbiggest_pointerthopstcounttcused((s./usr/lib64/python2.7/site-packages/dns/name.pyt from_wires<             ()RRoRrR6R-Rtencodings.idnaRdt dns.exceptionRt dns.wiredataR:R<R=R>R;t exceptiont SyntaxErrorRRt FormErrorRRt DNSExceptionRRR R R RKRRLRR"tobjectR#RRRRR(((s./usr/lib64/python2.7/site-packages/dns/name.pytsP           > =