objutils package#

Subpackages#

Submodules#

objutils.ash module#

class objutils.ash.Reader(address_pattern='^(?:(?P<stx>[\\x02])\\s+)?\\$A(?P<address>[0-9a-zA-Z]{2,8})[,.]\\s*$', data_pattern='^(?:[0-9a-zA-Z]{{2,4}}[{0}]?)*\\s*$', etx_pattern='^q.*$')[source]#

Bases: ASCIIHexReader

VALID_CHARS = re.compile("^[a-fA-F0-9 %,\\'\\$\\x02\\x03\\n\\r]*$")#
codecName = 'ash'#
class objutils.ash.Writer(address_designator='$A')[source]#

Bases: ASCIIHexWriter

ADDRESS_DESIGNATOR = '$A'#
MAX_ADDRESS_BITS = 16#
codecName = 'ash'#
compose_header(meta)[source]#
row_callout(address, length, row)[source]#

objutils.binfile module#

Reader/Writer for plain binfiles.

class objutils.binfile.BinZipReader[source]#

Bases: object

codecName = 'binzip'#
class objutils.binfile.BinZipWriter[source]#

Bases: object

MANIFEST_FILE_NAME = 'IMAGES.mf'#
SECTION_FILE_NAME = 'image{0:d}.bin'#
codecName = 'binzip'#
dump(fp, image: Image, **kws)[source]#
dumps(image: Image, **kws)[source]#
exception objutils.binfile.NoContiniousError[source]#

Bases: Exception

class objutils.binfile.Reader[source]#

Bases: object

codecName = 'bin'#
load(fp, address: int = 0)[source]#
loads(image: Image, address: int = 0)[source]#
class objutils.binfile.Writer[source]#

Bases: object

codecName = 'bin'#
dump(fp, image: Image, filler: bytes = b'\xff', **kws)[source]#
dumps(image: Image, filler: bytes = b'\xff', **kws)[source]#

objutils.cc2vmc module#

objutils.checksums module#

objutils.checksums.ADD11(frame)#
objutils.checksums.ADD12(frame)#
objutils.checksums.ADD14(frame)#
objutils.checksums.ADD22(frame)#
objutils.checksums.ADD24(frame)#
objutils.checksums.ADD44(frame)#
class objutils.checksums.Algorithm(*values)[source]#

Bases: IntEnum

Enumerates available checksum algorithms

CHK_ADD_11 = 1#
CHK_ADD_12 = 2#
CHK_ADD_14 = 3#
CHK_ADD_22 = 4#
CHK_ADD_24 = 5#
CHK_ADD_44 = 6#
CHK_CRC_16 = 7#
CHK_CRC_16_CCITT = 8#
CHK_CRC_32 = 9#
CHK_USER_DEFINED = 10#
objutils.checksums.CRC32(x)[source]#
class objutils.checksums.Crc16(table, initalRemainder, finalXorValue, reflectData, reflectRemainder)[source]#

Bases: object

Calculate CRC (16-bit)

Parameters:
table: list-like

lookup table for CRC calculation

initalRemainderint

value to start with

finalXorValueint

final XOR value

reflectDatabool

reflect input data

reflectRemainderbool

reflect output data

.. [1] A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS

http://www.ross.net/crc/download/crc_v3.txt

.. [2] Understanding and implementing CRC (Cyclic Redundancy Check)

calculation http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html

.. [3] Online CRC calculator

http://zorc.breitbandkatze.de/crc.html

WIDTH = 16#
reflectIn(ch, remainder)[source]#
reflectOut(remainder)[source]#
objutils.checksums.ROTATE_LEFT(value)#

Rotate byte left.

objutils.checksums.ROTATE_RIGHT(value)#

Rotate byte right.

objutils.checksums.adder(modulus)[source]#

Factory function for modulus adders

Parameters:
modulusint

modulus to use

Returns:
function

adder function

Examples

>>> a256=adder(256)
>>> a256([11, 22, 33, 44, 55, 66, 77, 88, 99])
239
objutils.checksums.check(frame, algo)[source]#

Calculate checksum using given algorithm

Parameters:
framelist of integers
algoALGO
Returns:
int
objutils.checksums.lrc(data, width, comp=0)[source]#

Longitudinal redundancy check.

objutils.checksums.nibble_sum(data)[source]#
objutils.checksums.reflect(data, nBits)[source]#

Reflect data, i.e. reverse bit order.

