<s> import sys <EOL> from ctypes import * <EOL> _array_type = type ( Array ) <EOL> def _other_endian ( typ ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( typ , _OTHER_ENDIAN ) : <EOL> return getattr ( typ , _OTHER_ENDIAN ) <EOL> if isinstance ( typ , _array_type ) : <EOL> return _other_endian ( typ . _type_ ) * typ . _length_ <EOL> if issubclass ( typ , Structure ) : <EOL> return typ <EOL> raise TypeError ( "<STR_LIT>" % typ ) <EOL> class _swapped_meta ( type ( Structure ) ) : <EOL> def __setattr__ ( self , attrname , value ) : <EOL> if attrname == "<STR_LIT>" : <EOL> fields = [ ] <EOL> for desc in value : <EOL> name = desc [ <NUM_LIT:0> ] <EOL> typ = desc [ <NUM_LIT:1> ] <EOL> rest = desc [ <NUM_LIT:2> : ] <EOL> fields . append ( ( name , _other_endian ( typ ) ) + rest ) <EOL> value = fields <EOL> super ( _swapped_meta , self ) . __setattr__ ( attrname , value ) <EOL> if sys . byteorder == "<STR_LIT>" : <EOL> _OTHER_ENDIAN = "<STR_LIT>" <EOL> LittleEndianStructure = Structure <EOL> class BigEndianStructure ( Structure ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = _swapped_meta <EOL> _swappedbytes_ = None <EOL> elif sys . byteorder == "<STR_LIT>" : <EOL> _OTHER_ENDIAN = "<STR_LIT>" <EOL> BigEndianStructure = Structure <EOL> class LittleEndianStructure ( Structure ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = _swapped_meta <EOL> _swappedbytes_ = None <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" ) </s>
