Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove more Python2 hybridation #822

Merged
merged 2 commits into from
Nov 26, 2024
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
1 change: 0 additions & 1 deletion examples/BusmasterRestbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import division
import math
from struct import *
import zipfile
Expand Down
1 change: 0 additions & 1 deletion src/canmatrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import logging

import canmatrix._version
Expand Down
1 change: 0 additions & 1 deletion src/canmatrix/cancluster.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import typing
from builtins import *
Expand Down
4 changes: 1 addition & 3 deletions src/canmatrix/cli/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import, division, print_function

import logging
import sys
import typing
Expand Down Expand Up @@ -105,4 +103,4 @@ def cli_compare(matrix1, matrix2, verbosity, silent, check_comments, check_attri

# to be run as module `python -m canmatrix.compare`, NOT as script with argument `canmatrix/compare.py`
if __name__ == '__main__':
sys.exit(cli_compare())
sys.exit(cli_compare())
4 changes: 1 addition & 3 deletions src/canmatrix/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import, division, print_function

import logging
import sys

Expand Down Expand Up @@ -160,4 +158,4 @@ def cli_convert(infile, outfile, silent, verbosity, **options):


if __name__ == '__main__':
sys.exit(cli_convert())
sys.exit(cli_convert())
6 changes: 2 additions & 4 deletions src/canmatrix/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import, division, print_function

import logging
import sys
import typing
Expand All @@ -36,7 +34,7 @@


@attr.s
class CompareResult(object):
class CompareResult:
"""Hold comparison results in logical tree."""
result = attr.ib(default=None) # type: typing.Optional[str] # any of equal, added, deleted, changed
type = attr.ib(default=None) # type: typing.Optional[str] # db, ecu, frame, signal, signalGroup or attribute
Expand Down Expand Up @@ -508,4 +506,4 @@ def dump_result(res, depth=0):
" new: " +
str(res.changes[1]))
for child in res.children:
dump_result(child, depth + 1)
dump_result(child, depth + 1)
2 changes: 0 additions & 2 deletions src/canmatrix/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import, division, print_function

import copy
import logging
import sys
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import, division, print_function

import copy
import logging
import typing
Expand Down
1 change: 0 additions & 1 deletion src/canmatrix/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import importlib
import logging
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
# currently Support for Autosar 3.2 and 4.0-4.3 is planned
# AUTOSAR 4.2.2 is partial support -> 2024/05/20

from __future__ import absolute_import, division, print_function

import copy
import decimal
import logging
Expand Down
20 changes: 6 additions & 14 deletions src/canmatrix/formats/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# this script exports canmatrix-objects to a CSV file. (Based on xlsx)
# Author: Martin Hoffmann ([email protected])

from __future__ import absolute_import, division, print_function

import collections
import csv
import logging
Expand All @@ -47,9 +45,6 @@ def __getitem__(self, key): # type: (int) -> CsvDataType
return self._row_dict[key]

def __setitem__(self, key, item): # type: (int, CsvDataType) -> None
if sys.version_info <= (3, 0):
if type(item).__name__ == "unicode":
item = item.encode('utf-8')
self._row_dict[key] = item

def __add__(self, other): # type: (typing.Iterable[CsvDataType]) -> CsvRow
Expand Down Expand Up @@ -263,11 +258,8 @@ def dump(db, file_object, delimiter=',', **options):
# loop over signals ends here
# loop over frames ends here

if sys.version_info > (3, 0):
import io
temp = io.TextIOWrapper(file_object, encoding='UTF-8')
else:
temp = file_object
import io
temp = io.TextIOWrapper(file_object, encoding='UTF-8')

try:
writer = csv.writer(temp, delimiter=delimiter)
Expand All @@ -279,7 +271,7 @@ def dump(db, file_object, delimiter=',', **options):
# [row.toCSV(delimiter) for row in csv_table])
# print(finalTableString)
finally:
if sys.version_info > (3, 0):
# When TextIOWrapper is garbage collected, it closes the raw stream
# unless the raw stream is detached first
temp.detach()
# When TextIOWrapper is garbage collected, it closes the raw stream
# unless the raw stream is detached first
temp.detach()

2 changes: 0 additions & 2 deletions src/canmatrix/formats/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# this script exports dbc-files from a canmatrix-object
# dbc-files are the can-matrix-definitions of the CANoe (Vector Informatic)

from __future__ import absolute_import, division, print_function

import collections
import copy
import decimal
Expand Down
1 change: 0 additions & 1 deletion src/canmatrix/formats/dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# this script imports dbf-files in a canmatrix-object
# dbf-files are the can-matrix-definitions of the busmaster-project (http://rbei-etas.github.io/busmaster/)
#
from __future__ import absolute_import, division, print_function

import copy
import decimal
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/fibex.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
# only (fibex: Field Bus Exchange Format //
# https://de.wikipedia.org/wiki/Field_Bus_Exchange_Format)

from __future__ import absolute_import, division, print_function

import os
import typing
from builtins import *
Expand Down
25 changes: 7 additions & 18 deletions src/canmatrix/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
# json-files are the can-matrix-definitions of the CANard-project
# (https://github.com/ericevenchick/CANard)

from __future__ import absolute_import, division, print_function

import json
import sys
import typing
from builtins import *
import decimal
Expand Down Expand Up @@ -181,33 +178,25 @@ def dump(db, f, **options):
"header_id": frame.header_id,
"pdu_name": frame.pdu_name,
"transmitters": frame.transmitters})
if sys.version_info > (3, 0):
import io
temp = io.TextIOWrapper(f, encoding='UTF-8')
else:
temp = f
import io
temp = io.TextIOWrapper(f, encoding='UTF-8')

try:
json.dump(export_dict, temp, sort_keys=True,
indent=4, separators=(',', ': '))
finally:
if sys.version_info > (3, 0):
# When TextIOWrapper is garbage collected, it closes the raw stream
# unless the raw stream is detached first
temp.detach()
# When TextIOWrapper is garbage collected, it closes the raw stream
# unless the raw stream is detached first
temp.detach()


def load(f, **_options):
# type: (typing.BinaryIO, **str) -> canmatrix.CanMatrix

db = canmatrix.CanMatrix()

if sys.version_info > (3, 0):
import io
json_data = json.load(io.TextIOWrapper(f, encoding='UTF-8'))
else:

json_data = json.load(f)
import io
json_data = json.load(io.TextIOWrapper(f, encoding='UTF-8'))

if "enumerations" in json_data:
for val_tab_name, val_tab_dict in json_data['enumerations'].items():
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/kcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
# kcd-files are the can-matrix-definitions of the kayak
# (http://kayak.2codeornot2code.org/)

from __future__ import absolute_import, division, print_function

import decimal
import os
import re
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/ldf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import ldfparser
import canmatrix
import ldfparser.encoding
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/odx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from lxml import etree
import canmatrix.formats
import decimal
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/scapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# this script exports scapy python files
# https://scapy.readthedocs.io/en/latest/advanced_usage.html#automotive-usage

from __future__ import absolute_import, division, print_function

import textwrap
import typing
from builtins import *
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# this script exports sym-files from a canmatrix-object
# sym-files are the can-matrix-definitions of the Peak Systems Tools

from __future__ import absolute_import, division, print_function

import collections
import decimal
import logging
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# this script exports xls-files from a canmatrix-object
# xls-files are the can-matrix-definitions displayed in Excel

from __future__ import absolute_import, division, print_function

import decimal
import logging
import typing
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/xls_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

from __future__ import absolute_import, division, print_function

import typing
from builtins import *

Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# this script exports xls-files from a canmatrix-object
# xls-files are the can-matrix-definitions displayed in Excel

from __future__ import absolute_import, division, print_function

import logging
import typing
from builtins import *
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/formats/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# yaml-files are just object-dumps human readable.
# This export is complete, no information lost

from __future__ import absolute_import, division, print_function

import copy
import typing
from builtins import *
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/j1939_decoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

from builtins import *

import attr
Expand Down
1 change: 0 additions & 1 deletion src/canmatrix/join.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import typing
from builtins import *
Expand Down
2 changes: 0 additions & 2 deletions src/canmatrix/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# Configurable logging
# Author: Martin Hoffmann ([email protected])

from __future__ import absolute_import, division, print_function

import logging


Expand Down
5 changes: 1 addition & 4 deletions src/canmatrix/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import csv
import shlex
Expand All @@ -16,9 +15,7 @@


def quote_aware_space_split(in_line): # type: (str) -> typing.List[str]
if sys.version_info >= (3, 0): # is there a clean way to to it?
return shlex.split(in_line.strip())
return [item.decode('utf-8') for item in shlex.split(in_line.strip().encode('utf-8'))]
return shlex.split(in_line.strip())


# https://stackoverflow.com/questions/18092354/python-split-string-without-splitting-escaped-character
Expand Down
8 changes: 2 additions & 6 deletions tests/createTestMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@

myFrame = Frame("testFrame1", Id=0x123, dlc=8, transmitter="testBU")

if sys.version_info > (3, 0):
unit = u"specialCharUnit°$"
comment = u"Multi \n Line \n Signal comment with a-umlaut: ä"
else:
unit = "specialCharUnit°$".decode("utf-8")
comment = "Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8")
unit = "specialCharUnit°$"
comment = "Multi \n Line \n Signal comment with a-umlaut: ä"

mySignal = Signal("someTestSignal",
signalSize=11,
Expand Down
2 changes: 0 additions & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python3

from __future__ import absolute_import, division, print_function

import copy
import os
import shutil
Expand Down
Loading