Skip to content

Commit

Permalink
Adjusts module imports and __all__ for byteclasses for easier access …
Browse files Browse the repository at this point in the history
…to types.
  • Loading branch information
thetacom committed May 1, 2024
1 parent a449253 commit 73d779b
Show file tree
Hide file tree
Showing 48 changed files with 384 additions and 1,062 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ The `ByteArray` and `String` collections can be instantiated directly using the
## Simple Byteclass Structure Example

```python
from byteclasses.types.collections import structure
from byteclasses.types.primitives.integer import UInt8, UInt32
from byteclasses.types import structure, UInt8, UInt32

@structure
class MyStruct:
Expand Down
5 changes: 1 addition & 4 deletions byteclasses/handlers/executables/elf/elf_hdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from enum import IntEnum

from ....types.collections import String, member, structure
from ....types.primitives.byte_enum import ByteEnum
from ....types.primitives.generics import BitField
from ....types.primitives.integers import Ptr32, Ptr64, UInt16, UInt32
from ....types import BitField, ByteEnum, Ptr32, Ptr64, String, UInt16, UInt32, member, structure

__all__ = [
"ElfHdr32",
Expand Down
5 changes: 1 addition & 4 deletions byteclasses/handlers/executables/elf/phdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from enum import IntEnum

from ....types.collections import member, structure
from ....types.primitives.byte_enum import ByteEnum
from ....types.primitives.generics import BitField32, BitPos
from ....types.primitives.integers import Ptr32, Ptr64, UInt32, UInt64
from ....types import BitField32, BitPos, ByteEnum, Ptr32, Ptr64, UInt32, UInt64, member, structure

__all__ = [
"PHdr32",
Expand Down
5 changes: 1 addition & 4 deletions byteclasses/handlers/executables/elf/shdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from enum import IntEnum

from ....types.collections import member, structure
from ....types.primitives.byte_enum import ByteEnum
from ....types.primitives.generics import BitField32, BitPos
from ....types.primitives.integers import Ptr32, Ptr64, UInt32, UInt64
from ....types import BitField32, BitPos, ByteEnum, Ptr32, Ptr64, UInt32, UInt64, member, structure

__all__ = [
"SHdr32",
Expand Down
5 changes: 1 addition & 4 deletions byteclasses/handlers/executables/mach/mach_hdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from enum import IntEnum

from ....types.collections import structure
from ....types.primitives.bitfield import BitField32, mask2bitpos
from ....types.primitives.generics import DWord
from ....types.primitives.integers import Int32, UInt32
from ....types import BitField32, DWord, Int32, UInt32, mask2bitpos, structure

__all__ = [
"MachFlags32",
Expand Down
4 changes: 1 addition & 3 deletions byteclasses/handlers/executables/mach/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
[llvm::MachO Namespace Reference](https://llvm.org/doxygen/namespacellvm_1_1MachO.html)
"""

from ....types.collections import String, member, structure
from ....types.primitives.generics import BitField32
from ....types.primitives.integers import Ptr32, Ptr64, UInt32, UInt64
from ....types import BitField32, Ptr32, Ptr64, String, UInt32, UInt64, member, structure

__all__ = [
"Section32",
Expand Down
4 changes: 1 addition & 3 deletions byteclasses/handlers/executables/mach/seg_cmd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Mach-O Segment Command Module."""

from ....types.collections import String, member, structure
from ....types.primitives.generics import BitField32
from ....types.primitives.integers import Int32, Ptr32, Ptr64, UInt32, UInt64
from ....types import BitField32, Int32, Ptr32, Ptr64, String, UInt32, UInt64, member, structure

__all__ = [
"SegCmd32",
Expand Down
3 changes: 1 addition & 2 deletions byteclasses/handlers/executables/mach/uuid_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[llvm::MachO Namespace Reference](https://llvm.org/doxygen/namespacellvm_1_1MachO.html)
"""

from ....types.collections import ByteArray, member, structure
from ....types.primitives.integers import Ptr32, UInt32
from ....types import ByteArray, Ptr32, UInt32, member, structure

__all__ = ["UUIDCmd"]

Expand Down
2 changes: 1 addition & 1 deletion byteclasses/handlers/network/ipv4_hdr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""IPv4 Header class implemented with byteclasses."""

from byteclasses.types.collections import ByteArray, member, structure, union
from byteclasses.types.primitives.generics import BitField, BitPos
from byteclasses.types.primitives.bitfield import BitField, BitPos
from byteclasses.types.primitives.integers import UInt8, UInt16, UInt32


Expand Down
2 changes: 1 addition & 1 deletion byteclasses/handlers/network/ipv6_hdr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""IPv6 Header class implemented with byteclasses."""

from byteclasses.types.collections import ByteArray, member, structure, union
from byteclasses.types.primitives.generics import BitField, BitPos
from byteclasses.types.primitives.bitfield import BitField, BitPos
from byteclasses.types.primitives.integers import UInt8, UInt16, UInt32, UInt64


Expand Down
6 changes: 2 additions & 4 deletions byteclasses/handlers/network/tcp_hdr.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"""TCP Header implemented with byteclasses."""

from byteclasses.types.collections import structure
from byteclasses.types.primitives.generics import BitField, BitPos
from byteclasses.types.primitives.integers import UInt16, UInt32
from ...types import BitField, BitPos, UInt16, UInt32, structure


class OffFlag(BitField):
"""Offset and Flag BitField."""

byte_length = 2
data_offset = BitPos(0, bit_width=4)
flags = BitPos(4, bit_width=12)
tcp_flags = BitPos(4, bit_width=12)


@structure(byte_order=b"!", packed=True)
Expand Down
86 changes: 83 additions & 3 deletions byteclasses/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,85 @@
"""Byteclasses Types Module."""
"""Byteclass Types Package."""

from .primitives import floats, integers
# pylint: disable=R0801
from .collections import ByteArray, ByteclassCollection, String, make_fixed_collection, member, structure, union
from .primitives.bitfield import BitField, BitField16, BitField32, BitField64, BitPos, bitpos2mask, mask2bitpos
from .primitives.byte_enum import ByteEnum
from .primitives.byteclass_primitive_protocol import ByteclassPrimitive
from .primitives.characters import Char, SChar, UChar
from .primitives.floats import Double, Float, Float16, Float32, Float64, Half
from .primitives.generics import Bit, Byte, DWord, QWord, Word
from .primitives.integers import (
Int,
Int8,
Int16,
Int32,
Int64,
Long,
LongLong,
Ptr16,
Ptr32,
Ptr64,
Short,
UInt,
UInt8,
UInt16,
UInt32,
UInt64,
ULong,
ULongLong,
UnderflowError,
UShort,
)

__all__ = ["floats", "integers"]
__all__ = [
"Bit",
"BitField",
"BitField16",
"BitField32",
"BitField64",
"BitPos",
"bitpos2mask",
"Byte",
"ByteArray",
"ByteclassCollection",
"ByteclassPrimitive",
"ByteEnum",
"Char",
"Double",
"DWord",
"Float16",
"Float32",
"Float",
"Float64",
"Half",
"Int",
"Int8",
"Int16",
"Int32",
"Int64",
"Long",
"LongLong",
"make_fixed_collection",
"mask2bitpos",
"member",
"Ptr16",
"Ptr32",
"Ptr64",
"QWord",
"SChar",
"Short",
"String",
"structure",
"UChar",
"UInt",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"ULong",
"ULongLong",
"UnderflowError",
"union",
"UShort",
"Word",
]
76 changes: 73 additions & 3 deletions byteclasses/types/primitives/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
"""Fixed length types for binary data."""
"""Primitive Byteclasses Package."""

from . import floats, integers
# pylint: disable=R0801
from .bitfield import BitField, BitField16, BitField32, BitField64, BitPos
from .byte_enum import ByteEnum
from .byteclass_primitive_protocol import ByteclassPrimitive
from .characters import Char, SChar, UChar
from .floats import Double, Float, Float16, Float32, Float64, Half
from .generics import Bit, Byte, DWord, QWord, Word
from .integers import (
Int,
Int8,
Int16,
Int32,
Int64,
Long,
LongLong,
Ptr16,
Ptr32,
Ptr64,
Short,
UInt,
UInt8,
UInt16,
UInt32,
UInt64,
ULong,
ULongLong,
UnderflowError,
UShort,
)

__all__ = ["floats", "generics", "integers"]
__all__ = [
"Bit",
"BitField",
"BitField16",
"BitField32",
"BitField64",
"BitPos",
"Byte",
"ByteclassPrimitive",
"ByteEnum",
"Char",
"Double",
"DWord",
"Float16",
"Float32",
"Float",
"Float64",
"Half",
"Int",
"Int8",
"Int16",
"Int32",
"Int64",
"Long",
"LongLong",
"Ptr16",
"Ptr32",
"Ptr64",
"QWord",
"SChar",
"Short",
"UChar",
"UInt",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"ULong",
"ULongLong",
"UnderflowError",
"UShort",
"Word",
]
2 changes: 1 addition & 1 deletion byteclasses/types/primitives/bitfield.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""BitField Fixed Length Class."""
"""Primitive Byteclass BitField Type Module."""

from collections.abc import ByteString, Iterable, Sequence
from struct import calcsize
Expand Down
2 changes: 1 addition & 1 deletion byteclasses/types/primitives/byte_enum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A fixed size enum class."""
"""Primitive Byteclass ByteEnum Type Module."""

from collections.abc import ByteString
from enum import Enum, IntEnum
Expand Down
2 changes: 1 addition & 1 deletion byteclasses/types/primitives/characters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Fixed Size Character Primitives."""
"""Primitive Byteclass Character Types Module."""

from struct import calcsize

Expand Down
2 changes: 1 addition & 1 deletion byteclasses/types/primitives/floats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Fixed length floating point types."""
"""Primitive Byteclass Float Types Module."""

from collections.abc import ByteString
from struct import calcsize
Expand Down
8 changes: 1 addition & 7 deletions byteclasses/types/primitives/generics.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
"""Fixed Size Integer Types."""
"""Primitive Byteclass Generic Types Module."""

from enum import IntEnum
from struct import calcsize

from ..._enums import TypeChar
from ...types.primitives._primitive import _Primitive
from .bitfield import BitField, BitField16, BitField32, BitField64, BitPos

__all__ = [
"Bit",
"Byte",
"DWord",
"QWord",
"Word",
"BitField",
"BitField16",
"BitField32",
"BitField64",
"BitPos",
]


Expand Down
Loading

0 comments on commit 73d779b

Please sign in to comment.