SrecTag#

class hexrec.formats.srec.SrecTag(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Motorola S-record tag.

Attributes

HEADER

Header string.

DATA_16

16-bit address data record.

DATA_24

24-bit address data record.

DATA_32

32-bit address data record.

RESERVED

Reserved tag.

COUNT_16

16-bit record count.

COUNT_24

24-bit record count.

START_32

32-bit start address.

START_24

24-bit start address.

START_16

16-bit start address.

denominator

the denominator of a rational number in lowest terms

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

Methods

fit_count_tag

Fits count record tag.

fit_data_tag

Fits data record tag.

fit_start_tag

Fits data record tag.

get_address_max

Calculates the maximum address.

get_address_size

Calculates the maximum address size.

get_data_max

Calculates the maximum data size.

get_tag_match

Calculates the matching tag.

is_count

Tells whether this is a record count tag.

is_header

Tells whether this is a header record tag.

is_start

Tells whether this is a start address record tag.

__init__

as_integer_ratio

Return integer ratio.

bit_count

Number of ones in the binary representation of the absolute value of self.

bit_length

Number of bits necessary to represent self in binary.

conjugate

Returns self, the complex conjugate of any int.

from_bytes

Return the integer represented by the given array of bytes.

to_bytes

Return an array of bytes representing an integer.

COUNT_16 = 5#

16-bit record count. Optional.

COUNT_24 = 6#

24-bit record count. Optional.

DATA_16 = 1#

16-bit address data record.

DATA_24 = 2#

24-bit address data record.

DATA_32 = 3#

32-bit address data record.

HEADER = 0#

Header string. Optional.

RESERVED = 4#

Reserved tag.

START_16 = 9#

16-bit start address. Terminates DATA_16.

START_24 = 8#

24-bit start address. Terminates DATA_24.

START_32 = 7#

32-bit start address. Terminates DATA_32.

_DATA: Optional[BaseTag] = 1#

Alias to a common data record tag.

This tag is used internally to build a generic data record.

__abs__()#

abs(self)

__add__(value, /)#

Return self+value.

__and__(value, /)#

Return self&value.

__bool__()#

True if self else False

__ceil__()#

Ceiling of an Integral returns itself.

classmethod __contains__(member)#

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

__dir__()#

Returns all members and all public methods

__divmod__(value, /)#

Return divmod(self, value).

__eq__(value, /)#

Return self==value.

__float__()#

float(self)

__floor__()#

Flooring an Integral returns itself.

__floordiv__(value, /)#

Return self//value.

__format__(format_spec, /)#

Default object formatter.

__ge__(value, /)#

Return self>=value.

__getattribute__(name, /)#

Return getattr(self, name).

classmethod __getitem__(name)#

Return the member matching name.

__gt__(value, /)#

Return self>value.

__hash__()#

Return hash(self).

__index__()#

Return self converted to an integer, if self is suitable for use as an index into a list.

__init__(*args, **kwds)#
__int__()#

int(self)

__invert__()#

~self

classmethod __iter__()#

Return members in definition order.

__le__(value, /)#

Return self<=value.

classmethod __len__()#

Return the number of members (no aliases)

__lshift__(value, /)#

Return self<<value.

__lt__(value, /)#

Return self<value.

__mod__(value, /)#

Return self%value.

__mul__(value, /)#

Return self*value.

__ne__(value, /)#

Return self!=value.

__neg__()#

-self

__new__(value)#
__or__(value, /)#

Return self|value.

__pos__()#

+self

__pow__(value, mod=None, /)#

Return pow(self, value, mod).

__radd__(value, /)#

Return value+self.

__rand__(value, /)#

Return value&self.

__rdivmod__(value, /)#

Return divmod(value, self).

__reduce_ex__(proto)#

Helper for pickle.

__repr__()#

Return repr(self).

__rfloordiv__(value, /)#

Return value//self.

__rlshift__(value, /)#

Return value<<self.

__rmod__(value, /)#

Return value%self.

__rmul__(value, /)#

Return value*self.

__ror__(value, /)#

Return value|self.

__round__()#

Rounding an Integral returns itself.

Rounding with an ndigits argument also returns an integer.

__rpow__(value, mod=None, /)#

Return pow(value, self, mod).

__rrshift__(value, /)#

Return value>>self.

__rshift__(value, /)#

Return self>>value.

__rsub__(value, /)#

Return value-self.

__rtruediv__(value, /)#

Return value/self.

__rxor__(value, /)#

Return value^self.

__sizeof__()#

Returns size in memory, in bytes.

__str__()#

Return repr(self).

__sub__(value, /)#

Return self-value.

__truediv__(value, /)#

Return self/value.

__trunc__()#

Truncating an Integral returns itself.

__xor__(value, /)#

Return self^value.

_generate_next_value_(start, count, last_values)#

Generate the next value when not given.

name: the name of the member start: the initial start value or None count: the number of existing members last_values: the list of values assigned

_member_type_#

alias of int

_new_member_(**kwargs)#

Create and return a new object. See help(type) for accurate signature.

_value_repr_()#

Return repr(self).

as_integer_ratio()#

Return integer ratio.

Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()#

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()#

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()#

Returns self, the complex conjugate of any int.

denominator#

the denominator of a rational number in lowest terms

classmethod fit_count_tag(count)[source]#

Fits count record tag.

Given the record sequence count, it fits the most compact count tag.

Parameters:

count (int) – Record sequence count.

Returns:

SrecTagCount record tag.

Raises:

ValueError – invalid count.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.fit_count_tag(0xFFFF)
<SrecTag.COUNT_16: 5>
>>> SrecTag.fit_count_tag(0xFFFFFF)
<SrecTag.COUNT_24: 6>
>>> SrecTag.fit_count_tag(0x1000000)
Traceback (most recent call last):
    ...
ValueError: count overflow
classmethod fit_data_tag(address_max)[source]#

Fits data record tag.

Given the maximum address of the involved data records, it fits the most compact data tag.

Parameters:

address_max (int) – Maximum address of the involved data records.

Returns:

SrecTagData record tag.

Raises:

ValueError – invalid address_max.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.fit_data_tag(0xFFFF)
<SrecTag.DATA_16: 1>
>>> SrecTag.fit_data_tag(0xFFFFFF)
<SrecTag.DATA_24: 2>
>>> SrecTag.fit_data_tag(0xFFFFFFFF)
<SrecTag.DATA_32: 3>
>>> SrecTag.fit_data_tag(0x100000000)
Traceback (most recent call last):
    ...
ValueError: address overflow
classmethod fit_start_tag(address)[source]#

Fits data record tag.

Given the start address, it fits the most compact start address tag.

Parameters:

address (int) – Start address.

Returns:

SrecTagStart address record tag.

Raises:

ValueError – invalid address.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.fit_start_tag(0xFFFF)
<SrecTag.START_16: 9>
>>> SrecTag.fit_start_tag(0xFFFFFF)
<SrecTag.START_24: 8>
>>> SrecTag.fit_start_tag(0xFFFFFFFF)
<SrecTag.START_32: 7>
>>> SrecTag.fit_start_tag(0x100000000)
Traceback (most recent call last):
    ...
ValueError: address overflow
from_bytes(byteorder='big', *, signed=False)#

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

get_address_max()[source]#

Calculates the maximum address.

It calculates the maximum address field for the calling tag. If the address field is not supported, it returns None.

Returns:

int – Maximum address value, or None.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> hex(SrecTag.DATA_32.get_address_max())
'0xffffffff'
>>> hex(SrecTag.START_32.get_address_max())
'0xffffffff'
>>> hex(SrecTag.COUNT_24.get_address_max())
'0xffffff'
>>> SrecTag.RESERVED.get_address_max()
0
get_address_size()[source]#

Calculates the maximum address size.

It calculates the maximum address field size for the calling tag. If the address field is not supported, it returns zero.

Returns:

int – Maximum address size, or None.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.DATA_32.get_address_size()
4
>>> SrecTag.START_32.get_address_size()
4
>>> SrecTag.COUNT_24.get_address_size()
3
>>> SrecTag.RESERVED.get_address_size()
0
get_data_max()[source]#

Calculates the maximum data size.

It calculates the maximum data field size for the calling tag. If the data field is not supported, it returns None.

Returns:

int – Maximum data size, or None.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.DATA_16.get_data_max()
252
>>> SrecTag.DATA_32.get_data_max()
250
>>> SrecTag.START_32.get_data_max()
0
get_tag_match()[source]#

Calculates the matching tag.

Given data or start address records, it returns the matching tag.

Returns:

SrecTag – Matching tag for self, or None

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.DATA_16.get_tag_match()
<SrecTag.START_16: 9>
>>> SrecTag.START_32.get_tag_match()
<SrecTag.DATA_32: 3>
>>> SrecTag.HEADER.get_tag_match() is None
True
imag#

the imaginary part of a complex number

is_count()[source]#

Tells whether this is a record count tag.

This method returns true if this record tag is used for record count records.

Returns:

bool – This is a record count tag.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.COUNT_16.is_count()
True
>>> SrecTag.COUNT_24.is_count()
True
>>> SrecTag.DATA_16.is_count()
False
is_header()[source]#

Tells whether this is a header record tag.

This method returns true if this record tag is used for header records.

Returns:

bool – This is a header record tag.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.HEADER.is_header()
True
>>> SrecTag.DATA_16.is_header()
False
is_start()[source]#

Tells whether this is a start address record tag.

This method returns true if this record tag is used for start address records.

Returns:

bool – This is a start address record tag.

Examples

>>> from hexrec import SrecFile
>>> SrecTag = SrecFile.Record.Tag
>>> SrecTag.START_16.is_start()
True
>>> SrecTag.START_32.is_start()
True
>>> SrecTag.DATA_16.is_start()
False
numerator#

the numerator of a rational number in lowest terms

real#

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)#

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.