Parameters:
dataint
nBitsint

width in bits of data

objutils.checksums.rolb(value)[source]#

Rotate byte left.

objutils.checksums.rorb(value)[source]#

Rotate byte right.

objutils.checksums.rotatedXOR(values, width, rotator)[source]#

Rotated XOR cipher.

objutils.checksums.userDefined(x)[source]#

User defined algorithms are not supported yet.

objutils.checksums.wordSum(modulus, step)[source]#

Factory function for (double-)word modulus sums

Parameters:
modulusint
step[2, 4]

2 - word wise 4 - double-word wise

Returns:
function

summation function

objutils.checksums.xor(frame, invert=True)[source]#

objutils.cosmac module#

class objutils.cosmac.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, '!MAAAA DD'), (2, '\\?MAAAA DD'), (3, 'AAAA DD'), (4, 'DD'))#
check_line(line, format_type)[source]#
codecName = 'cosmac'#
is_data_line(line, format_type)[source]#
previous_address = 0#
previous_length = 0#
class objutils.cosmac.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
codecName = 'cosmac'#
compose_row(address, length, row)[source]#

objutils.emon52 module#

class objutils.emon52.Codec(file_like)[source]#

Bases: object

readlines()[source]#
writelines(lines)[source]#
class objutils.emon52.Reader[source]#

Bases: Reader

DATA_SEPARATOR: str | None = ' '#
FORMAT_SPEC = ((0, 'LL AAAA:DD CCCC'),)#
check_line(line, format_type)[source]#
codecName = 'emon52'#
is_data_line(line, format_type)[source]#
class objutils.emon52.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
codecName = 'emon52'#
compose_row(address, length, row)[source]#

objutils.etek module#

class objutils.etek.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, '%LL6CCAAAAADD'), (2, '%LL3CCU'), (3, '%LL8CCAAAAADD'))#
VALID_CHARS = re.compile('^[a-zA-Z0-9_ %\\n\\r]*$')#
check_line(line, format_type)[source]#
codecName = 'etek'#
is_data_line(line, format_type)[source]#
parseData(line, format_type)[source]#
class objutils.etek.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 24#
codecName = 'etek'#
compose_row(address, length, row)[source]#

objutils.exceptions module#

exception objutils.exceptions.FeatureNotAvailableError[source]#

Bases: Exception

Raised if something is missing, e.g. Numpy for certain operations.

exception objutils.exceptions.FileCorruptedError[source]#

Bases: Exception

exception objutils.exceptions.InvalidAddressError[source]#

Bases: Exception

Raised if address information is out of range.

exception objutils.exceptions.PrematureEndOfFileError[source]#

Bases: Exception

objutils.fpc module#

class objutils.fpc.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, 'CCLL0000AAAAAAAADD'), (2, 'CCLL0001DD'), (3, 'CCLL0002AAAAAAAADD'), (4, '00000000'))#
check_line(line, format_type)[source]#
codecName = 'fpc'#
convert_quintuple(quintuple)[source]#
decode(fp)[source]#
is_data_line(line, format_type)[source]#
probe(fp)[source]#

Determine if object is likely valid for this codec.

Strategy (robust, production-grade): - Quickly reject binary-looking content. - Sample up to 50 non-empty lines (or 8KB), decoding safely. - Count how many lines match this codec’s patterns. - Accept when we see sufficient evidence (>= 2 matches), or when

there’s exactly one non-empty sampled line and it matches (tiny files).

  • Always restore the file pointer to the beginning before returning.

read(fp)[source]#
split_quintuples(line)[source]#
class objutils.fpc.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
codecName = 'fpc'#
compose_row(address, length, row)[source]#
convert_quintuple(value)[source]#
post_processing(data)[source]#

objutils.hexdiff module#

objutils.hexdump module#

class objutils.hexdump.CanonicalDumper(fp: ~typing.TextIO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, num_address_bits: int = 32)[source]#

Bases: Dumper

LINE_LENGTH: int = 16#
dump_row(row: Sequence[int] | bytes | bytearray, startAddr: int) None[source]#
printhex_bytes(row: Sequence[int]) None[source]#
class objutils.hexdump.Dumper(fp: ~typing.TextIO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, num_address_bits: int = 32)[source]#

Bases: object

LINE_LENGTH: int = 16#
dump_data(section, offset: int = 0) None[source]#
objutils.hexdump.isprintable(ch: int) bool[source]#

