Skip to content

Commit

Permalink
Renamed hexdump and xxd core functions as *_core
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Zoppi <texzk@email.it>
  • Loading branch information
TexZK committed Mar 2, 2024
1 parent d581eea commit db43051
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 55 deletions.
6 changes: 0 additions & 6 deletions docs/_autosummary/hexrec.hexdump.hexdump.rst

This file was deleted.

6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.hexdump.hexdump_core.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hexdump\_core
=============

.. currentmodule:: hexrec.hexdump

.. autofunction:: hexdump_core
2 changes: 1 addition & 1 deletion docs/_autosummary/hexrec.hexdump.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:template: custom-base-template.rst
:nosignatures:

~hexdump
~hexdump_core



Expand Down
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.xxd.HUMAN_ASCII.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HUMAN\_ASCII
============

.. currentmodule:: hexrec.xxd

.. autodata:: HUMAN_ASCII
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.xxd.HUMAN_EBCDIC.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HUMAN\_EBCDIC
=============

.. currentmodule:: hexrec.xxd

.. autodata:: HUMAN_EBCDIC
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.xxd.humanize.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
humanize
========

.. currentmodule:: hexrec.xxd

.. autofunction:: humanize
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.xxd.parse_seek.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parse\_seek
===========

.. currentmodule:: hexrec.xxd

.. autofunction:: parse_seek
21 changes: 21 additions & 0 deletions docs/_autosummary/hexrec.xxd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,35 @@



.. rubric:: Attributes

.. autosummary::
:toctree:
:template: custom-base-template.rst
:nosignatures:

~HUMAN_ASCII
~HUMAN_EBCDIC






.. rubric:: Functions

.. autosummary::
:toctree:
:template: custom-base-template.rst
:nosignatures:

~humanize
~parse_seek
~xxd_core







Expand Down
6 changes: 6 additions & 0 deletions docs/_autosummary/hexrec.xxd.xxd_core.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
xxd\_core
=========

.. currentmodule:: hexrec.xxd

.. autofunction:: xxd_core
2 changes: 1 addition & 1 deletion src/hexrec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .formats.srec import SrecFile
from .formats.titxt import TiTxtFile
from .formats.xtek import XtekFile
from .xxd import xxd
from .xxd import xxd_core


def _register_default_file_types():
Expand Down
4 changes: 2 additions & 2 deletions src/hexrec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
from .base import guess_format_name
from .formats.srec import SrecFile
from .formats.srec import SrecRecord
from .hexdump import hexdump as hexdump_core
from .hexdump import hexdump_core
from .utils import hexlify
from .utils import parse_int
from .utils import unhexlify
from .xxd import xxd as xxd_core
from .xxd import xxd_core


class BasedIntParamType(click.ParamType):
Expand Down
2 changes: 1 addition & 1 deletion src/hexrec/hexdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _format_two_bytes_hex(


# noinspection PyShadowingBuiltins
def hexdump(
def hexdump_core(
infile: Optional[Union[str, AnyBytes, IO]] = None,
outfile: Optional[Union[str, AnyBytes, IO]] = None,
one_byte_octal: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion src/hexrec/xxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def parse_seek(value: Optional[str]) -> Tuple[str, int]:
return ss, sv


def xxd(
def xxd_core(
infile: Optional[Union[str, AnyBytes, IO]] = None,
outfile: Optional[Union[str, AnyBytes, IO]] = None,
autoskip: bool = False,
Expand Down
26 changes: 14 additions & 12 deletions tests/test_hexdump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import glob
import io
import os
from pathlib import Path
from typing import Any
from typing import cast as _cast
Expand All @@ -9,7 +11,7 @@
from test_base import replace_stdout

from hexrec.cli import main as cli_main
from hexrec.hexdump import *
from hexrec.hexdump import hexdump_core


@pytest.fixture
Expand Down Expand Up @@ -93,7 +95,7 @@ def test_hexdump_io(datapath):
data_in = stream.read()
text_out = io.BytesIO()

hexdump(data_in, text_out)
hexdump_core(data_in, text_out)

text_out = text_out.getvalue().replace(b'\r\n', b'\n').decode()
text_ref = read_text(str(datapath / 'test_hexdump_bytes.bin.hexdump'))
Expand All @@ -105,25 +107,25 @@ def test_hexdump_raises(datapath, tmppath):
data_in = memoryview(stream.read())

with pytest.raises(NotImplementedError, match='"color" option is not supported'):
hexdump(data_in, color='')
hexdump_core(data_in, color='')

with pytest.raises(NotImplementedError, match='"format" option is not supported'):
hexdump(data_in, format='')
hexdump_core(data_in, format='')

with pytest.raises(NotImplementedError, match='"format_file" option is not supported'):
hexdump(data_in, format_file='')
hexdump_core(data_in, format_file='')

with pytest.raises(ValueError, match='negative skip'):
hexdump(data_in, skip=-1)
hexdump_core(data_in, skip=-1)

with pytest.raises(ValueError, match='negative length'):
hexdump(data_in, length=-1)
hexdump_core(data_in, length=-1)

with pytest.raises(ValueError, match='invalid width'):
hexdump(data_in, width=0)
hexdump_core(data_in, width=0)

with pytest.raises(ValueError, match='unknown format option'):
hexdump(data_in, format_order=['(this is a non-existing format)'])
hexdump_core(data_in, format_order=['(this is a non-existing format)'])


def test_hexdump_stdin_stdout(datapath):
Expand All @@ -133,7 +135,7 @@ def test_hexdump_stdin_stdout(datapath):
fake_stdout = io.BytesIO()

with replace_stdin(fake_stdin), replace_stdout(fake_stdout):
hexdump(linesep=b'\n')
hexdump_core(linesep=b'\n')

text_out = fake_stdout.getvalue().decode()
text_ref = read_text(str(datapath / 'test_hexdump_bytes.bin.hexdump'))
Expand All @@ -145,7 +147,7 @@ def test_hexdump_str(datapath, tmppath):
data_in = stream.read()
path_out = str(tmppath / 'test_hexdump_str.hexdump')

hexdump(data_in, path_out)
hexdump_core(data_in, path_out)

text_out = read_text(path_out)
text_ref = read_text(str(datapath / 'test_hexdump_bytes.bin.hexdump'))
Expand All @@ -156,7 +158,7 @@ def test_hexdump_stream(datapath):
fake_stdout = io.BytesIO()
with replace_stdout(fake_stdout):
with open(str(datapath / 'bytes.bin'), 'rb') as stream_in:
hexdump(stream_in, linesep=b'\n')
hexdump_core(stream_in, linesep=b'\n')

text_out = fake_stdout.getvalue().decode()
text_ref = read_text(str(datapath / 'test_hexdump_bytes.bin.hexdump'))
Expand Down
Loading

0 comments on commit db43051

Please sign in to comment.