From 67ffcff1d29deaf639fc67e572893512ed767779 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 9 Sep 2024 23:22:23 +0200 Subject: [PATCH] Raise `DeprecationWarning` from deprecated methods --- kaitaistruct.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/kaitaistruct.py b/kaitaistruct.py index 8905ac6..31f39b5 100644 --- a/kaitaistruct.py +++ b/kaitaistruct.py @@ -2,6 +2,7 @@ import sys import struct from io import open, BytesIO, SEEK_CUR, SEEK_END # noqa +import warnings PY2 = sys.version_info[0] == 2 @@ -322,9 +323,17 @@ def read_bits_int_be(self, n): return res - # Unused since Kaitai Struct Compiler v0.9+ - compatibility with - # older versions. def read_bits_int(self, n): + """Deprecated and no longer used as of KSC 0.9. It is only available + for backwards compatibility and will be removed in the future. + + KSC 0.9 and later uses `read_bits_int_be()` instead. + """ + warnings.warn( + "read_bits_int() is deprecated since 0.9, use read_bits_int_be() instead", + DeprecationWarning, + stacklevel=2, + ) return self.read_bits_int_be(n) def read_bits_int_le(self, n): @@ -457,6 +466,18 @@ def read_bytes_term_multi(self, term, include_term, consume_term, eos_error): r += c def ensure_fixed_contents(self, expected): + """Deprecated and no longer used as of KSC 0.9. It is only available + for backwards compatibility and will be removed in the future. + + KSC 0.9 and later explicitly raises `ValidationNotEqualError` from an + `if` statement instead. + """ + warnings.warn( + "ensure_fixed_contents() is deprecated since 0.9, explicitly raise " + "ValidationNotEqualError from an `if` statement instead", + DeprecationWarning, + stacklevel=2, + ) actual = self._io.read(len(expected)) if actual != expected: raise Exception(