objutils.hexfile module#

class objutils.hexfile.ASCIIHexReader(address_pattern: str, data_pattern: str, etx_pattern: str, separators: str = ', ')[source]#

Bases: Reader

FORMAT_SPEC = None#
getAddress(line: str, match: Match[str]) bool[source]#
nop(line: str, match: Match[str]) bool[source]#
parse_line(line: str, match: Match[str]) bool[source]#
read(fp: Any) Image[source]#
class objutils.hexfile.ASCIIHexWriter(address_designator: str)[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
compose_row(address: int, length: int, row: Sequence[int]) str[source]#
previous_address: int | None = None#
row_callout(address: int, length: int, row: Sequence[int]) None[source]#
exception objutils.hexfile.AddressRangeToLargeError[source]#

Bases: Exception

class objutils.hexfile.BaseType[source]#

Bases: object

debug(msg: str) None[source]#
error(msg: str) None[source]#
info(msg: str) None[source]#
logger: Logger#
valid: bool#
warn(msg: str) None[source]#
class objutils.hexfile.Container[source]#

Bases: object

add_processing_instruction(pi: Any) None[source]#
class objutils.hexfile.FormatParser(fmt: str, data_separator: str | None = None)[source]#

Bases: object

parse() Pattern[str][source]#
translateFormat(group: str) None[source]#
exception objutils.hexfile.InvalidRecordChecksumError[source]#

Bases: Exception

exception objutils.hexfile.InvalidRecordLengthError[source]#

Bases: Exception

exception objutils.hexfile.Invalidrecord_typeError[source]#

Bases: Exception

class objutils.hexfile.MetaRecord(format_type: str, address: int | None, chunk: bytearray | None)[source]#

Bases: object

address: int | None#
chunk: bytearray | None#
format_type: str#
class objutils.hexfile.Reader[source]#

Bases: BaseType

ALIGMENT = 0#
DATA_SEPARATOR: str | None = None#
VALID_CHARS = re.compile('^[a-fA-F0-9 :/;,%\\n\\r!?S]*$')#
_address_space(value: int) int[source]#
check_line(line: Any, format_type: int) None[source]#
classifyLine(line: Any) int[source]#
is_data_line(line: Any, format_type: int) bool[source]#
load(fp: str | Any, **kws: Any) Image[source]#
loads(image: str | bytes | bytearray, **kws: Any) Image[source]#
maybe_binary_file(fp: Any) bool[source]#
parseData(line: Any, format_type: int) bool[source]#
probe(fp: Any) bool[source]#

Determine if object is likely valid for this codec.

Strategy (robust, production-grade): - Quickly reject binary-looking content. - Sample up to 50 non-empty lines (or 8KB), decoding safely. - Count how many lines match this codec’s patterns. - Accept when we see sufficient evidence (>= 2 matches), or when

there’s exactly one non-empty sampled line and it matches (tiny files).

  • Always restore the file pointer to the beginning before returning.

probes(image: str | bytes | bytearray) bool[source]#
read(fp: Any) Image[source]#
special_processing(line: Any, format_type: int) None[source]#
class objutils.hexfile.Statistics(record_types: collections.Counter[int] = <factory>, data_bytes: collections.Counter[int] = <factory>)[source]#

Bases: object

data_bytes: Counter[int]#
record_types: Counter[int]#
class objutils.hexfile.Writer[source]#

Bases: BaseType

calculate_address_bits(image: Image) int[source]#
compose_header(meta: Mapping[str, Any]) str | None[source]#
compose_row(address: int, length: int, row: Sequence[int]) str[source]#
dump(fp: str | Any, image: Image, row_length: int = 16, **kws: Any) None[source]#
dumps(image: Image, row_length: int = 16, **kws: Any) bytes[source]#
static hex_bytes(row: Sequence[int], spaced: bool = False) str[source]#
post_processing(data: bytes) bytes[source]#
pre_processing(image: Image) None[source]#
set_parameters(**kws: Any) None[source]#
word_to_bytes(word: int) Tuple[int, int][source]#

objutils.ihex module#

class objutils.ihex.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((0, ':LLAAAATTDDCC'),)#
_address_calculator(x)[source]#
calculate_extended_address(line, shift_by, name)[source]#
check_line(line, format_type)[source]#
codecName = 'ihex'#
is_data_line(line, format_type)[source]#
special_processing(line, format_type)[source]#
class objutils.ihex.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 32#
static checksum(data, *, width=8, comp=2)#

Longitudinal redundancy check.

codecName = 'ihex'#
compose_row(address, length, row)[source]#
pre_processing(image)[source]#

objutils.image module#

class objutils.image.AddressSpace(*values)[source]#

Bases: IntEnum

Adress-space constants.

AS_16 = 0#
AS_24 = 1#
AS_32 = 2#
AS_64 = 3#
class objutils.image.Image(sections=None, join=True, meta=None)[source]#

Bases: object

Manage images.

An image is a collection of :class:`Section`s and meta-data.

Parameters:
sections: iteratable (typically `list`or `tuple`

The sections the image should initialized with.

meta: object

Arbitrary meta-data.

_address_contained(address, length)[source]#

Check if address space exists.

Parameters:
address: int
length: int
Returns:
bool
_call_address_function(func_name, addr, *args, **kws)[source]#
delete_section(address=None)[source]#
get_section(address)[source]#

Get Section containing address. Parameters ———- address: int

Returns:
Section
Raises:
InvalidAddressError
hexdump(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#
insert_section(data: bytes | bytearray | memoryview | str, start_address: int | None = None, join: bool = True)[source]#

Insert/add a new section to image.

Parameters:
data: convertible to bytearray() – s. :func:`_data_converter`.

Bytes making up the section.

start_address: int
join: bool

Join/merge adjacent section.

Raises:
InvalidAddressError

Notes

Overlapping sections are not supported. To update/replace a section use update_section().

join_sections()[source]#
read(addr, length, **kws)[source]#

Read bytes from image.

Parameters:
addr: int

Startaddress.

length: int

Number of bytes to read.

Returns:
bytes
Raises:
InvalidAddressError

if addr is out of range

read_ndarray(addr, length, dtype, shape=None, order=None, **kws)[source]#
read_numeric(addr, dtype, **kws)[source]#
read_numeric_array(addr, length, dtype, **kws)[source]#
read_string(addr, encoding='latin1', length=-1, **kws)[source]#
property sections#
split(at=None, equal_parts=None, remap=None)[source]#
update_section(data, address=None)[source]#
write(addr, data, **kws)[source]#

Write bytes to image.

Parameters:
addr: int

Startaddress.

data: bytes
Raises:
InvalidAddressError

if addr is out of range

write_ndarray(addr, array, order=None, **kws)[source]#
write_numeric(addr, value, dtype, **kws)[source]#
write_numeric_array(addr, data, dtype, **kws)[source]#
write_string(addr, value, encoding='latin1', **kws)[source]#
objutils.image._validate_sections(sections)[source]#

Test for required protocol

objutils.logger module#

class objutils.logger.Logger(name, level=30)[source]#

Bases: object

FORMAT = '[%(levelname)s (%(name)s)]: %(message)s'#
LOGGER_BASE_NAME = 'objutils'#
critical(message)[source]#
debug(message)[source]#
error(message)[source]#
getLastError()[source]#
info(message)[source]#
log(message, level)[source]#
setLevel(level)[source]#
silent()[source]#
verbose()[source]#
warn(message)[source]#

objutils.mostec module#

class objutils.mostec.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, ';LLAAAADDCCCC'), (2, ';00'))#
check_line(line, format_type)[source]#
codecName = 'mostec'#
is_data_line(line, format_type)[source]#
class objutils.mostec.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
codecName = 'mostec'#
compose_row(address, length, row)[source]#

objutils.pickleif module#

class objutils.pickleif.PickleIF[source]#

Bases: object

abstractmethod dump(obj, file_, protocol=None)[source]#
abstractmethod dumps(obj, protocol=None)[source]#
abstractmethod load(file_)[source]#
abstractmethod loads(string_)[source]#

objutils.rca module#

class objutils.rca.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, 'AAAA DD;'), (2, ':0000'))#
check_line(line, format_type)[source]#
codecName = 'rca'#
is_data_line(line, format_type)[source]#
class objutils.rca.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
SEPARATOR = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\n'#
codecName = 'rca'#
compose_header(meta)[source]#
compose_row(address, length, row)[source]#

