<s> import struct <EOL> import dns . exception <EOL> import dns . rdata <EOL> import dns . name <EOL> class SRV ( dns . rdata . Rdata ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:port>' , '<STR_LIT:target>' ] <EOL> def __init__ ( self , rdclass , rdtype , priority , weight , port , target ) : <EOL> super ( SRV , self ) . __init__ ( rdclass , rdtype ) <EOL> self . priority = priority <EOL> self . weight = weight <EOL> self . port = port <EOL> self . target = target <EOL> def to_text ( self , origin = None , relativize = True , ** kw ) : <EOL> target = self . target . choose_relativity ( origin , relativize ) <EOL> return '<STR_LIT>' % ( self . priority , self . weight , self . port , <EOL> target ) <EOL> def from_text ( cls , rdclass , rdtype , tok , origin = None , relativize = True ) : <EOL> priority = tok . get_uint16 ( ) <EOL> weight = tok . get_uint16 ( ) <EOL> port = tok . get_uint16 ( ) <EOL> target = tok . get_name ( None ) <EOL> target = target . choose_relativity ( origin , relativize ) <EOL> tok . get_eol ( ) <EOL> return cls ( rdclass , rdtype , priority , weight , port , target ) <EOL> from_text = classmethod ( from_text ) <EOL> def to_wire ( self , file , compress = None , origin = None ) : <EOL> three_ints = struct . pack ( "<STR_LIT>" , self . priority , self . weight , self . port ) <EOL> file . write ( three_ints ) <EOL> self . target . to_wire ( file , compress , origin ) <EOL> def from_wire ( cls , rdclass , rdtype , wire , current , rdlen , origin = None ) : <EOL> ( priority , weight , port ) = struct . unpack ( '<STR_LIT>' , <EOL> wire [ current : current + <NUM_LIT:6> ] ) <EOL> current += <NUM_LIT:6> <EOL> rdlen -= <NUM_LIT:6> <EOL> ( target , 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> target = target . relativize ( origin ) <EOL> return cls ( rdclass , rdtype , priority , weight , port , target ) <EOL> from_wire = classmethod ( from_wire ) <EOL> def choose_relativity ( self , origin = None , relativize = True ) : <EOL> self . target = self . target . choose_relativity ( origin , relativize ) <EOL> def _cmp ( self , other ) : <EOL> sp = struct . pack ( "<STR_LIT>" , self . priority , self . weight , self . port ) <EOL> op = struct . pack ( "<STR_LIT>" , other . priority , other . weight , other . port ) <EOL> v = cmp ( sp , op ) <EOL> if v == <NUM_LIT:0> : <EOL> v = cmp ( self . target , other . target ) <EOL> return v </s>
