<s> import struct <EOL> import dns . exception <EOL> import dns . name <EOL> import dns . rdata <EOL> def _write_string ( file , s ) : <EOL> l = len ( s ) <EOL> assert l < <NUM_LIT> <EOL> byte = chr ( l ) <EOL> file . write ( byte ) <EOL> file . write ( s ) <EOL> class NAPTR ( dns . rdata . Rdata ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def __init__ ( self , rdclass , rdtype , order , preference , flags , service , <EOL> regexp , replacement ) : <EOL> super ( NAPTR , self ) . __init__ ( rdclass , rdtype ) <EOL> self . order = order <EOL> self . preference = preference <EOL> self . flags = flags <EOL> self . service = service <EOL> self . regexp = regexp <EOL> self . replacement = replacement <EOL> def to_text ( self , origin = None , relativize = True , ** kw ) : <EOL> replacement = self . replacement . choose_relativity ( origin , relativize ) <EOL> return '<STR_LIT>' % ( self . order , self . preference , <EOL> dns . rdata . _escapify ( self . flags ) , <EOL> dns . rdata . _escapify ( self . service ) , <EOL> dns . rdata . _escapify ( self . regexp ) , <EOL> self . replacement ) <EOL> def from_text ( cls , rdclass , rdtype , tok , origin = None , relativize = True ) : <EOL> order = tok . get_uint16 ( ) <EOL> preference = tok . get_uint16 ( ) <EOL> flags = tok . get_string ( ) <EOL> service = tok . get_string ( ) <EOL> regexp = tok . get_string ( ) <EOL> replacement = tok . get_name ( ) <EOL> replacement = replacement . choose_relativity ( origin , relativize ) <EOL> tok . get_eol ( ) <EOL> return cls ( rdclass , rdtype , order , preference , flags , service , <EOL> regexp , replacement ) <EOL> from_text = classmethod ( from_text ) <EOL> def to_wire ( self , file , compress = None , origin = None ) : <EOL> two_ints = struct . pack ( "<STR_LIT>" , self . order , self . preference ) <EOL> file . write ( two_ints ) <EOL> _write_string ( file , self . flags ) <EOL> _write_string ( file , self . service ) <EOL> _write_string ( file , self . regexp ) <EOL> self . replacement . to_wire ( file , compress , origin ) <EOL> def from_wire ( cls , rdclass , rdtype , wire , current , rdlen , origin = None ) : <EOL> ( order , preference ) = struct . unpack ( '<STR_LIT>' , wire [ current : current + <NUM_LIT:4> ] ) <EOL> current += <NUM_LIT:4> <EOL> rdlen -= <NUM_LIT:4> <EOL> strings = [ ] <EOL> for i in xrange ( <NUM_LIT:3> ) : <EOL> l = ord ( wire [ current ] ) <EOL> current += <NUM_LIT:1> <EOL> rdlen -= <NUM_LIT:1> <EOL> if l > rdlen or rdlen < <NUM_LIT:0> : <EOL> raise dns . exception . FormError <EOL> s = wire [ current : current + l ] . unwrap ( ) <EOL> current += l <EOL> rdlen -= l <EOL> strings . append ( s ) <EOL> ( replacement , cused ) = dns . name . from_wire ( wire [ : current + rdlen ] , <EOL> current ) <EOL> if cused != rdlen : <EOL> raise dns . exception . FormError <EOL> if not origin is None : <EOL> replacement = replacement . relativize ( origin ) <EOL> return cls ( rdclass , rdtype , order , preference , strings [ <NUM_LIT:0> ] , strings [ <NUM_LIT:1> ] , <EOL> strings [ <NUM_LIT:2> ] , replacement ) <EOL> from_wire = classmethod ( from_wire ) <EOL> def choose_relativity ( self , origin = None , relativize = True ) : <EOL> self . replacement = self . replacement . choose_relativity ( origin , <EOL> relativize ) </s>