objutils.readers module#

class objutils.readers.PlainBinaryReader(image, byte_order_prefix='@')[source]#

Bases: object

BIG_ENDIAN = '>'#
LITTLE_ENDIAN = '<'#
_get_pos()[source]#
_get_size()[source]#
_set_pos(pos)[source]#
asciiz()[source]#
next_byte()[source]#
property pos#
reset()[source]#
s16()[source]#
s32()[source]#
s64()[source]#
s8()[source]#
property size#
sleb()[source]#
u16()[source]#
u32()[source]#
u64()[source]#
u8()[source]#
uleb()[source]#
value(conversion_code, size)[source]#

objutils.registry module#

class objutils.registry.Codec(Reader, Writer, description)[source]#

Bases: NamedTuple

Reader: Type[Any]#

Alias for field number 0

Writer: Type[Any]#

Alias for field number 1

_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('Reader', 'Writer', 'description')#
classmethod _make(iterable)#

Make a new Codec object from a sequence or iterable

_replace(**kwds)#

Return a new Codec object replacing specified fields with new values

description: str#

Alias for field number 2

exception objutils.registry.CodecAlreadyExistError[source]#

Bases: Exception

exception objutils.registry.CodecDoesNotExistError[source]#

Bases: Exception

class objutils.registry.Registry(*args, **kws)[source]#

