
                            S r SSKJr  SSKrSSKrSSKrSSKJr  SSKr	SSK
r	SSKr	SSKr	SSKr	SSKr	SSKr	SSKr	SSKr	SSKr	SSKr	SSKJrJrJr   " S S\	R0                  R2                  5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r S\	RB                  RD                  S\SSS4S jr#S\	RB                  RD                  S\SSS4S jr$\SS4S jr%g)z
DNS Zones.    )
generatorsN)BytesIO   )string_types	text_typePY3c                       \ rS rSrSrSrg)BadZone)   zThe DNS zone is malformed. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       lib/third_party/dns/zone.pyr
   r
   )   s    $r   r
   c                       \ rS rSrSrSrg)NoSOA.   z)The DNS zone has no SOA RR at its origin.r   Nr   r   r   r   r   r   .   s    3r   r   c                       \ rS rSrSrSrg)NoNS3   z+The DNS zone has no NS RRset at its origin.r   Nr   r   r   r   r   r   3   s    5r   r   c                       \ rS rSrSrSrg)UnknownOrigin8   z!The DNS zone's origin is unknown.r   Nr   r   r   r   r   r   8   s    +r   r   c                      \ rS rSrSr\R                  R                  r/ SQr	\R                  R                  S4S jrS rS rS rS	 rS
 rS rS rS rS rS rS rS r\rS rS rS%S jrS%S jrS r\R>                  R@                  S4S jr!\R>                  R@                  S4S jr"\R>                  R@                  4S jr#S r$\R>                  R@                  4S jr%\R>                  R@                  4S jr&\R>                  RN                  \R>                  R@                  4S jr(\R>                  RN                  \R>                  R@                  4S jr)S&S! jr*S&S" jr+S# r,S$r-g )'Zone=   a  A DNS zone.

A Zone is a mapping from names to nodes.  The zone object may be
treated like a Python dictionary, e.g. zone[name] will retrieve
the node associated with that name.  The I{name} may be a
dns.name.Name object, or it may be a string.  In the either case,
if the name is relative it is treated as relative to the origin of
the zone.

