<s> """<STR_LIT>""" <EOL> import struct <EOL> import collections <EOL> def _make_struct_class ( name , names ) : <EOL> class Struct ( object ) : <EOL> _names = names <EOL> def __init__ ( self , ** kwargs ) : <EOL> vars ( self ) . update ( kwargs ) <EOL> def __repr__ ( self ) : <EOL> fields = '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( name , getattr ( self , name ) ) <EOL> for name in self . _names ) <EOL> return '<STR_LIT>' . format ( self . __class__ . __name__ , fields ) <EOL> Struct . __name__ = name <EOL> return Struct <EOL> class StructParser : <EOL> def __init__ ( self , name , format , names ) : <EOL> self . format = format <EOL> self . names = names <EOL> self . struct = struct . Struct ( format ) <EOL> self . Class = _make_struct_class ( name , names ) <EOL> self . size = self . struct . size <EOL> def unpack ( self , data ) : <EOL> """<STR_LIT>""" <EOL> items = zip ( self . names , self . struct . unpack ( data ) ) <EOL> return self . Class ( ** dict ( items ) ) <EOL> def read ( self , file ) : <EOL> """<STR_LIT>""" <EOL> return self . unpack ( file . read ( self . struct . size ) ) </s>
