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