<s> import enum <EOL> import collections <EOL> @ enum . unique <EOL> class ByteOrder ( enum . Enum ) : <EOL> LE = <NUM_LIT:0> <EOL> BE = <NUM_LIT:1> <EOL> @ enum . unique <EOL> class Encoding ( enum . Enum ) : <EOL> NONE = <NUM_LIT:0> <EOL> UTF8 = <NUM_LIT:1> <EOL> ASCII = <NUM_LIT:2> <EOL> class Type : <EOL> @ property <EOL> def align ( self ) : <EOL> return None <EOL> @ property <EOL> def size ( self ) : <EOL> pass <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> raise NotImplementedError ( ) <EOL> class PropertyMapping : <EOL> def __init__ ( self , object , prop ) : <EOL> self . _object = object <EOL> self . _prop = prop <EOL> @ property <EOL> def object ( self ) : <EOL> return self . _object <EOL> @ object . setter <EOL> def object ( self , value ) : <EOL> self . _object = value <EOL> @ property <EOL> def prop ( self ) : <EOL> return self . prop <EOL> @ prop . setter <EOL> def prop ( self , value ) : <EOL> self . prop = value <EOL> class Integer ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_size ( ) <EOL> self . set_default_align ( ) <EOL> self . set_default_signed ( ) <EOL> self . set_default_byte_order ( ) <EOL> self . set_default_base ( ) <EOL> self . set_default_encoding ( ) <EOL> self . set_default_property_mappings ( ) <EOL> def set_default_size ( self ) : <EOL> self . _size = None <EOL> def set_default_align ( self ) : <EOL> self . _align = None <EOL> def set_default_signed ( self ) : <EOL> self . _signed = False <EOL> def set_default_byte_order ( self ) : <EOL> self . _byte_order = None <EOL> def set_default_base ( self ) : <EOL> self . _base = <NUM_LIT:10> <EOL> def set_default_encoding ( self ) : <EOL> self . _encoding = Encoding . NONE <EOL> def set_default_property_mappings ( self ) : <EOL> self . _property_mappings = [ ] <EOL> @ property <EOL> def signed ( self ) : <EOL> return self . _signed <EOL> @ signed . setter <EOL> def signed ( self , value ) : <EOL> self . _signed = value <EOL> @ property <EOL> def byte_order ( self ) : <EOL> return self . _byte_order <EOL> @ byte_order . setter <EOL> def byte_order ( self , value ) : <EOL> self . _byte_order = value <EOL> @ property <EOL> def base ( self ) : <EOL> return self . _base <EOL> @ base . setter <EOL> def base ( self , value ) : <EOL> self . _base = value <EOL> @ property <EOL> def encoding ( self ) : <EOL> return self . _encoding <EOL> @ encoding . setter <EOL> def encoding ( self , value ) : <EOL> self . _encoding = value <EOL> @ property <EOL> def align ( self ) : <EOL> if self . _align is None : <EOL> if self . _size is None : <EOL> return <EOL> else : <EOL> if self . _size % <NUM_LIT:8> == <NUM_LIT:0> : <EOL> return <NUM_LIT:8> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return self . _align <EOL> @ align . setter <EOL> def align ( self , value ) : <EOL> self . _align = value <EOL> @ property <EOL> def size ( self ) : <EOL> return self . _size <EOL> @ size . setter <EOL> def size ( self , value ) : <EOL> self . _size = value <EOL> @ property <EOL> def property_mappings ( self ) : <EOL> return self . _property_mappings <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> return False <EOL> class FloatingPoint ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_exp_size ( ) <EOL> self . set_default_mant_size ( ) <EOL> self . set_default_align ( ) <EOL> self . set_default_byte_order ( ) <EOL> def set_default_exp_size ( self ) : <EOL> self . _exp_size = None <EOL> def set_default_mant_size ( self ) : <EOL> self . _mant_size = None <EOL> def set_default_align ( self ) : <EOL> self . _align = <NUM_LIT:8> <EOL> def set_default_byte_order ( self ) : <EOL> self . _byte_order = None <EOL> @ property <EOL> def exp_size ( self ) : <EOL> return self . _exp_size <EOL> @ exp_size . setter <EOL> def exp_size ( self , value ) : <EOL> self . _exp_size = value <EOL> @ property <EOL> def mant_size ( self ) : <EOL> return self . _mant_size <EOL> @ mant_size . setter <EOL> def mant_size ( self , value ) : <EOL> self . _mant_size = value <EOL> @ property <EOL> def size ( self ) : <EOL> if self . _exp_size is None or self . _mant_size is None : <EOL> return <EOL> return self . _exp_size + self . _mant_size <EOL> @ property <EOL> def byte_order ( self ) : <EOL> return self . _byte_order <EOL> @ byte_order . setter <EOL> def byte_order ( self , value ) : <EOL> self . _byte_order = value <EOL> @ property <EOL> def align ( self ) : <EOL> return self . _align <EOL> @ align . setter <EOL> def align ( self , value ) : <EOL> self . _align = value <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> return False <EOL> class Enum ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_value_type ( ) <EOL> self . set_default_members ( ) <EOL> def set_default_value_type ( self ) : <EOL> self . _value_type = None <EOL> def set_default_members ( self ) : <EOL> self . _members = collections . OrderedDict ( ) <EOL> @ property <EOL> def align ( self ) : <EOL> return self . _value_type . align <EOL> @ property <EOL> def size ( self ) : <EOL> return self . _value_type . size <EOL> @ property <EOL> def value_type ( self ) : <EOL> return self . _value_type <EOL> @ value_type . setter <EOL> def value_type ( self , value ) : <EOL> self . _value_type = value <EOL> @ property <EOL> def members ( self ) : <EOL> return self . _members <EOL> @ property <EOL> def last_value ( self ) : <EOL> if not self . _members : <EOL> return <EOL> return list ( self . _members . values ( ) ) [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> def value_of ( self , label ) : <EOL> return self . _members [ label ] <EOL> def label_of ( self , value ) : <EOL> for label , vrange in self . _members . items ( ) : <EOL> if value >= vrange [ <NUM_LIT:0> ] and value <= vrange [ <NUM_LIT:1> ] : <EOL> return label <EOL> def __getitem__ ( self , key ) : <EOL> if type ( key ) is str : <EOL> return self . value_of ( key ) <EOL> elif type ( key ) is int : <EOL> return self . label_of ( key ) <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> return False <EOL> class String ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_encoding ( ) <EOL> def set_default_encoding ( self ) : <EOL> self . _encoding = Encoding . UTF8 <EOL> @ property <EOL> def align ( self ) : <EOL> return <NUM_LIT:8> <EOL> @ property <EOL> def encoding ( self ) : <EOL> return self . _encoding <EOL> @ encoding . setter <EOL> def encoding ( self , value ) : <EOL> self . _encoding = value <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> return True <EOL> class Array ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_element_type ( ) <EOL> self . set_default_length ( ) <EOL> def set_default_element_type ( self ) : <EOL> self . _default_element_type = None <EOL> def set_default_length ( self ) : <EOL> self . _default_length = None <EOL> @ property <EOL> def align ( self ) : <EOL> return self . _element_type . align <EOL> @ property <EOL> def element_type ( self ) : <EOL> return self . _element_type <EOL> @ element_type . setter <EOL> def element_type ( self , value ) : <EOL> self . _element_type = value <EOL> @ property <EOL> def length ( self ) : <EOL> return self . _length <EOL> @ length . setter <EOL> def length ( self , value ) : <EOL> self . _length = value <EOL> @ property <EOL> def is_variable_length ( self ) : <EOL> return type ( self . _length ) is not int <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> if self . is_variable_length : <EOL> return True <EOL> return self . element_type . is_dynamic <EOL> class Struct ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_min_align ( ) <EOL> self . set_default_fields ( ) <EOL> def set_default_min_align ( self ) : <EOL> self . _min_align = <NUM_LIT:1> <EOL> def set_default_fields ( self ) : <EOL> self . _fields = collections . OrderedDict ( ) <EOL> @ property <EOL> def min_align ( self ) : <EOL> return self . _min_align <EOL> @ min_align . setter <EOL> def min_align ( self , value ) : <EOL> self . _min_align = value <EOL> @ property <EOL> def align ( self ) : <EOL> align = self . min_align <EOL> for field in self . fields . values ( ) : <EOL> if field . align is None : <EOL> return <EOL> if field . align > align : <EOL> align = field . align <EOL> return align <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> for field in self . fields . values ( ) : <EOL> if field . is_dynamic : <EOL> return True <EOL> return False <EOL> @ property <EOL> def fields ( self ) : <EOL> return self . _fields <EOL> def __getitem__ ( self , key ) : <EOL> return self . fields [ key ] <EOL> def __len__ ( self ) : <EOL> return len ( self . _fields ) <EOL> class Variant ( Type ) : <EOL> def __init__ ( self ) : <EOL> self . set_default_tag ( ) <EOL> self . set_default_types ( ) <EOL> def set_default_tag ( self ) : <EOL> self . _tag = None <EOL> def set_default_types ( self ) : <EOL> self . _types = collections . OrderedDict ( ) <EOL> @ property <EOL> def align ( self ) : <EOL> single_type = self . get_single_type ( ) <EOL> if single_type is not None : <EOL> return single_type . align <EOL> align = None <EOL> for t in self . types . values ( ) : <EOL> if t . align is None : <EOL> return <EOL> if align is None : <EOL> align = t . align <EOL> else : <EOL> if t . align != align : <EOL> return <EOL> return align <EOL> @ property <EOL> def size ( self ) : <EOL> single_type = self . get_single_type ( ) <EOL> if single_type is not None : <EOL> return single_type . size <EOL> @ property <EOL> def tag ( self ) : <EOL> return self . _tag <EOL> @ tag . setter <EOL> def tag ( self , value ) : <EOL> self . _tag = value <EOL> @ property <EOL> def types ( self ) : <EOL> return self . _types <EOL> def __getitem__ ( self , key ) : <EOL> return self . types [ key ] <EOL> def get_single_type ( self ) : <EOL> if len ( self . members ) == <NUM_LIT:1> : <EOL> return list ( self . members . values ( ) ) [ <NUM_LIT:0> ] <EOL> @ property <EOL> def is_dynamic ( self ) : <EOL> single_type = self . get_single_type ( ) <EOL> if single_type is not None : <EOL> return single_type . is_dynamic <EOL> return True <EOL> class Trace : <EOL> def __init__ ( self ) : <EOL> self . _byte_order = None <EOL> self . _packet_header_type = None <EOL> self . _uuid = None <EOL> @ property <EOL> def uuid ( self ) : <EOL> return self . _uuid <EOL> @ uuid . setter <EOL> def uuid ( self , value ) : <EOL> self . _uuid = value <EOL> @ property <EOL> def byte_order ( self ) : <EOL> return self . _byte_order <EOL> @ byte_order . setter <EOL> def byte_order ( self , value ) : <EOL> self . _byte_order = value <EOL> @ property <EOL> def packet_header_type ( self ) : <EOL> return self . _packet_header_type <EOL> @ packet_header_type . setter <EOL> def packet_header_type ( self , value ) : <EOL> self . _packet_header_type = value <EOL> class Env ( collections . OrderedDict ) : <EOL> pass <EOL> class Clock : <EOL> def __init__ ( self ) : <EOL> self . set_default_name ( ) <EOL> self . set_default_uuid ( ) <EOL> self . set_default_description ( ) <EOL> self . set_default_freq ( ) <EOL> self . set_default_error_cycles ( ) <EOL> self . set_default_offset_seconds ( ) <EOL> self . set_default_offset_cycles ( ) <EOL> self . set_default_absolute ( ) <EOL> self . set_default_return_ctype ( ) <EOL> def set_default_name ( self ) : <EOL> self . _name = None <EOL> def set_default_uuid ( self ) : <EOL> self . _uuid = None <EOL> def set_default_description ( self ) : <EOL> self . _description = None <EOL> def set_default_freq ( self ) : <EOL> self . _freq = <NUM_LIT> <EOL> def set_default_error_cycles ( self ) : <EOL> self . _error_cycles = <NUM_LIT:0> <EOL> def set_default_offset_seconds ( self ) : <EOL> self . _offset_seconds = <NUM_LIT:0> <EOL> def set_default_offset_cycles ( self ) : <EOL> self . _offset_cycles = <NUM_LIT:0> <EOL> def set_default_absolute ( self ) : <EOL> self . _absolute = False <EOL> def set_default_return_ctype ( self ) : <EOL> self . _return_ctype = '<STR_LIT>' <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ name . setter <EOL> def name ( self , value ) : <EOL> self . _name = value <EOL> @ property <EOL> def uuid ( self ) : <EOL> return self . _uuid <EOL> @ uuid . setter <EOL> def uuid ( self , value ) : <EOL> self . _uuid = value <EOL> @ property <EOL> def description ( self ) : <EOL> return self . _description <EOL> @ description . setter <EOL> def description ( self , value ) : <EOL> self . _description = value <EOL> @ property <EOL> def error_cycles ( self ) : <EOL> return self . _error_cycles <EOL> @ error_cycles . setter <EOL> def error_cycles ( self , value ) : <EOL> self . _error_cycles = value <EOL> @ property <EOL> def freq ( self ) : <EOL> return self . _freq <EOL> @ freq . setter <EOL> def freq ( self , value ) : <EOL> self . _freq = value <EOL> @ property <EOL> def offset_seconds ( self ) : <EOL> return self . _offset_seconds <EOL> @ offset_seconds . setter <EOL> def offset_seconds ( self , value ) : <EOL> self . _offset_seconds = value <EOL> @ property <EOL> def offset_cycles ( self ) : <EOL> return self . _offset_cycles <EOL> @ offset_cycles . setter <EOL> def offset_cycles ( self , value ) : <EOL> self . _offset_cycles = value <EOL> @ property <EOL> def absolute ( self ) : <EOL> return self . _absolute <EOL> @ absolute . setter <EOL> def absolute ( self , value ) : <EOL> self . _absolute = value <EOL> @ property <EOL> def return_ctype ( self ) : <EOL> return self . _return_ctype <EOL> @ return_ctype . setter <EOL> def return_ctype ( self , value ) : <EOL> self . _return_ctype = value <EOL> LogLevel = collections . namedtuple ( '<STR_LIT>' , [ '<STR_LIT:name>' , '<STR_LIT:value>' ] ) <EOL> class Event : <EOL> def __init__ ( self ) : <EOL> self . _id = None <EOL> self . _name = None <EOL> self . _log_level = None <EOL> self . _context_type = None <EOL> self . _payload_type = None <EOL> @ property <EOL> def id ( self ) : <EOL> return self . _id <EOL> @ id . setter <EOL> def id ( self , value ) : <EOL> self . _id = value <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ name . setter <EOL> def name ( self , value ) : <EOL> self . _name = value <EOL> @ property <EOL> def log_level ( self ) : <EOL> return self . _log_level <EOL> @ log_level . setter <EOL> def log_level ( self , value ) : <EOL> self . _log_level = value <EOL> @ property <EOL> def context_type ( self ) : <EOL> return self . _context_type <EOL> @ context_type . setter <EOL> def context_type ( self , value ) : <EOL> self . _context_type = value <EOL> @ property <EOL> def payload_type ( self ) : <EOL> return self . _payload_type <EOL> @ payload_type . setter <EOL> def payload_type ( self , value ) : <EOL> self . _payload_type = value <EOL> def __getitem__ ( self , key ) : <EOL> if type ( self . payload_type ) in [ Struct , Variant ] : <EOL> return self . payload_type [ key ] <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> class Stream : <EOL> def __init__ ( self ) : <EOL> self . _id = <NUM_LIT:0> <EOL> self . _name = None <EOL> self . _packet_context_type = None <EOL> self . _event_header_type = None <EOL> self . _event_context_type = None <EOL> self . _events = collections . OrderedDict ( ) <EOL> @ property <EOL> def name ( self ) : <EOL> return self . _name <EOL> @ name . setter <EOL> def name ( self , value ) : <EOL> self . _name = value <EOL> @ property <EOL> def id ( self ) : <EOL> return self . _id <EOL> @ id . setter <EOL> def id ( self , value ) : <EOL> self . _id = value <EOL> @ property <EOL> def packet_context_type ( self ) : <EOL> return self . _packet_context_type <EOL> @ packet_context_type . setter <EOL> def packet_context_type ( self , value ) : <EOL> self . _packet_context_type = value <EOL> @ property <EOL> def event_header_type ( self ) : <EOL> return self . _event_header_type <EOL> @ event_header_type . setter <EOL> def event_header_type ( self , value ) : <EOL> self . _event_header_type = value <EOL> @ property <EOL> def event_context_type ( self ) : <EOL> return self . _event_context_type <EOL> @ event_context_type . setter <EOL> def event_context_type ( self , value ) : <EOL> self . _event_context_type = value <EOL> @ property <EOL> def events ( self ) : <EOL> return self . _events <EOL> def is_event_empty ( self , event ) : <EOL> total_fields = <NUM_LIT:0> <EOL> if self . event_header_type : <EOL> total_fields += len ( self . event_header_type ) <EOL> if self . event_context_type : <EOL> total_fields += len ( self . event_context_type ) <EOL> if event . context_type : <EOL> total_fields += len ( event . context_type ) <EOL> if event . payload_type : <EOL> total_fields += len ( event . payload_type ) <EOL> return total_fields == <NUM_LIT:0> <EOL> class Metadata : <EOL> def __init__ ( self ) : <EOL> self . _trace = None <EOL> self . _env = collections . OrderedDict ( ) <EOL> self . _clocks = collections . OrderedDict ( ) <EOL> self . _streams = collections . OrderedDict ( ) <EOL> self . _default_stream_name = None <EOL> @ property <EOL> def trace ( self ) : <EOL> return self . _trace <EOL> @ trace . setter <EOL> def trace ( self , value ) : <EOL> self . _trace = value <EOL> @ property <EOL> def env ( self ) : <EOL> return self . _env <EOL> @ env . setter <EOL> def env ( self , value ) : <EOL> self . _env = value <EOL> @ property <EOL> def clocks ( self ) : <EOL> return self . _clocks <EOL> @ clocks . setter <EOL> def clocks ( self , value ) : <EOL> self . _clocks = value <EOL> @ property <EOL> def streams ( self ) : <EOL> return self . _streams <EOL> @ streams . setter <EOL> def streams ( self , value ) : <EOL> self . _streams = value <EOL> @ property <EOL> def default_stream_name ( self ) : <EOL> return self . _default_stream_name <EOL> @ default_stream_name . setter <EOL> def default_stream_name ( self , value ) : <EOL> self . _default_stream_name = value <EOL> @ property <EOL> def default_stream ( self ) : <EOL> if self . _default_stream_name in self . _streams : <EOL> return self . _streams [ self . _default_stream_name ] </s>
