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

tcalmant / python-javaobj / 8591112367

07 Apr 2024 07:18PM UTC coverage: 78.701%. First build
8591112367

push

github

tcalmant
Added 3.11 & 3.12 to GitHub actions

1611 of 2047 relevant lines covered (78.7%)

4.71 hits per line

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

86.36
/javaobj/v2/api.py
1
#!/usr/bin/env python3
2
"""
6✔
3
Definition of the object transformer API
4

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

10
..
11

12
    Copyright 2024 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
from __future__ import absolute_import
6✔
28

29
from typing import List, Optional
6✔
30

31
from ..constants import TypeCode  # pylint:disable=W0611
6✔
32
from .beans import (  # pylint:disable=W0611
6✔
33
    JavaClassDesc,
34
    JavaInstance,
35
    ParsedJavaContent,
36
)
37
from .stream import DataStreamReader  # pylint:disable=W0611
6✔
38

39
# ------------------------------------------------------------------------------
40

41
# Module version
42
__version_info__ = (0, 4, 4)
6✔
43
__version__ = ".".join(str(x) for x in __version_info__)
6✔
44

45
# Documentation strings format
46
__docformat__ = "restructuredtext en"
6✔
47

48
# ------------------------------------------------------------------------------
49

50

51
class IJavaStreamParser:
6✔
52
    """
53
    API of the Java stream parser
54
    """
55

56
    def run(self):
6✔
57
        # type: () -> List[ParsedJavaContent]
58
        """
59
        Parses the input stream
60
        """
61
        raise NotImplementedError
×
62

63
    def dump(self, content):
6✔
64
        # type: (List[ParsedJavaContent]) -> str
65
        """
66
        Dumps to a string the given objects
67
        """
68
        raise NotImplementedError
×
69

70
    def _read_content(self, type_code, block_data, class_desc=None):
6✔
71
        # type: (int, bool, Optional[JavaClassDesc]) -> ParsedJavaContent
72
        """
73
        Parses the next content. Use with care (use only in a transformer)
74
        """
75

76

77
class ObjectTransformer(object):  # pylint:disable=R0205
6✔
78
    """
79
    Representation of an object transformer
80
    """
81

82
    def create_instance(self, classdesc):  # pylint:disable=W0613,R0201
6✔
83
        # type: (JavaClassDesc) -> Optional[JavaInstance]
84
        """
85
        Transforms a parsed Java object into a Python object.
86

87
        The result must be a JavaInstance bean, or None if the transformer
88
        doesn't support this kind of instance.
89

90
        :param classdesc: The description of a Java class
91
        :return: The Python form of the object, or the original JavaObject
92
        """
93
        return None
×
94

95
    def load_array(
6✔
96
        self, reader, type_code, size
97
    ):  # pylint:disable=W0613,R0201
98
        # type: (DataStreamReader, TypeCode, int) -> Optional[list]
99
        """
100
        Loads and returns the content of a Java array, if possible.
101

102
        The result of this method must be the content of the array, i.e. a list
103
        or an array. It will be stored in a JavaArray bean created by the
104
        parser.
105

106
        This method must return None if it can't handle the array.
107

108
        :param reader: The data stream reader
109
        :param type_code: Type of the elements of the array
110
        :param size: Number of elements in the array
111
        """
112
        return None
6✔
113

114
    def load_custom_writeObject(
6✔
115
        self, parser, reader, name
116
    ):  # pylint:disable=W0613,R0201
117
        # type: (IJavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc]
118
        """
119
        Reads content stored from a custom writeObject.
120

121
        This method is called only if the class description has both the
122
        ``SC_SERIALIZABLE`` and ``SC_WRITE_METHOD`` flags set.
123

124
        The stream parsing will stop and fail if this method returns None.
125

126
        :param parser: The JavaStreamParser in use
127
        :param reader: The data stream reader
128
        :param name: The class description name
129
        :return: A Java class description, if handled, else None
130
        """
131
        return None
6✔
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

© 2025 Coveralls, Inc