Bases: SingletonBase

_get_codecs() OrderedDict[str, Codec][source]#
_get_formats() list[str][source]#
_instance = <objutils.registry.Registry object>#
property codecs: OrderedDict[str, Codec]#
property formats: list[str]#
get(name: str) Codec[source]#
register(name: str, readerClass: Type[Any], writerClass: Type[Any], description: str = '') None[source]#

objutils.section module#

class objutils.section.NumberRange(lower, upper)#

Bases: tuple

_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('lower', 'upper')#
classmethod _make(iterable)#

Make a new NumberRange object from a sequence or iterable

_replace(**kwds)#

Return a new NumberRange object replacing specified fields with new values

lower#

Alias for field number 0

upper#

Alias for field number 1

class objutils.section.Section(start_address: int = 0, data: bytearray = <factory>)[source]#

Bases: object

Manage sections.

A section is a continuous block of bytes, with a start-address and known length.

_getformat(dtype: str, length: int = 1) str[source]#
_verify_dtype(dtype: str) str[source]#
property address: int#
apply_bitmask(data: bytes, dtype: str, bit_mask: int) bytes[source]#
data: bytearray#
find(expr: str, addr: int = -1) int[source]#
hexdump(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#
property length: int#
read(addr: int, length: int, **kws) bytes[source]#
Parameters:
addr: int
length: int
read_ndarray(addr: int, length: int, dtype: str, shape: tuple = None, order: str = None, **kws) ndarray[source]#
read_numeric(addr: int, dtype: str, **kws) int | float[source]#
read_numeric_array(addr: int, length: int, dtype: str, **kws) List[int] | List[float][source]#
read_string(addr: int, encoding: str = 'latin1', length: int = -1, **kws) str[source]#
start_address: int = 0#
tobytes() bytes[source]#
tolist() List[int][source]#
write(addr: int, data: bytes, **kws) None[source]#
Parameters:
addr: int
length: int
data: array-like
write_ndarray(addr: int, array: ndarray, order: str = None, **kws) None[source]#
write_numeric(addr: int, value: int | float, dtype: str, **kws) None[source]#
write_numeric_array(addr: int, data: List[int] | List[float], dtype: str, **kws) None[source]#
write_string(addr: int, value: str, encoding: str = 'latin1', **kws)[source]#
class objutils.section.TypeInformation(type, byte_order, size)#

Bases: tuple

_asdict()#

Return a new dict which maps field names to their values.

_field_defaults = {}#
_fields = ('type', 'byte_order', 'size')#
classmethod _make(iterable)#

Make a new TypeInformation object from a sequence or iterable

_replace(**kwds)#

Return a new TypeInformation object replacing specified fields with new values

byte_order#

Alias for field number 1

size#

Alias for field number 2

type#

Alias for field number 0

objutils.section._data_converter(data: str | bytearray | array | Any) bytearray[source]#
objutils.section.filler(ch: int, n: int) bytearray[source]#

Create an bytearray consisting of n `ch`s.

Parameters:
ch: int (0 <= ch <= 255)

fill char

n: int

repetition count

Returns:
bytearray
objutils.section.fortran_array_from_buffer(arr: bytearray, shape: tuple, dtype: str) ndarray[source]#
objutils.section.fortran_array_to_buffer(array: ndarray) bytearray[source]#
objutils.section.join_sections(sections: List[Section]) List[Section][source]#
objutils.section.signed_range(x: int) NumberRange[source]#
objutils.section.unsigned_range(x: int) NumberRange[source]#

objutils.sig module#

class objutils.sig.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, ':AAAALLBBDDCC'), (2, ':00'))#
check_line(line, format_type)[source]#
codecName = 'sig'#
is_data_line(line, format_type)[source]#
class objutils.sig.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
codecName = 'sig'#
compose_row(address, length, row)[source]#

objutils.srec module#

class objutils.srec.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, 'S0LLAAAADDCC'), (2, 'S1LLAAAADDCC'), (3, 'S2LLAAAAAADDCC'), (4, 'S3LLAAAAAAAADDCC'), (5, 'S5LLAAAACC'), (6, 'S7LLAAAAAAAACC'), (7, 'S8LLAAAAAACC'), (8, 'S9LLAAAACC'))#
_strip_symbols(symbol_tables)[source]#
check_line(line: Any, format_type: int) None[source]#
codecName = 'srec'#
is_data_line(line: Any, format_type: int) bool[source]#
load(fp: Any, **kws: Any)[source]#
special_processing(line: Any, format_type: int) None[source]#
class objutils.srec.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 32#
static checksum(data, *, width=8, comp=1)#

Longitudinal redundancy check.

codecName = 'srec'#
compose_header(meta: Mapping[int, Sequence[MetaRecord]]) str[source]#
compose_row(address: int, length: int, row: Sequence[int]) str[source]#
pre_processing(image) None[source]#
record_type: int | None = None#
s5record: bool = False#
srecord(record_type: int, length: int, address: int, data: Sequence[int] | None = None) str[source]#
start_address: int | None = None#

objutils.tek module#

class objutils.tek.Reader[source]#

Bases: Reader

FORMAT_SPEC = ((1, '/AAAALLBBDDCC'), (2, '/AAAA00BB'))#
check_line(line, format_type)[source]#
codecName = 'tek'#
is_data_line(line, format_type)[source]#
class objutils.tek.Writer[source]#

Bases: Writer

MAX_ADDRESS_BITS = 16#
codecName = 'tek'#
compose_row(address, length, row)[source]#

objutils.titxt module#

class objutils.titxt.Reader(address_pattern='^@(?P<address>[0-9a-zA-Z]{2,8})\\s*$', data_pattern='^(?:[0-9a-zA-Z]{{2,4}}[{0}]?)*\\s*$', etx_pattern='^q.*$')[source]#

Bases: ASCIIHexReader

codecName = 'titxt'#
class objutils.titxt.Writer(address_designator='@')[source]#

Bases: ASCIIHexWriter

codecName = 'titxt'#

objutils.utils module#

class objutils.utils.Curry(fun, *args, **kwargs)[source]#

Bases: object

class objutils.utils.SingletonBase(*args, **kws)[source]#

Bases: object

_lock = <unlocked _thread.lock object>#
class objutils.utils.StructureWithEnums[source]#

Bases: Structure

Add missing enum feature to ctypes Structures.

_map = {}#
objutils.utils.bin_extractor(fname, offset, length)[source]#

Extract a junk of data from a file.

objutils.utils.create_memorymapped_fileview(filename, writeable=False)[source]#
objutils.utils.create_string_buffer(*args)[source]#

Create a string with file-like behaviour (StringIO on Python 2.x).

objutils.utils.cygpath_to_win(path)[source]#
objutils.utils.enum_from_str(enum_class: IntEnum, enumerator: str) IntEnum[source]#

Create an IntEnum instance from an enumerator str.

Parameters:
enum_class: IntEnum
enumerator: str
objutils.utils.ffs(v: int) int[source]#

Find first set bit.

objutils.utils.int_to_array(value)[source]#
objutils.utils.make_list(*args)[source]#
objutils.utils.slicer(iterable, sliceLength, converter=None)[source]#

Module contents#

Package entry-point.

Registers CODECS and implements an interface to them.

The first parameter is always the codec name.

class objutils.Image(sections=None, join=True, meta=None)[source]#

Bases: object

Manage images.

An image is a collection of :class:`Section`s and meta-data.

Parameters:
sections: iteratable (typically `list`or `tuple`

The sections the image should initialized with.

meta: object

Arbitrary meta-data.

_address_contained(address, length)[source]#

Check if address space exists.

Parameters:
address: int
length: int
Returns:
bool
_call_address_function(func_name, addr, *args, **kws)[source]#
delete_section(address=None)[source]#
get_section(address)[source]#

Get Section containing address. Parameters ———- address: int

Returns:
Section
Raises:
InvalidAddressError
hexdump(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#
insert_section(data: bytes | bytearray | memoryview | str, start_address: int | None = None, join: bool = True)[source]#

Insert/add a new section to image.

Parameters:
data: convertible to bytearray() – s. :func:`_data_converter`.

Bytes making up the section.

start_address: int
join: bool

Join/merge adjacent section.

Raises:
InvalidAddressError

Notes

Overlapping sections are not supported. To update/replace a section use update_section().

join_sections()[source]#
read(addr, length, **kws)[source]#

Read bytes from image.

Parameters:
addr: int

Startaddress.

length: int

Number of bytes to read.

Returns:
bytes
Raises:
InvalidAddressError

if addr is out of range

read_ndarray(addr, length, dtype, shape=None, order=None, **kws)[source]#
read_numeric(addr, dtype, **kws)[source]#
read_numeric_array(addr, length, dtype, **kws)[source]#
read_string(addr, encoding='latin1', length=-1, **kws)[source]#
property sections#
split(at=None, equal_parts=None, remap=None)[source]#
update_section(data, address=None)[source]#
write(addr, data, **kws)[source]#

Write bytes to image.

Parameters:
addr: int

Startaddress.

data: bytes
Raises:
InvalidAddressError

if addr is out of range

write_ndarray(addr, array, order=None, **kws)[source]#
write_numeric(addr, value, dtype, **kws)[source]#
write_numeric_array(addr, data, dtype, **kws)[source]#
write_string(addr, value, encoding='latin1', **kws)[source]#
class objutils.Section(start_address: int = 0, data: bytearray = <factory>)[source]#

Bases: object

Manage sections.

A section is a continuous block of bytes, with a start-address and known length.

_getformat(dtype: str, length: int = 1) str[source]#
_verify_dtype(dtype: str) str[source]#
property address: int#
apply_bitmask(data: bytes, dtype: str, bit_mask: int) bytes[source]#
data: bytearray#
find(expr: str, addr: int = -1) int[source]#
hexdump(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]#
property length: int#
read(addr: int, length: int, **kws) bytes[source]#
Parameters:
addr: int
length: int
read_ndarray(addr: int, length: int, dtype: str, shape: tuple = None, order: str = None, **kws) ndarray[source]#
read_numeric(addr: int, dtype: str, **kws) int | float[source]#
read_numeric_array(addr: int, length: int, dtype: str, **kws) List[int] | List[float][source]#
read_string(addr: int, encoding: str = 'latin1', length: int = -1, **kws) str[source]#
start_address: int = 0#
tobytes() bytes[source]#
tolist() List[int][source]#
write(addr: int, data: bytes, **kws) None[source]#
Parameters:
addr: int
length: int
data: array-like
write_ndarray(addr: int, array: ndarray, order: str = None, **kws) None[source]#
write_numeric(addr: int, value: int | float, dtype: str, **kws) None[source]#
write_numeric_array(addr: int, data: List[int] | List[float], dtype: str, **kws) None[source]#
write_string(addr: int, value: str, encoding: str = 'latin1', **kws)[source]#
objutils.dump(codec_name: str, *args: Any, **kws: Any) None[source]#

Save hex data to file.

Parameters:
codec_name: str

Name of a registered codec.

Returns:
bytes
objutils.dumps(codec_name: str, *args: Any, **kws: Any) bytes[source]#

Save hex data to bytes.

Parameters:
codec_name: str

Name of a registered codec.

Returns:
bytes
objutils.load(codec_name: str, *args: Any, **kws: Any) Image[source]#

Load hex data from file.

Parameters:
codec_name: str

Name of a registered codec.

Returns:
class:Image
objutils.loads(codec_name: str, *args: Any, **kws: Any) Image[source]#

Load hex data from bytes.

Parameters:
codec_name: str

Name of a registered codec.

Returns:
class:Image
objutils.probe(*args: Any, **kws: Any) str | None[source]#

Try to guess codec from file.

Returns:
str | None

The detected codec name or None if undetected.

objutils.probes(*args: Any, **kws: Any) str | None[source]#

Try to guess codec from bytes.

Returns:
str | None

The detected codec name or None if undetected.