<s> import struct <EOL> import dns . rdata <EOL> import dns . rdatatype <EOL> class DSBase ( dns . rdata . Rdata ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , rdclass , rdtype , key_tag , algorithm , digest_type , <EOL> digest ) : <EOL> super ( DSBase , self ) . __init__ ( rdclass , rdtype ) <EOL> self . key_tag = key_tag <EOL> self . algorithm = algorithm <EOL> self . digest_type = digest_type <EOL> self . digest = digest <EOL> def to_text ( self , origin = None , relativize = True , ** kw ) : <EOL> return '<STR_LIT>' % ( self . key_tag , self . algorithm , <EOL> self . digest_type , <EOL> dns . rdata . _hexify ( self . digest , <EOL> chunksize = <NUM_LIT> ) ) <EOL> def from_text ( cls , rdclass , rdtype , tok , origin = None , relativize = True ) : <EOL> key_tag = tok . get_uint16 ( ) <EOL> algorithm = tok . get_uint8 ( ) <EOL> digest_type = tok . get_uint8 ( ) <EOL> chunks = [ ] <EOL> while <NUM_LIT:1> : <EOL> t = tok . get ( ) . unescape ( ) <EOL> if t . is_eol_or_eof ( ) : <EOL> break <EOL> if not t . is_identifier ( ) : <EOL> raise dns . exception . SyntaxError <EOL> chunks . append ( t . value ) <EOL> digest = '<STR_LIT>' . join ( chunks ) <EOL> digest = digest . decode ( '<STR_LIT>' ) <EOL> return cls ( rdclass , rdtype , key_tag , algorithm , digest_type , <EOL> digest ) <EOL> from_text = classmethod ( from_text ) <EOL> def to_wire ( self , file , compress = None , origin = None ) : <EOL> header = struct . pack ( "<STR_LIT>" , self . key_tag , self . algorithm , <EOL> self . digest_type ) <EOL> file . write ( header ) <EOL> file . write ( self . digest ) <EOL> def from_wire ( cls , rdclass , rdtype , wire , current , rdlen , origin = None ) : <EOL> header = struct . unpack ( "<STR_LIT>" , wire [ current : current + <NUM_LIT:4> ] ) <EOL> current += <NUM_LIT:4> <EOL> rdlen -= <NUM_LIT:4> <EOL> digest = wire [ current : current + rdlen ] . unwrap ( ) <EOL> return cls ( rdclass , rdtype , header [ <NUM_LIT:0> ] , header [ <NUM_LIT:1> ] , header [ <NUM_LIT:2> ] , digest ) <EOL> from_wire = classmethod ( from_wire ) </s>
