• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tcalmant / python-javaobj / 26726380856

31 May 2026 10:31PM UTC coverage: 78.709% (+0.008%) from 78.701%
26726380856

Pull #63

github

web-flow
Merge 01d037f2a into 519fc2167
Pull Request #63: Addition of a v3 package

808 of 1023 new or added lines in 7 files covered. (78.98%)

2403 of 3053 relevant lines covered (78.71%)

4.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.27
/javaobj/v3/exceptions.py
1
#!/usr/bin/env python3
2
"""
3
Exception hierarchy for javaobj v3.
4

5
:authors: Thomas Calmant
6
:license: Apache License 2.0
7
:version: 0.5.0
8
:status: Alpha
9

10
..
11

12
    Copyright 2026 Thomas Calmant
13

14
    Licensed under the Apache License, Version 2.0 (the "License");
15
    you may not use this file except in compliance with the License.
16
    You may obtain a copy of the License at
17

18
        http://www.apache.org/licenses/LICENSE-2.0
19

20
    Unless required by applicable law or agreed to in writing, software
21
    distributed under the License is distributed on an "AS IS" BASIS,
22
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
    See the License for the specific language governing permissions and
24
    limitations under the License.
25
"""
26

27
# ------------------------------------------------------------------------------
28

29
# Module version
30
__version_info__ = (0, 5, 0)
3✔
31
__version__ = ".".join(str(x) for x in __version_info__)
3✔
32

33
# Documentation strings format
34
__docformat__ = "restructuredtext en"
3✔
35

36
# ------------------------------------------------------------------------------
37

38
__all__ = [
3✔
39
    "JavaObjError",
40
    "ParseError",
41
    "UnexpectedOpcodeError",
42
    "UnsupportedFeatureError",
43
    "SecurityError",
44
]
45

46

47
class JavaObjError(Exception):
3✔
48
    """Base exception for all javaobj v3 errors."""
49

50

51
class ParseError(JavaObjError):
3✔
52
    """Raised when the stream cannot be decoded according to the protocol."""
53

54
    def __init__(self, message: str, offset: int = -1) -> None:
3✔
55
        """
56
        :param message: Human-readable description of the problem.
57
        :param offset: Byte offset in the stream where the error occurred,
58
                       or -1 if unknown.
59
        """
60
        super().__init__(message)
3✔
61
        self.offset = offset
3✔
62

63
    def __str__(self) -> str:
3✔
64
        base = super().__str__()
3✔
65
        if self.offset >= 0:
3✔
66
            return f"{base} (at stream offset 0x{self.offset:x})"
3✔
NEW
67
        return base
×
68

69

70
class UnexpectedOpcodeError(ParseError):
3✔
71
    """
72
    Raised when an opcode byte is not among the set of expected values.
73

74
    Attributes:
75
        expected: Tuple of acceptable opcode values.
76
        got: The opcode that was actually read.
77
    """
78

79
    def __init__(
3✔
80
        self,
81
        expected: tuple[int, ...],
82
        got: int,
83
        offset: int = -1,
84
    ) -> None:
NEW
85
        expected_hex = [f"0x{e:02x}" for e in expected]
×
NEW
86
        super().__init__(
×
87
            f"Expected one of {expected_hex}, got 0x{got:02x}",
88
            offset,
89
        )
NEW
90
        self.expected = expected
×
NEW
91
        self.got = got
×
92

93

94
class UnsupportedFeatureError(JavaObjError):
3✔
95
    """Raised when the stream uses a feature not yet implemented in v3."""
96

97

98
class SecurityError(JavaObjError):
3✔
99
    """
100
    Raised when a configurable safety limit is exceeded.
101

102
    This guards against malicious streams that declare huge arrays, deeply
103
    nested object graphs, or extremely long strings to exhaust memory or
104
    the call stack.
105
    """
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc