Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
source = javaobj/

[report]
include = javaobj/*
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: CI Build

on:
push:
branches: '**'
tags: '**'
pull_request:
branches: '**'

jobs:
build:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=110 --statistics
- name: Test
run: |
coverage run -m pytest
- name: Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
pip install coveralls
coveralls
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# javaobj-py3

<p>
<a href="https://pypi.python.org/pypi/javaobj-py3/">
<img src="https://img.shields.io/pypi/v/javaobj-py3.svg" alt="Latest Version" />
<img src="https://img.shields.io/pypi/l/javaobj-py3.svg" alt="License" />
</a>
<a href="https://travis-ci.org/tcalmant/python-javaobj">
<img src="https://travis-ci.org/tcalmant/python-javaobj.svg?branch=master"
alt="Travis-CI status" />
</a>
<a href="https://coveralls.io/r/tcalmant/python-javaobj?branch=master">
<img src="https://coveralls.io/repos/tcalmant/python-javaobj/badge.svg?branch=master"
alt="Coveralls status" />
</a>
</p>
[![Latest Version](https://img.shields.io/pypi/v/javaobj-py3.svg)](https://pypi.python.org/pypi/javaobj-py3/)
[![License](https://img.shields.io/pypi/l/javaobj-py3.svg)](https://pypi.python.org/pypi/javaobj-py3/)
[![CI Build](https://github.com/tcalmant/python-javaobj/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/tcalmant/python-javaobj/actions/workflows/build.yml)
[![Coveralls status](https://coveralls.io/repos/tcalmant/python-javaobj/badge.svg?branch=master)](https://coveralls.io/r/tcalmant/python-javaobj?branch=master)

*python-javaobj* is a python library that provides functions for reading and
writing (writing is WIP currently) Java objects serialized or will be
Expand Down
38 changes: 34 additions & 4 deletions javaobj/v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@

from __future__ import absolute_import

from typing import Optional
from typing import List, Optional

from .beans import JavaClassDesc, JavaInstance # pylint:disable=W0611
from .stream import DataStreamReader # pylint:disable=W0611
from ..constants import TypeCode # pylint:disable=W0611
from .beans import ( # pylint:disable=W0611
JavaClassDesc,
JavaInstance,
ParsedJavaContent,
)
from .stream import DataStreamReader # pylint:disable=W0611

# ------------------------------------------------------------------------------

Expand All @@ -44,6 +48,32 @@
# ------------------------------------------------------------------------------


class IJavaStreamParser:
"""
API of the Java stream parser
"""

def run(self):
# type: () -> List[ParsedJavaContent]
"""
Parses the input stream
"""
raise NotImplementedError

def dump(self, content):
# type: (List[ParsedJavaContent]) -> str
"""
Dumps to a string the given objects
"""
raise NotImplementedError

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


class ObjectTransformer(object): # pylint:disable=R0205
"""
Representation of an object transformer
Expand Down Expand Up @@ -84,7 +114,7 @@ def load_array(
def load_custom_writeObject(
self, parser, reader, name
): # pylint:disable=W0613,R0201
# type: (JavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc]
# type: (IJavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc]
"""
Reads content stored from a custom writeObject.

Expand Down
4 changes: 2 additions & 2 deletions javaobj/v2/beans.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

from __future__ import absolute_import

import logging
from enum import IntEnum
from typing import Any, Dict, List, Optional, Set
import logging

from ..constants import ClassDescFlags, TypeCode
from ..modifiedutf8 import decode_modified_utf8, byte_to_int
from ..modifiedutf8 import byte_to_int, decode_modified_utf8
from ..utils import UNICODE_TYPE

# ------------------------------------------------------------------------------
Expand Down
47 changes: 23 additions & 24 deletions javaobj/v2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,45 @@

from __future__ import absolute_import

from typing import (
import logging
import os
from typing import ( # pylint:disable=W0611
IO,
Any,
Callable,
Dict,
IO,
List,
Optional,
) # pylint:disable=W0611
import logging
import os
)

from ..constants import (
PRIMITIVE_TYPES,
StreamConstants,
TerminalCode,
TypeCode,
)
from ..modifiedutf8 import ( # pylint:disable=W0611 # noqa: F401
decode_modified_utf8,
)
from . import api # pylint:disable=W0611
from .beans import (
ParsedJavaContent,
BlockData,
JavaClassDesc,
JavaClass,
ClassDataType,
ClassDescType,
ExceptionRead,
ExceptionState,
FieldType,
JavaArray,
JavaClass,
JavaClassDesc,
JavaEnum,
JavaField,
JavaInstance,
JavaString,
ExceptionState,
ExceptionRead,
ClassDescType,
FieldType,
ClassDataType,
ParsedJavaContent,
)
from .stream import DataStreamReader
from .transformers import DefaultObjectTransformer
from ..constants import (
StreamConstants,
TerminalCode,
TypeCode,
PRIMITIVE_TYPES,
)

from ..modifiedutf8 import (
decode_modified_utf8,
) # pylint:disable=W0611 # noqa: F401

# ------------------------------------------------------------------------------

Expand All @@ -80,7 +79,7 @@
# ------------------------------------------------------------------------------


class JavaStreamParser:
class JavaStreamParser(api.IJavaStreamParser):
"""
Parses a Java stream
"""
Expand Down
4 changes: 2 additions & 2 deletions javaobj/v2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import absolute_import

from typing import Any, IO # pylint:disable=W0611
from typing import IO, Any # pylint:disable=W0611

try:
# Python 2
Expand All @@ -14,10 +14,10 @@
# Python 3+
from io import BytesIO

from ..utils import java_data_fd
from .api import ObjectTransformer # pylint:disable=W0611
from .core import JavaStreamParser
from .transformers import DefaultObjectTransformer, NumpyArrayTransformer
from ..utils import java_data_fd

# ------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions javaobj/v2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

from __future__ import absolute_import

from typing import Any, IO, Tuple # pylint:disable=W0611
import struct
from typing import IO, Any, Tuple # pylint:disable=W0611

from ..modifiedutf8 import decode_modified_utf8
from ..utils import unicode_char, UNICODE_TYPE # pylint:disable=W0611
from ..utils import UNICODE_TYPE, unicode_char # pylint:disable=W0611

# ------------------------------------------------------------------------------

Expand Down
22 changes: 11 additions & 11 deletions javaobj/v2/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@
"""

# Standard library
from typing import List, Optional, Tuple
import functools
from typing import List, Optional, Tuple

# Numpy (optional)
try:
import numpy
except ImportError:
numpy = None

numpy = None # type: ignore

# Javaobj
from .api import ObjectTransformer
from .beans import (
JavaInstance,
JavaClassDesc,
BlockData,
) # pylint:disable=W0611
from ..constants import TerminalCode, TypeCode
from ..utils import to_bytes, log_error, log_debug, read_struct, read_string
from ..utils import log_debug, log_error, read_string, read_struct, to_bytes
from .api import IJavaStreamParser, ObjectTransformer
from .beans import ( # pylint:disable=W0611
BlockData,
JavaClassDesc,
JavaInstance,
)
from .stream import DataStreamReader

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -183,7 +183,7 @@ class JavaLinkedHashMap(JavaMap):
HANDLED_CLASSES = ("java.util.LinkedHashMap",)

def load_from_blockdata(self, parser, reader, indent=0):
# type: (JavaStreamParser, DataStreamReader, int) -> bool
# type: (IJavaStreamParser, DataStreamReader, int) -> bool
"""
Loads the content of the map, written with a custom implementation
"""
Expand Down
File renamed without changes.
7 changes: 2 additions & 5 deletions tests/tests_v2.py → tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@
# Standard library
import logging
import os
import struct
import subprocess
import sys
import unittest
import struct

from io import BytesIO

# Prepare Python path to import javaobj
sys.path.insert(0, os.path.abspath(os.path.dirname(os.getcwd())))

import javaobj.v2 as javaobj
# Local
from javaobj.utils import bytes_char, java_data_fd
import javaobj.v2 as javaobj

# ------------------------------------------------------------------------------

Expand All @@ -57,8 +56,6 @@

# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------

# Custom writeObject parsing classes
class CustomWriterInstance(javaobj.beans.JavaInstance):
def __init__(self):
Expand Down