<s> """<STR_LIT>""" <EOL> import dns . exception <EOL> QUERY = <NUM_LIT:0> <EOL> IQUERY = <NUM_LIT:1> <EOL> STATUS = <NUM_LIT:2> <EOL> NOTIFY = <NUM_LIT:4> <EOL> UPDATE = <NUM_LIT:5> <EOL> _by_text = { <EOL> '<STR_LIT>' : QUERY , <EOL> '<STR_LIT>' : IQUERY , <EOL> '<STR_LIT>' : STATUS , <EOL> '<STR_LIT>' : NOTIFY , <EOL> '<STR_LIT>' : UPDATE <EOL> } <EOL> _by_value = dict ( [ ( y , x ) for x , y in _by_text . iteritems ( ) ] ) <EOL> class UnknownOpcode ( dns . exception . DNSException ) : <EOL> """<STR_LIT>""" <EOL> def from_text ( text ) : <EOL> """<STR_LIT>""" <EOL> if text . isdigit ( ) : <EOL> value = int ( text ) <EOL> if value >= <NUM_LIT:0> and value <= <NUM_LIT:15> : <EOL> return value <EOL> value = _by_text . get ( text . upper ( ) ) <EOL> if value is None : <EOL> raise UnknownOpcode <EOL> return value <EOL> def from_flags ( flags ) : <EOL> """<STR_LIT>""" <EOL> return ( flags & <NUM_LIT> ) >> <NUM_LIT:11> <EOL> def to_flags ( value ) : <EOL> """<STR_LIT>""" <EOL> return ( value << <NUM_LIT:11> ) & <NUM_LIT> <EOL> def to_text ( value ) : <EOL> """<STR_LIT>""" <EOL> text = _by_value . get ( value ) <EOL> if text is None : <EOL> text = str ( value ) <EOL> return text <EOL> def is_update ( flags ) : <EOL> """<STR_LIT>""" <EOL> if ( from_flags ( flags ) == UPDATE ) : <EOL> return True <EOL> return False </s>
