<s> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> : <EOL> import struct <EOL> def _build_fmt ( length , endianess ) : <EOL> format_ = "<STR_LIT>" <EOL> if endianess == "<STR_LIT>" : <EOL> format_ += "<STR_LIT:>>" <EOL> elif endianess == "<STR_LIT>" : <EOL> format_ += "<STR_LIT:<>" <EOL> if length == <NUM_LIT:1> : <EOL> format_ += "<STR_LIT:B>" <EOL> elif length == <NUM_LIT:2> : <EOL> format_ += "<STR_LIT:H>" <EOL> elif length == <NUM_LIT:4> : <EOL> format_ += "<STR_LIT:I>" <EOL> elif length == <NUM_LIT:8> : <EOL> format_ += "<STR_LIT>" <EOL> return format_ <EOL> def to_bytes ( val , length , endianess ) : <EOL> return struct . pack ( _build_fmt ( length , endianess ) , val ) <EOL> def from_bytes ( val , length , endianess ) : <EOL> return struct . unpack ( _build_fmt ( length , endianess ) , val ) [ <NUM_LIT:0> ] <EOL> else : <EOL> def from_bytes ( val , length , endianess ) : <EOL> return int . from_bytes ( val , length , endianess ) <EOL> def to_bytes ( val , length , endianess ) : <EOL> return val . to_bytes ( length , endianess ) </s>