@ivar rdclass: The zone's rdata class; the default is class IN.
@type rdclass: int
@ivar origin: The origin of the zone.
@type origin: dns.name.Name object
@ivar nodes: A dictionary mapping the names of nodes in the zone to the
nodes themselves.
@type nodes: dict
@ivar relativize: should names in the zone be relativized?
@type relativize: bool
@cvar node_factory: the factory used to create a new node
@type node_factory: class or callable
)rdclassoriginnodes
relativizeTc                 N   Ub  [        U[        5      (       a   [        R                  R	                  U5      nO4[        U[        R                  R
                  5      (       d  [        S5      eUR                  5       (       d  [        S5      eXl        X l	        0 U l
        X0l        g)zInitialize a zone object.

@param origin: The origin of the zone.
@type origin: dns.name.Name object
@param rdclass: The zone's rdata class; the default is class IN.
@type rdclass: intNz2origin parameter must be convertible to a DNS namez)origin parameter must be an absolute name)
isinstancer   dnsname	from_textName
ValueErroris_absoluter#   r"   r$   r%   )selfr#   r"   r%   s       r   __init__Zone.__init__Y   s     &,//++F366  ", - -%%'' !LMM
$r   c                     [        U[        5      (       d  gU R                  UR                  :w  d4  U R                  UR                  :w  d  U R                  UR                  :w  a  gg)zQTwo zones are equal if they have the same origin, class, and
nodes.
@rtype: bool
FT)r'   r    r"   r#   r$   r.   others     r   __eq__Zone.__eq__n   sJ     %&&<<5==(;;%,,&::$r   c                 .    U R                  U5      (       + $ )z&Are two zones not equal?
@rtype: bool
)r4   r2   s     r   __ne__Zone.__ne__|   s    
 ;;u%%%r   c                    [        U[        5      (       a!  [        R                  R	                  US 5      nO4[        U[        R                  R
                  5      (       d  [        S5      eUR                  5       (       aW  UR                  U R                  5      (       d  [        S5      eU R                  (       a  UR                  U R                  5      nU$ )Nz0name parameter must be convertible to a DNS namez5name parameter must be a subdomain of the zone origin)r'   r   r(   r)   r*   r+   KeyErrorr-   is_subdomainr#   r%   r.   r)   s     r   _validate_nameZone._validate_name   s    dL))88%%dD1DD#((--00MNN$$T[[11KM Mt{{3r   c                 B    U R                  U5      nU R                  U   $ Nr=   r$   r.   keys     r   __getitem__Zone.__getitem__   s     !!#&zz#r   c                 B    U R                  U5      nX R                  U'   g r@   rA   )r.   rC   values      r   __setitem__Zone.__setitem__   s    !!#&

3r   c                 @    U R                  U5      nU R                  U	 g r@   rA   rB   s     r   __delitem__Zone.__delitem__   s    !!#&JJsOr   c                 6    U R                   R                  5       $ r@   )r$   __iter__r.   s    r   rN   Zone.__iter__   s    zz""$$r   c                     [         (       a  U R                  R                  5       $ U R                  R                  5       $ r@   )r   r$   keysiterkeysrO   s    r   rS   Zone.iterkeys   s+    3::??$$::&&((r   c                 6    U R                   R                  5       $ r@   )r$   rR   rO   s    r   rR   	Zone.keys   s    zz  r   c                     [         (       a  U R                  R                  5       $ U R                  R                  5       $ r@   )r   r$   values
itervaluesrO   s    r   rY   Zone.itervalues   s-    3::$$&&::((**r   c                 6    U R                   R                  5       $ r@   )r$   rX   rO   s    r   rX   Zone.values   s    zz  ""r   c                 6    U R                   R                  5       $ r@   )r$   itemsrO   s    r   r^   
Zone.items   s    zz!!r   c                 Z    U R                  U5      nU R                  R                  U5      $ r@   )r=   r$   getrB   s     r   ra   Zone.get   s%    !!#&zz~~c""r   c                     XR                   ;   $ r@   )r$   r2   s     r   __contains__Zone.__contains__   s    

""r   Fc                     U R                  U5      nU R                  R                  U5      nUc+  U(       d  [        eU R	                  5       nX0R                  U'   U$ )a:  Find a node in the zone, possibly creating it.

@param name: the name of the node to find
@type name: dns.name.Name object or string
@param create: should the node be created if it doesn't exist?
@type create: bool
@raises KeyError: the name is not known and create was not specified.
@rtype: dns.node.Node object
)r=   r$   ra   r:   node_factoryr.   r)   createnodes       r   	find_nodeZone.find_node   sR     ""4(zz~~d#<$$&D#JJtr   c                 P     U R                  X5      nU$ ! [         a    Sn U$ f = f)a  Get a node in the zone, possibly creating it.

This method is like L{find_node}, except it returns None instead
of raising an exception if the node does not exist and creation
has not been requested.

@param name: the name of the node to find
@type name: dns.name.Name object or string
@param create: should the node be created if it doesn't exist?
@type create: bool
@rtype: dns.node.Node object or None
N)rk   r:   rh   s       r   get_nodeZone.get_node   s7    	>>$/D   	D	s    %%c                 `    U R                  U5      nXR                  ;   a  U R                  U	 gg)zXDelete the specified node if it exists.

It is not an error if the node does not exist.
NrA   r<   s     r   delete_nodeZone.delete_node   s/     ""4(::

4  r   c                 P   U R                  U5      n[        U[        5      (       a  [        R                  R                  U5      n[        U[        5      (       a  [        R                  R                  U5      nU R                  X5      nUR                  U R                  X#U5      $ )aD  Look for rdata with the specified name and type in the zone,
and return an rdataset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

The rdataset returned is not a copy; changes to it will change
the zone.

KeyError is raised if the name or type are not found.
Use L{get_rdataset} if you want to have None returned instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@param create: should the node and rdataset be created if they do not
exist?
@type create: bool
@raises KeyError: the node or rdata could not be found
@rtype: dns.rdataset.Rdataset object
)	r=   r'   r   r(   	rdatatyper*   rk   find_rdatasetr"   )r.   r)   rdtypecoversri   rj   s         r   ru   Zone.find_rdataset   s}    8 ""4(fl++]],,V4Ffl++]],,V4F~~d+!!$,,GGr   c                 R     U R                  XX45      nU$ ! [         a    Sn U$ f = f)a  Look for rdata with the specified name and type in the zone,
and return an rdataset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

The rdataset returned is not a copy; changes to it will change
the zone.

None is returned if the name or type are not found.
Use L{find_rdataset} if you want to have KeyError raised instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@param create: should the node and rdataset be created if they do not
exist?
@type create: bool
@rtype: dns.rdataset.Rdataset object or None
N)ru   r:   )r.   r)   rv   rw   ri   rdatasets         r   get_rdatasetZone.get_rdataset  s;    6	))$GH   	H	    &&c                    U R                  U5      n[        U[        5      (       a  [        R                  R                  U5      n[        U[        5      (       a  [        R                  R                  U5      nU R                  U5      nUb>  UR                  U R                  X#5        [        U5      S:X  a  U R                  U5        ggg)au  Delete the rdataset matching I{rdtype} and I{covers}, if it
exists at the node specified by I{name}.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

It is not an error if the node does not exist, or if there is no
matching rdataset at the node.

If the node has no rdatasets after the deletion, it will itself
be deleted.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
Nr   )r=   r'   r   r(   rt   r*   rn   delete_rdatasetr"   lenrq   )r.   r)   rv   rw   rj   s        r   r   Zone.delete_rdataset4  s    , ""4(fl++]],,V4Ffl++]],,V4F}}T"  v>4yA~  &  r   c                     UR                   U R                   :w  a  [        S5      eU R                  US5      nUR                  U5        g)a  Replace an rdataset at name.

It is not an error if there is no rdataset matching I{replacement}.

Ownership of the I{replacement} object is transferred to the zone;
in other words, this method does not store a copy of I{replacement}
at the node, it stores I{replacement} itself.

If the I{name} node does not exist, it is created.

@param name: the owner name
@type name: DNS.name.Name object or string
@param replacement: the replacement rdataset
@type replacement: dns.rdataset.Rdataset
z#replacement.rdclass != zone.rdclassTN)r"   r,   rk   replace_rdataset)r.   r)   replacementrj   s       r   r   Zone.replace_rdatasetU  s@    " $,,.BCC~~dD)k*r   c                    U R                  U5      n[        U[        5      (       a  [        R                  R                  U5      n[        U[        5      (       a  [        R                  R                  U5      nU R                  U   R                  U R                  X#5      n[        R                  R                  XR                  X#5      nUR                  U5        U$ )a  Look for rdata with the specified name and type in the zone,
and return an RRset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

This method is less efficient than the similar
L{find_rdataset} because it creates an RRset instead of
returning the matching rdataset.  It may be more convenient
for some uses since it returns an object which binds the owner
name to the rdata.

This method may not be used to create new nodes or rdatasets;
use L{find_rdataset} instead.

KeyError is raised if the name or type are not found.
Use L{get_rrset} if you want to have None returned instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@raises KeyError: the node or rdata could not be found
@rtype: dns.rrset.RRset object
)r=   r'   r   r(   rt   r*   r$   ru   r"   rrsetRRsetupdate)r.   r)   rv   rw   rz   r   s         r   
find_rrsetZone.find_rrsetk  s    < ""4(fl++]],,V4Ffl++]],,V4F::d#11$,,O		llFCXr   c                 R     U R                  XU5      nU$ ! [         a    Sn U$ f = f)a  Look for rdata with the specified name and type in the zone,
and return an RRset encapsulating it.

The I{name}, I{rdtype}, and I{covers} parameters may be
strings, in which case they will be converted to their proper
type.

This method is less efficient than the similar L{get_rdataset}
because it creates an RRset instead of returning the matching
rdataset.  It may be more convenient for some uses since it
returns an object which binds the owner name to the rdata.

This method may not be used to create new nodes or rdatasets;
use L{find_rdataset} instead.

None is returned if the name or type are not found.
Use L{find_rrset} if you want to have KeyError raised instead.

@param name: the owner name to look for
@type name: DNS.name.Name object or string
@param rdtype: the rdata type desired
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
@rtype: dns.rrset.RRset object
N)r   r:   )r.   r)   rv   rw   r   s        r   	get_rrsetZone.get_rrset  s9    8	OOD&9E   	E	r}   c              #     #    [        U[        5      (       a  [        R                  R	                  U5      n[        U[        5      (       a  [        R                  R	                  U5      nU R                  5        HU  u  p4U HJ  nU[        R                  R                  :X  d$  UR                  U:X  d  M3  UR                  U:X  d  ME  X54v   ML     MW     g7f)af  Return a generator which yields (name, rdataset) tuples for
all rdatasets in the zone which have the specified I{rdtype}
and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
then all rdatasets will be matched.

@param rdtype: int or string
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
N)	r'   r   r(   rt   r*   	iteritemsANYrv   rw   )r.   rv   rw   r)   rj   rdss         r   iterate_rdatasetsZone.iterate_rdatasets  s      fl++]],,V4Ffl++]],,V4F NN,LTS]]...JJ&(SZZ6-A+%  -s   B/C5CCc              #     #    [        U[        5      (       a  [        R                  R	                  U5      n[        U[        5      (       a  [        R                  R	                  U5      nU R                  5        Hi  u  p4U H^  nU[        R                  R                  :X  d$  UR                  U:X  d  M3  UR                  U:X  d  ME  U H  nX5R                  U4v   M     M`     Mk     g7f)ab  Return a generator which yields (name, ttl, rdata) tuples for
all rdatas in the zone which have the specified I{rdtype}
and I{covers}.  If I{rdtype} is dns.rdatatype.ANY, the default,
then all rdatas will be matched.

@param rdtype: int or string
@type rdtype: int or string
@param covers: the covered type (defaults to None)
@type covers: int or string
N)
r'   r   r(   rt   r*   r   r   rv   rw   ttl)r.   rv   rw   r)   rj   r   rdatas          r   iterate_rdatasZone.iterate_rdatas  s      fl++]],,V4Ffl++]],,V4F NN,LTS]]...JJ&(SZZ6-A!$#WWe44 "%  -s   B/C)5C)"C)Nc                    [        U[        5      (       a  [        US5      nSnOSn[        USS5      nUc  SnUc"  [        R
                  R                  U5      nSnO9[        U[        5      (       a  UR                  U5      nOUnUR                  5       n U(       a*  [        U R                  5       5      nUR                  5         OU R                  5       nU H{  n	X	   R                  XR                  US9n
[        U
[        5      (       a  U
R                  U5      nOU
nU
R                  5       n
 UR                  U5        UR                  U5        M}     U(       a  UR#                  5         gg! [          a&    UR                  U
5        UR                  U5         M  f = f! U(       a  UR#                  5         f f = f)	a  Write a zone to a file.

@param f: file or string.  If I{f} is a string, it is treated
as the name of a file to open.
@param sorted: if True, the file will be written with the
names sorted in DNSSEC order from least to greatest.  Otherwise
the names will be written in whatever order they happen to have
in the zone's dictionary.
@param relativize: if True, domain names in the output will be
relativized to the zone's origin (if possible).
@type relativize: bool
@param nl: The end of line string.  If not specified, the
output will use the platform's native end-of-line marker (i.e.
LF on POSIX, CRLF on Windows, CR on Macintosh).
@type nl: string or None
wbTFencodingNzutf-8
)r#   r%   )r'   r   opengetattroslinesepencodedecodelistrR   sortrS   to_textr#   r   write	TypeErrorclose)r.   fsortedr%   nl
want_closefile_encnl_bnamesnll_bs               r   to_fileZone.to_file  sr   $ a&&QAJJ 1j$/H:::$$X.DBL))99X&DDB	TYY[)

GOOAkk/9 $ ;a++((8,CC
A GGCLGGDM   	 	 !  GGAJGGBK  	 s1   BF& 4"E3F& 3,F#F& "F##F& &G c                 ~    [        5       nU R                  XAX#5        UR                  5       nUR                  5         U$ )aW  Return a zone's text as though it were written to a file.

@param sorted: if True, the file will be written with the
names sorted in DNSSEC order from least to greatest.  Otherwise
the names will be written in whatever order they happen to have
in the zone's dictionary.
@param relativize: if True, domain names in the output will be
relativized to the zone's origin (if possible).
@type relativize: bool
@param nl: The end of line string.  If not specified, the
output will use the platform's native end-of-line marker (i.e.
LF on POSIX, CRLF on Windows, CR on Macintosh).
@type nl: string or None
)r   r   getvaluer   )r.   r   r%   r   temp_bufferreturn_values         r   r   Zone.to_text$  s9     i[*9"++-r   c                 8   U R                   (       a  [        R                  R                  nOU R                  nU R                  U[        R                  R                  5      c  [        eU R                  U[        R                  R                  5      c  [        eg)zDo some simple checking of the zone's origin.

@raises dns.zone.NoSOA: there is no SOA RR
@raises dns.zone.NoNS: there is no NS RRset
@raises KeyError: there is no origin node
N)r%   r(   r)   emptyr#   r{   rt   SOAr   NSr   r<   s     r   check_originZone.check_origin9  sj     ??88>>D;;DT3==#4#45=KT3==#3#34<J =r   )r$   r#   r"   r%   )F)TTN).r   r   r   r   r   r(   rj   Noderg   	__slots__
rdataclassINr/   r4   r7   r=   rD   rH   rK   rN   rS   rR   rY   rX   r^   r   ra   rd   rk   rn   rq   rt   NONEru   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r    =   sR   , 88==L<I'*~~'8'8T %*& %)!+#" I##((! 251C1C""HH 140B0B!B 47==3E3E 'B+, /2mm.@.@ &P .1]]-?-?  D (+}}'8'8!$!3!3&. %(MM$5$5!mm0050>@*r   r    c                   F    \ rS rSrSr\SS4S jrS rS rS r	S	 r
S
 rSrg)_MasterReaderiJ  a  Read a DNS master file

@ivar tok: The tokenizer
@type tok: dns.tokenizer.Tokenizer object
@ivar last_ttl: The last seen explicit TTL for an RR
@type last_ttl: int
@ivar last_ttl_known: Has last TTL been detected
@type last_ttl_known: bool
@ivar default_ttl: The default TTL from a $TTL directive or SOA RR
@type default_ttl: int
@ivar default_ttl_known: Has default TTL been detected
@type default_ttl_known: bool
@ivar last_name: The last name read
@type last_name: dns.name.Name object
@ivar current_origin: The current origin
@type current_origin: dns.name.Name object
@ivar relativize: should names in the zone be relativized?
@type relativize: bool
@ivar zone: the zone
@type zone: dns.zone.Zone object
@ivar saved_state: saved reader state (used when processing $INCLUDE)
@type saved_state: list of (tokenizer, current_origin, last_name, file,
last_ttl, last_ttl_known, default_ttl, default_ttl_known) tuples.
@ivar current_file: the file object of the $INCLUDed file being parsed
(None if no $INCLUDE is active).
@ivar allow_include: is $INCLUDE allowed?
@type allow_include: bool
@ivar check_origin: should sanity checks of the origin node be done?
The default is True.
@type check_origin: bool
FTc                 6   [        U[        5      (       a  [        R                  R	                  U5      nXl        X l        X@l        SU l        SU l	        SU l
        SU l        U R                  U l        U" X#US9U l        / U l        S U l        X`l        Xpl        g )Nr   Fr%   )r'   r   r(   r)   r*   tokcurrent_originr%   last_ttllast_ttl_knowndefault_ttldefault_ttl_known	last_namezonesaved_statecurrent_fileallow_includer   )r.   r   r#   r"   r%   zone_factoryr   r   s           r   r/   _MasterReader.__init__l  s    fl++XX''/F$$#!&,, ZH	 *(r   c                 h     U R                   R                  5       nUR                  5       (       a  g M2  r@   )r   ra   is_eol_or_eof)r.   tokens     r   	_eat_line_MasterReader._eat_line~  s+    HHLLNE""$$ r   c           	         U R                   c  [        eU R                  R                  SS9nUR	                  5       (       d:  [
        R                  R                  UR                  U R                   5      U l	        OKU R                  R                  5       nUR                  5       (       a  gU R                  R                  U5        U R                  nUR                  U R                  R                  5      (       d  U R                  5         gU R                   (       a%  UR!                  U R                  R                  5      nU R                  R                  5       nUR#                  5       (       d  [
        R$                  R&                  e [
        R(                  R                  UR                  5      nX0l        SU l        U R                  R                  5       nUR#                  5       (       d  [
        R$                  R&                  e  [
        R4                  R                  UR                  5      nU R                  R                  5       nUR#                  5       (       d  [
        R$                  R&                  e X@R                  R8                  :w  a  [
        R$                  R'                  S5      e [
        R:                  R                  UR                  5      nU R                  R<                  R                  U5      nUc2  U R                  R?                  5       nX`R                  R<                  U'    [
        R@                  R                  XEU R                  U R                   S5      nU R0                  (       dU  [K        U[
        RL                  RN                  RP                  RP                  5      (       a  URR                  U l        SU l        URU                  U R                  R                  U R                   5        URW                  5       n
URY                  XEU
S5      nUR[                  Xs5        g! [
        R(                  R.                   aq    U R,                  (       d0  U R0                  (       d  [
        R$                  R'                  S5      eU R0                  (       a  U R2                  n GNU R*                  n GNf = f! [
        R$                  R&                   a    [
        R$                  R&                  e[6         a    U R                  R8                  n GNf = f!   [
        R$                  R'                  SUR                  -  5      e= f! [
        R$                  R&                   a    [B        RD                  " 5       SS u  pU	e  [B        RD                  " 5       SS u  p[
        R$                  R'                  S	RG                  [I        U5      [I        U	5      5      5      e= f)
z(Process one line from a DNS master file.NT)want_leadingMissing default TTL valueRR class is not zone's classunknown rdatatype '%s'F   zcaught exception {}: {}).r   r   r   ra   is_whitespacer(   r)   r*   rG   r   r   ungetr;   r   r#   r   r%   is_identifier	exceptionSyntaxErrorr   r   r   BadTTLr   r   r   	Exceptionr"   rt   r$   rg   r   sysexc_infoformatstrr'   rdtypesr   r   minimumchoose_relativityrw   ru   add)r.   r   r)   r   r"   rv   r   rdtyvarw   r   s               r   _rr_line_MasterReader._rr_line  s;    &$/""$$ XX//T002DN HHLLNE""$$HHNN5!~~  !1!122NN????499#3#34D""$$--+++	$''##EKK0CM"&DHHLLNE&&((mm/// )	(nn..u{{;GHHLLNE&&((mm/// ) ii'''--++,JKK	8]],,U[[9F IIOO%9		&&(A$%IIOOD!	D$$Wdhh%)%8%8%AB  %%*R9L9L9P9P*Q*Q  "zzD%)D"
TYY--t?oogvt<q ww~~ 	$''4+A+Amm//0KLL%%&&mm	$ }}(( 	,--+++ 	(ii''G	(	8--++(5;;68 8 }}(( 	||~bq)HRH	D ||~bq)HR--++)00R#b'BD DsG   A?Q  A2S ;)T0 ?6U!  A<S?SSAT-,T-0.U!BW7c                 X   [         R                  " S5      n[         R                  " S5      n[         R                  " S5      nUR                  U5      nU(       a  UR                  5       u  pgpn
US:X  a  SnUR                  U5      nU(       a  UR                  5       u  pgnUS:X  a  SnSn	Sn
UR                  U5      nU(       a0  UR                  5       u  pgpUS:X  a  SnUR                  5       S   n	Sn
U(       d  U(       d  U(       d
  SnSnSnSn	Sn
W
S:w  a
  [	        5       eWWWW	U
4$ )	Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$ +r   dr   )recompilematchgroupsNotImplementedError)r.   sideis_generate1is_generate2is_generate3g1modsignoffsetwidthbaseg2g3s                r   _parse_modify_MasterReader._parse_modify  s!    zz"GHzz"=>zz"CD %-/YY[*Cvdrz% "		CvrzED%')yy{$CvrzIIKNEDbBCDFED3;%''D&%--r   c           
         U R                   c  [        eU R                  R                  5       n [        R
                  R                  UR                  5      u  p#nU R                  R                  5       nUR                  5       (       d  [        R                  R                  e  UR                  nU R                  R                  5       nUR                  5       (       d  [        R                  R                  e  [        R                  R                  UR                  5      nX`l        SU l        U R                  R                  5       nUR                  5       (       d  [        R                  R                  e  [        R"                  R                  UR                  5      nU R                  R                  5       nUR                  5       (       d  [        R                  R                  e XpR&                  R(                  :w  a  [        R                  R                  S5      e [        R*                  R                  UR                  5      nU R                  R                  5       nUR                  5       (       d  [        R                  R                  e  UR                  n	U R-                  U5      u  ppnU R-                  U	5      u  nnnnn[/        X#S-   U5       GH`  nUS:X  a  U[1        U5      -   nOUS:X  a  U[1        U5      -
  nUS:X  a  U[1        U5      -
  nOUS:X  a  U[1        U5      -   n[3        W5      R5                  [1        U5      5      n[3        W5      R5                  [1        U5      5      nUR7                  S	U
-  U5      nU	R7                  S	U-  U5      n[        R8                  R                  UU R                   5      U l        U R:                  nUR=                  U R&                  R>                  5      (       d  U RA                  5           gU RB                  (       a%  URC                  U R&                  R>                  5      nU R&                  RD                  R                  U5      nUc3  U R&                  RG                  5       nUU R&                  RD                  U'    [        RH                  R                  XxUU R                   S
5      nURO                  U R&                  R>                  U RB                  5        URQ                  5       nURS                  XxUS5      n U RU                  UU5        GMc     g!   [        R                  R                  e= f!   [        R                  R                  e= f! [        R                  R                   aq    U R                  (       d0  U R                  (       d  [        R                  R                  S5      eU R                  (       a  U R                   n GNU R                  n GNf = f! [        R                  R                   a    [        R                  R                  e[$         a    U R&                  R(                  n GNf = f! [$         a-    [        R                  R                  SUR                  -  5      ef = f!   [        R                  R                  e= f! [        R                  R                   a    [J        RL                  " 5       SS u  nnUe  [J        RL                  " 5       SS u  nn[        R                  R                  S[3        U5      < S[3        U5      < 35      e= f)zJProcess one line containing the GENERATE statement from a DNS
master file.NTr   r   r   r   r   -z$%sFr   zcaught exception z: )+r   r   r   ra   r(   granger*   rG   r   r   r   r   r   r   r   r   r   r   r   r   r"   rt   r  rangeintr   zfillreplacer)   r   r;   r#   r   r%   r$   rg   r   r   r   r   rw   ru   r   )!r.   r   startstopsteplhsr   r"   rv   rhslmodlsignloffsetlwidthlbasermodrsignroffsetrwidthrbaseilindexrindexlzfindexrzfindexr)   r   r   r   r   r   rw   r   s!                                    r   _generate_line_MasterReader._generate_line  s    &	, #

 4 4U[[ AEHHLLNE&&((mm/// )	,++CHHLLNE&&((mm/// )	$''##EKK0CM"&DHHLLNE&&((mm/// )	(nn..u{{;GHHLLNE&&((mm/// ) ii'''--++,JKK	9]],,U[[9FHHLLNE&&((mm/// )	,++C /3.@.@.E+We.2.@.@.E+eWfeuQh-A }S\)$S\)}S\)$S\)6{((V5H6{((V5H;;v9DKK$:E XX//d6I6IJDN>>D$$TYY%5%566 tyy'7'78		##D)AyII**,()		%DYY((%)-)<)<eE    !1!14??CYY[F//'64@CGGBg .s	,--+++	,--+++ ww~~ 	$''4+A+Amm//0KLL%%&&mm	$ }}(( 	,--+++ 	(ii''G	(  	9--++,D,1KK-8 9 9	9	,--+++L ==,, <<>"1-RD <<>"1-Rmm//14R#b'1C D Dsm   A5U &AU* =A?V	 >A2X *A2Y9 Z3 4,[U'*V	A<XXXAY65Y697Z03[B]"c           
      
     U R                   R                  SS5      nUR                  5       (       a  U R                  b  U R                  R	                  5         [        U R                  5      S:  aN  U R                  R                  S5      u  U l         U l        U l	        U l        U l
        U l        U l        U l        M  GOUR                  5       (       a  M  UR                  5       (       a  U R                   R!                  5         GM  UR"                  S   S:X  Ga(  UR"                  R%                  5       nUS:X  a  U R                   R                  5       nUR'                  5       (       d  [(        R*                  R-                  S5      e[(        R.                  R1                  UR"                  5      U l        SU l        U R                   R!                  5         GOfUS:X  am  U R                   R3                  5       U l        U R                   R!                  5         U R4                  R6                  c  U R                  U R4                  l        GOUS	:X  Ga  U R8                  (       Ga  U R                   R                  5       nUR"                  nU R                   R                  5       nUR'                  5       (       aO  [(        R:                  R1                  UR"                  U R                  5      nU R                   R!                  5         O@UR=                  5       (       d  [(        R*                  R-                  S
5      eU R                  nU R                  R?                  U R                   U R                  U R                  U R                  U R                  U R                  U R                  U R                  45        [A        US5      U l        [(        RB                  RE                  U R                  U5      U l         X@l        O<US:X  a  U RG                  5         O%[(        R*                  R-                  SU-   S-   5      eGMG  U R                   RI                  U5        U RK                  5         GMt  U RN                  (       a  U R4                  RO                  5         gg! [(        R*                  R,                   aJ  nU R                   RM                  5       u  p6Uc  Sn[(        R*                  R-                  SX6U4-  5      eSnAff = f)zRead a DNS master 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
TNr   $z$TTLzbad $TTLz$ORIGINz$INCLUDEzbad origin in $INCLUDErz	$GENERATEzUnknown master file directive ''zsyntax errorz	%s:%d: %s)(r   ra   is_eofr   r   r   r   popr   r   r   r   r   r   is_eol
is_commentget_eolrG   upperr   r(   r   r   r   r*   get_namer   r#   r   r)   r   appendr   	tokenizer	Tokenizerr(  r   r   wherer   )r.   r   cfilename
new_origindetailline_numbers          r   read_MasterReader.read  s   K	?T40<<>>((4))//14++,q0 483C3C3G3G3K1,*,)/ \\^^%%''HH$$&[[^t+))+AG| $$2244"%--";";J"GG+.77+<+<U[[+I(15.((*j.2hh.?.?.A+((*99++3/3/B/BDII,k)d.@.@.@ $#(;; $ ..00 # 2 25;;373F3F!H ' !HH,,.!&!4!4!6!6"%--";"; 8#: : *.)<)<J((//151D1D15151B1B15151D1D151A1A151G1G1I J -13,?)#&==#:#:4;L;L;C$E.8+l*++-!mm77=ACGI Iu%I Z II""$  }}(( 	?&*hhnn&6#X~'--++xf==? ?		?s    C R$ N3R$ $TATT)r   r   r   r   r   r   r   r   r   r%   r   r   r   N)r   r   r   r   r   r    r/   r   r   r  r(  r?  r   r   r   r   r   r   J  s8    @ GK$4)$Xt'.RzxV%r   r   TFc           
          Uc  Sn[         R                  R                  X5      n[        XX#UUUS9n	U	R	                  5         U	R
                  $ )a  Build a zone object from a master file format string.

@param text: the master file format input
@type text: string.
@param origin: The origin of the zone; if not specified, the first
$ORIGIN statement in the master file will determine the origin of the
zone.
@type origin: dns.name.Name object or string
@param rdclass: The zone's rdata class; the default is class IN.
@type rdclass: int
@param relativize: should names be relativized?  The default is True
@type relativize: bool
@param zone_factory: The zone factory to use
@type zone_factory: function returning a Zone
@param filename: The filename to emit when describing where an error
occurred; the default is '<string>'.
@type filename: string
@param allow_include: is $INCLUDE allowed?
@type allow_include: bool
@param check_origin: should sanity checks of the origin node be done?
The default is True.
@type check_origin: bool
@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
@rtype: dns.zone.Zone object
z<string>)r   r   )r(   r7  r8  r   r?  r   )
textr#   r"   r%   r   r;  r   r   r   readers
             r   r*   r*     sO    D 
--
!
!$
1C3\)6(46F KKM;;r   c           
         [         n[        (       a  Sn	OSn	[        X5      (       a  Uc  U n[        X	5      n Sn
OUc  SnSn
 [	        XX#UXVU5      nU
(       a  U R                  5         U$ ! U
(       a  U R                  5         f f = f)aO  Read a master file and build a zone object.

@param f: file or string.  If I{f} is a string, it is treated
as the name of a file to open.
@param origin: The origin of the zone; if not specified, the first
$ORIGIN statement in the master file will determine the origin of the
zone.
@type origin: dns.name.Name object or string
@param rdclass: The zone's rdata class; the default is class IN.
@type rdclass: int
@param relativize: should names be relativized?  The default is True
@type relativize: bool
@param zone_factory: The zone factory to use
@type zone_factory: function returning a Zone
@param filename: The filename to emit when describing where an error
occurred; the default is '<file>', or the value of I{f} if I{f} is a
string.
@type filename: string
@param allow_include: is $INCLUDE allowed?
@type allow_include: bool
@param check_origin: should sanity checks of the origin node be done?
The default is True.
@type check_origin: bool
@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
@rtype: dns.zone.Zone object
r-  rUTz<file>F)r   r   r'   r   r*   r   )r   r#   r"   r%   r   r;  r   r   str_typeoptsr   zs               r   	from_filerI    s    > H
s!HM
H
al|= GGIH GGI s   A* *Bc                    SnU  GH>  nUcM  U(       a  UR                   nOUR                  S   R                  nUR                  S   R                  nU" XgUS9nUR                   H  nUR                  R                  UR                  5      n	U	(       d(  UR                  5       n	XR                  UR                  '   U	R                  UR                  UR                  UR                  S5      n
U
R                  UR                  5        U H0  nUR                  UR                   U5        U
R                  U5        M2     M     GMA     U(       a  UR                  5         U$ )a^  Convert the output of a zone transfer generator into a zone object.

@param xfr: The xfr generator
@type xfr: generator of dns.message.Message objects
@param relativize: should names be relativized?  The default is True.
It is essential that the relativize setting matches the one specified
to dns.query.xfr().
@type relativize: bool
@param check_origin: should sanity checks of the origin node be done?
The default is True.
@type check_origin: bool
@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
@rtype: dns.zone.Zone object
Nr   r   T)r#   answerr)   r"   r$   ra   rg   ru   rv   rw   
update_ttlr   r   r   r   )xfrr   r%   r   rH  r-  r#   r"   r   znodezrdsr   s               r   from_xfrrP  @  s   " 	A9!))hhqk))GVDAXXEGGKK

+E(&+

#&&u}}ell',||T;DOOEII&$$QXXz:   & 	Hr   )&r   
__future__r   r   r   r   ior   dns.exceptionr(   dns.namedns.nodedns.rdataclassdns.rdatatype	dns.rdatadns.rdtypes.ANY.SOA	dns.rrsetdns.tokenizerdns.ttl
dns.grange_compatr   r   r   r   DNSExceptionr
   r   r   r   objectr    r   r   r   r*   rI  rP  r   r   r   <module>ra     s   $  ! 
 	 	             1 1%cmm(( %
4G 4
67 6
,G ,
J6 JZO%F O%d  ):):D4!)X cnn&7&7D4 t5p  $4 'r   