From fcd156a77012a8bd702b90d01ea1527a75e8fdb3 Mon Sep 17 00:00:00 2001 From: Tomas Novak Date: Wed, 18 Sep 2019 17:43:04 +0200 Subject: [PATCH] unify imports (#236) --- src/canmatrix/cancluster.py | 3 +- src/canmatrix/canmatrix.py | 10 +++--- src/canmatrix/cli/compare.py | 3 +- src/canmatrix/cli/convert.py | 3 +- src/canmatrix/compare.py | 4 +-- src/canmatrix/convert.py | 3 +- src/canmatrix/copy.py | 2 +- src/canmatrix/formats/__init__.py | 7 ++-- src/canmatrix/formats/arxml.py | 36 +++++++++---------- src/canmatrix/formats/cmcsv.py | 2 +- src/canmatrix/formats/cmjson.py | 2 +- src/canmatrix/formats/dbc.py | 4 +-- src/canmatrix/formats/dbf.py | 4 +-- src/canmatrix/formats/fibex.py | 26 +++++++------- src/canmatrix/formats/kcd.py | 55 ++++++++++++++--------------- src/canmatrix/formats/scapy.py | 2 ++ src/canmatrix/formats/sym.py | 3 +- src/canmatrix/formats/xls.py | 4 +-- src/canmatrix/formats/xls_common.py | 2 ++ src/canmatrix/formats/xlsx.py | 4 +-- src/canmatrix/formats/yaml.py | 3 +- src/canmatrix/j1939_decoder.py | 2 +- src/canmatrix/join.py | 2 ++ src/canmatrix/log.py | 2 +- src/canmatrix/utils.py | 2 ++ 25 files changed, 92 insertions(+), 98 deletions(-) diff --git a/src/canmatrix/cancluster.py b/src/canmatrix/cancluster.py index 73612e2d..1dea5de6 100644 --- a/src/canmatrix/cancluster.py +++ b/src/canmatrix/cancluster.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function + import typing import canmatrix diff --git a/src/canmatrix/canmatrix.py b/src/canmatrix/canmatrix.py index 392b6950..8c6f9633 100644 --- a/src/canmatrix/canmatrix.py +++ b/src/canmatrix/canmatrix.py @@ -26,23 +26,23 @@ # TODO: Definitions should be disassembled -from __future__ import division, absolute_import +from __future__ import absolute_import, division, print_function import decimal import fnmatch +import itertools import logging import math import struct import typing -from itertools import chain try: from itertools import zip_longest as zip_longest except ImportError: from itertools import izip_longest as zip_longest # type: ignore -from past.builtins import basestring import attr +from past.builtins import basestring import canmatrix.copy import canmatrix.types @@ -1057,7 +1057,7 @@ def get_frame_layout(self): big_bit_signals.append(signal) little_bits_iter = reversed(tuple(grouper(little_bits, 8))) - little_bits = list(chain(*little_bits_iter)) + little_bits = list(itertools.chain(*little_bits_iter)) return_list = [ little + big @@ -1119,7 +1119,7 @@ def signals_to_bytes(self, data): big_bits[most:least] = bits little_bits_iter = reversed(tuple(grouper(little_bits, 8))) - little_bits = list(chain(*little_bits_iter)) + little_bits = list(itertools.chain(*little_bits_iter)) bitstring = ''.join( next(x for x in (l, b, '0') if x is not None) # l if l != ' ' else (b if b != ' ' else '0') diff --git a/src/canmatrix/cli/compare.py b/src/canmatrix/cli/compare.py index f157c298..06be79d7 100644 --- a/src/canmatrix/cli/compare.py +++ b/src/canmatrix/cli/compare.py @@ -21,8 +21,7 @@ # 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 -from __future__ import print_function +from __future__ import absolute_import, division, print_function import logging import sys diff --git a/src/canmatrix/cli/convert.py b/src/canmatrix/cli/convert.py index 21e62756..0a5d331a 100644 --- a/src/canmatrix/cli/convert.py +++ b/src/canmatrix/cli/convert.py @@ -21,8 +21,7 @@ # 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 -from __future__ import print_function +from __future__ import absolute_import, division, print_function import logging import sys diff --git a/src/canmatrix/compare.py b/src/canmatrix/compare.py index d8a0d667..5dfc6b8a 100644 --- a/src/canmatrix/compare.py +++ b/src/canmatrix/compare.py @@ -19,11 +19,9 @@ # 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 -from __future__ import print_function +from __future__ import absolute_import, division, print_function import logging -import optparse import sys import typing diff --git a/src/canmatrix/convert.py b/src/canmatrix/convert.py index 24d28334..10d40055 100644 --- a/src/canmatrix/convert.py +++ b/src/canmatrix/convert.py @@ -19,8 +19,7 @@ # 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 -from __future__ import print_function +from __future__ import absolute_import, division, print_function import logging import sys diff --git a/src/canmatrix/copy.py b/src/canmatrix/copy.py index 1c50f498..3d200c83 100644 --- a/src/canmatrix/copy.py +++ b/src/canmatrix/copy.py @@ -19,7 +19,7 @@ # 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 +from __future__ import absolute_import, division, print_function import copy import logging diff --git a/src/canmatrix/formats/__init__.py b/src/canmatrix/formats/__init__.py index 3b965104..9712c3fc 100644 --- a/src/canmatrix/formats/__init__.py +++ b/src/canmatrix/formats/__init__.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- -from importlib import import_module -import sys +import importlib import logging import os +import sys import typing import canmatrix import canmatrix.cancluster + if sys.version_info > (3, 0): import io else: @@ -21,7 +22,7 @@ for module in moduleList: try: - import_module("canmatrix.formats." + module) + importlib.import_module("canmatrix.formats." + module) loadedFormats.append(module) except ImportError: logger.info("%s is not supported", module) diff --git a/src/canmatrix/formats/arxml.py b/src/canmatrix/formats/arxml.py index 4602ef28..cb6343d8 100644 --- a/src/canmatrix/formats/arxml.py +++ b/src/canmatrix/formats/arxml.py @@ -24,16 +24,14 @@ # arxml-files are the can-matrix-definitions and a lot more in AUTOSAR-Context # currently Support for Autosar 3.2 and 4.0-4.3 is planned -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function +from __future__ import absolute_import, division, print_function import decimal import logging import typing from builtins import * -from lxml import etree +import lxml.etree import canmatrix import canmatrix.types @@ -47,7 +45,7 @@ class ArTree(object): - def __init__(self, name="", ref=None): # type: (str, etree._Element) -> None + def __init__(self, name="", ref=None): # type: (str, lxml.etree._Element) -> None self._name = name self._ref = ref self._array = [] # type: typing.List[ArTree] @@ -65,12 +63,12 @@ def get_child_by_name(self, name): # type: (str) -> typing.Union[ArTree, None] return None @property - def ref(self): # type: () -> etree._Element + def ref(self): # type: () -> lxml.etree._Element return self._ref # for typing only -_Element = etree._Element +_Element = lxml.etree._Element _DocRoot = typing.Union[_Element, ArTree] _MultiplexId = typing.Union[str, int, None] _FloatFactory = typing.Callable[[typing.Any], typing.Any] @@ -78,7 +76,7 @@ def ref(self): # type: () -> etree._Element def create_sub_element(parent, element_name, text=None): # type: (_Element, str, typing.Optional[str]) -> _Element - sn = etree.SubElement(parent, element_name) + sn = lxml.etree.SubElement(parent, element_name) if text is not None: sn.text = str(text) return sn @@ -135,7 +133,7 @@ def dump(dbs, f, **options): if ar_version[0] == "3": xsi = 'http://www.w3.org/2001/XMLSchema-instance' - root = etree.Element( + root = lxml.etree.Element( 'AUTOSAR', nsmap={ None: 'http://autosar.org/' + ar_version, @@ -145,7 +143,7 @@ def dump(dbs, f, **options): top_level_packages = create_sub_element(root, 'TOP-LEVEL-PACKAGES') else: xsi = 'http://www.w3.org/2001/XMLSchema-instance' - root = etree.Element( + root = lxml.etree.Element( 'AUTOSAR', nsmap={ None: "http://autosar.org/schema/r4.0", @@ -760,7 +758,7 @@ def dump(dbs, f, **options): ipdu_ref.set('DEST', "I-SIGNAL-I-PDU") ipdu_ref.text = "/PDU/PDU_" + frame_name - f.write(etree.tostring(root, pretty_print=True, xml_declaration=True)) + f.write(lxml.etree.tostring(root, pretty_print=True, xml_declaration=True)) ################################### @@ -1000,7 +998,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact base_type = get_child(isignal, "BASE-TYPE", root_or_cache, ns) try: - type_encoding = get_child(base_type,"BASE-TYPE-ENCODING", root_or_cache, ns).text + type_encoding = get_child(base_type, "BASE-TYPE-ENCODING", root_or_cache, ns).text except AttributeError: type_encoding = "None" signal_name = None # type: typing.Optional[str] @@ -1192,6 +1190,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact new_signal.add_attribute("LongName", signal_name) frame.add_signal(new_signal) + def get_frame_from_multiplexed_ipdu(pdu, target_frame, multiplex_translation, root_or_cache, ns, float_factory): selector_byte_order = get_child(pdu, "SELECTOR-FIELD-BYTE-ORDER", root_or_cache, ns) selector_len = get_child(pdu, "SELECTOR-FIELD-LENGTH", root_or_cache, ns) @@ -1244,8 +1243,8 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa header_type = get_child(pdu, "HEADER-TYPE", root_or_cache, ns).text if header_type == "SHORT-HEADER": header_length = 32 - target_frame.add_signal(canmatrix.Signal(start_bit=0, size=24, name="Header_ID", multiplex ="Multiplexor", is_little_endian = True)) - target_frame.add_signal(canmatrix.Signal(start_bit=24, size= 8, name="Header_DLC", is_little_endian = True)) + target_frame.add_signal(canmatrix.Signal(start_bit=0, size=24, name="Header_ID", multiplex="Multiplexor", is_little_endian=True)) + target_frame.add_signal(canmatrix.Signal(start_bit=24, size=8, name="Header_DLC", is_little_endian=True)) elif header_type == "LONG-HEADER": header_length = 64 target_frame.add_signal(canmatrix.Signal(start_bit=0, size=32, name="Header_ID", multiplex="Multiplexor", @@ -1254,7 +1253,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa else: raise("header " + header_type + " not supported for containers yet") # none type - #TODO + # TODO for cpdu in pdus: ipdu = get_child(cpdu, "I-PDU", root_or_cache, ns) @@ -1264,7 +1263,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa elif header_type == "LONG-HEADER": header_id = get_child(ipdu, "HEADER-ID-LONG-HEADER", root_or_cache, ns).text else: - #none type + # none type pass except AttributeError: header_id = "0" @@ -1286,6 +1285,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa singnals_grouped += new_signals signal_group_id += 1 + def store_frame_timings(target_frame, cyclic_timing, event_timing, minimum_delay, repeats, starting_time, time_offset, repeating_time, root_or_cache, time_period, ns, float_factory): if cyclic_timing is not None and event_timing is not None: target_frame.add_attribute("GenMsgSendType", "cyclicAndSpontanX") # CycleAndSpontan @@ -1602,7 +1602,7 @@ def load(file, **options): result = {} logger.debug("Read arxml ...") - tree = etree.parse(file) + tree = lxml.etree.parse(file) root = tree.getroot() # type: _Element logger.debug(" Done\n") @@ -1650,7 +1650,7 @@ def load(file, **options): logger.debug("%d I-SIGNAL-TO-I-PDU-MAPPING in arxml...", len(sig_ipdu)) if ignore_cluster_info is True: - ccs = [etree.Element("ignoreClusterInfo")] # type: typing.Sequence[_Element] + ccs = [lxml.etree.Element("ignoreClusterInfo")] # type: typing.Sequence[_Element] else: ccs = root.findall('.//' + ns + 'CAN-CLUSTER') for cc in ccs: # type: _Element diff --git a/src/canmatrix/formats/cmcsv.py b/src/canmatrix/formats/cmcsv.py index fcca2960..ef77fdf5 100644 --- a/src/canmatrix/formats/cmcsv.py +++ b/src/canmatrix/formats/cmcsv.py @@ -23,7 +23,7 @@ # this script exports canmatrix-objects to a CSV file. (Based on xlsx) # Author: Martin Hoffmann (m8ddin@gmail.com) -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function import collections import csv diff --git a/src/canmatrix/formats/cmjson.py b/src/canmatrix/formats/cmjson.py index 459df00c..2fa565be 100644 --- a/src/canmatrix/formats/cmjson.py +++ b/src/canmatrix/formats/cmjson.py @@ -24,7 +24,7 @@ # json-files are the can-matrix-definitions of the CANard-project # (https://github.com/ericevenchick/CANard) -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function import json import sys diff --git a/src/canmatrix/formats/dbc.py b/src/canmatrix/formats/dbc.py index 81280e59..c51884e2 100644 --- a/src/canmatrix/formats/dbc.py +++ b/src/canmatrix/formats/dbc.py @@ -23,9 +23,7 @@ # 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 -from __future__ import division -from __future__ import print_function +from __future__ import absolute_import, division, print_function import collections import copy diff --git a/src/canmatrix/formats/dbf.py b/src/canmatrix/formats/dbf.py index 8633c560..69a91d39 100644 --- a/src/canmatrix/formats/dbf.py +++ b/src/canmatrix/formats/dbf.py @@ -23,9 +23,7 @@ # 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 -from __future__ import division -from __future__ import print_function +from __future__ import absolute_import, division, print_function import copy import decimal diff --git a/src/canmatrix/formats/fibex.py b/src/canmatrix/formats/fibex.py index 727ba4f6..8722b37e 100644 --- a/src/canmatrix/formats/fibex.py +++ b/src/canmatrix/formats/fibex.py @@ -25,11 +25,11 @@ # only (fibex: Field Bus Exchange Format // # https://de.wikipedia.org/wiki/Field_Bus_Exchange_Format) -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function import typing from builtins import * -from lxml import etree +import lxml.etree import canmatrix @@ -45,20 +45,20 @@ extension = "xml" # noinspection PyProtectedMember -_Element = etree._Element +_Element = lxml.etree._Element def create_short_name_desc(parent, short_name, desc): # type: (_Element, str, str) -> None - short_name_elem = etree.SubElement(parent, ns_ho + "SHORT-NAME") + short_name_elem = lxml.etree.SubElement(parent, ns_ho + "SHORT-NAME") short_name_elem.text = short_name - desc_elem = etree.SubElement(parent, ns_ho + "DESC") + desc_elem = lxml.etree.SubElement(parent, ns_ho + "DESC") desc_elem.text = desc def create_sub_element_fx(parent, element_name, element_text=None): # type: (_Element, str, typing.Optional[str]) -> _Element - new = etree.SubElement(parent, ns_fx + element_name) + new = lxml.etree.SubElement(parent, ns_fx + element_name) if element_text is not None: new.text = element_text return new @@ -66,7 +66,7 @@ def create_sub_element_fx(parent, element_name, element_text=None): def create_sub_element_ho(parent, element_name, element_text=None): # type: (_Element, str, typing.Optional[str]) -> _Element - new = etree.SubElement(parent, ns_ho + element_name) + new = lxml.etree.SubElement(parent, ns_ho + element_name) if element_text is not None: new.text = element_text return new @@ -75,7 +75,7 @@ def create_sub_element_ho(parent, element_name, element_text=None): def dump(db, f, **options): # type: (canmatrix.CanMatrix, typing.IO, **typing.Any) -> None ns_map = {"fx": fx, "ho": ho, "can": can, "xsi": xsi} - root = etree.Element(ns_fx + "FIBEX", nsmap=ns_map) + root = lxml.etree.Element(ns_fx + "FIBEX", nsmap=ns_map) root.attrib[ '{{{pre}}}schemaLocation'.format( pre=xsi)] = 'http://www.asam.net/xml/fbx ..\\..\\xml_schema\\fibex.xsd http://www.asam.net/xml/fbx/can ..\\..\\xml_schema\\fibex4can.xsd' @@ -96,7 +96,7 @@ def dump(db, f, **options): # CLUSTERS # clusters = create_sub_element_fx(elements, "CLUSTERS") - cluster = etree.SubElement(clusters, ns_fx + "CLUSTER") + cluster = lxml.etree.SubElement(clusters, ns_fx + "CLUSTER") cluster.set('ID', 'canCluster1') create_short_name_desc(cluster, "clusterShort", "clusterDesc") create_sub_element_fx(cluster, "SPEED", "500") @@ -200,7 +200,7 @@ def dump(db, f, **options): if bu.name in signal.receivers: input_port = create_sub_element_fx(input_ports, "INPUT-PORT") input_port.set("ID", "INP_" + signal.name) - desc = etree.SubElement(input_port, ns_ho + "DESC") + desc = lxml.etree.SubElement(input_port, ns_ho + "DESC") desc.text = signal.comment signal_ref = create_sub_element_fx(input_port, "SIGNAL-REF") signal_ref.set("ID-REF", "SIG_" + signal.name) @@ -210,7 +210,7 @@ def dump(db, f, **options): for signal in frame.signals: output_port = create_sub_element_fx(input_ports, "OUTPUT-PORT") output_port.set("ID", "OUTP_" + signal.name) - desc = etree.SubElement(output_port, ns_ho + "DESC") + desc = lxml.etree.SubElement(output_port, ns_ho + "DESC") desc.text = "signalcomment" signal_ref = create_sub_element_fx(output_port, "SIGNAL-REF") signal_ref.set("ID-REF", "SIG_" + signal.name) @@ -230,7 +230,7 @@ def dump(db, f, **options): # # PROCESSING-INFORMATION # - proc_info = etree.SubElement(elements, ns_fx + "PROCESSING-INFORMATION", nsmap={"ho": ho}) + proc_info = lxml.etree.SubElement(elements, ns_fx + "PROCESSING-INFORMATION", nsmap={"ho": ho}) unit_spec = create_sub_element_ho(proc_info, "UNIT-SPEC") for frame in db.frames: for signal in frame.signals: @@ -286,4 +286,4 @@ def dump(db, f, **options): # # requirements = createSubElementFx(elements, "REQUIREMENTS") - f.write(etree.tostring(root, pretty_print=True)) + f.write(lxml.etree.tostring(root, pretty_print=True)) diff --git a/src/canmatrix/formats/kcd.py b/src/canmatrix/formats/kcd.py index 1e577d00..051796c6 100644 --- a/src/canmatrix/formats/kcd.py +++ b/src/canmatrix/formats/kcd.py @@ -24,8 +24,7 @@ # kcd-files are the can-matrix-definitions of the kayak # (http://kayak.2codeornot2code.org/) -from __future__ import absolute_import -from __future__ import division +from __future__ import absolute_import, division, print_function import decimal import os @@ -33,7 +32,7 @@ import typing from builtins import * -from lxml import etree +import lxml.etree import canmatrix import canmatrix.cancluster @@ -41,7 +40,7 @@ clusterExporter = 1 clusterImporter = 1 -_Element = etree._Element +_Element = lxml.etree._Element def default_float_factory(value): # type: (typing.Any) -> decimal.Decimal @@ -50,7 +49,7 @@ def default_float_factory(value): # type: (typing.Any) -> decimal.Decimal def create_signal(signal, node_list, type_enums): # type: (canmatrix.Signal, typing.Mapping[str, int], typing.Mapping[str, typing.Sequence[str]]) -> _Element - xml_signal = etree.Element( + xml_signal = lxml.etree.Element( 'Signal', name=signal.name, offset=str(signal.get_startbit())) @@ -72,18 +71,18 @@ def create_signal(signal, node_list, type_enums): comment += "\n" + more_comments if comment: - notes = etree.Element('Notes') + notes = lxml.etree.Element('Notes') notes.text = comment xml_signal.append(notes) - consumer = etree.Element('Consumer') + consumer = lxml.etree.Element('Consumer') for receiver in signal.receivers: if receiver in node_list and len(receiver) > 1: - node_ref = etree.Element('NodeRef', id=str(node_list[receiver])) + node_ref = lxml.etree.Element('NodeRef', id=str(node_list[receiver])) consumer.append(node_ref) if len(consumer) > 0: # if consumer has children xml_signal.append(consumer) - value = etree.Element('Value') + value = lxml.etree.Element('Value') if signal.is_float: if signal.size > 32: value.set('type', "double") @@ -107,9 +106,9 @@ def create_signal(signal, node_list, type_enums): xml_signal.append(value) if signal.values: # signal has value table - label_set = etree.Element('LabelSet') + label_set = lxml.etree.Element('LabelSet') for table_value, table_name in sorted(signal.values.items(), key=lambda x: int(x[0])): - label = etree.Element( + label = lxml.etree.Element( 'Label', name=table_name.replace('"', ''), value=str(table_value)) @@ -135,15 +134,15 @@ def dump(dbs, f, **_options): signal_type_enums[typename] = enum_literals # create XML - root = etree.Element('NetworkDefinition') # type: _Element + root = lxml.etree.Element('NetworkDefinition') # type: _Element root.set("xmlns", "http://kayak.2codeornot2code.org/1.0") ns_xsi = "{http://www.w3.org/2001/XMLSchema-instance}" root.set(ns_xsi + "schemaLocation", "Definition.xsd") - # root.append(etree.Element('Document')) + # root.append(lxml.etree.Element('Document')) # another child with text - child = etree.Element('Document') + child = lxml.etree.Element('Document') child.set("name", "Some Document Name") child.text = 'some text' root.append(child) @@ -152,7 +151,7 @@ def dump(dbs, f, **_options): element_id = 1 node_list = {} # type: typing.MutableMapping[str, int] for ecu in cluster.ecus: - node = etree.Element('Node', name=ecu.name, id="%d" % element_id) + node = lxml.etree.Element('Node', name=ecu.name, id="%d" % element_id) root.append(node) node_list[ecu.name] = element_id element_id += 1 @@ -160,9 +159,9 @@ def dump(dbs, f, **_options): db = cluster[name] # Bus if 'Baudrate' in db.attributes: - bus = etree.Element('Bus', baudrate=db.attributes['Baudrate']) + bus = lxml.etree.Element('Bus', baudrate=db.attributes['Baudrate']) else: - bus = etree.Element('Bus') + bus = lxml.etree.Element('Bus') if not name: (path, ext) = os.path.splitext(f.name) @@ -172,7 +171,7 @@ def dump(dbs, f, **_options): bus.set("name", name) for frame in db.frames: - message = etree.Element( + message = lxml.etree.Element( 'Message', id="0x%03X" % frame.arbitration_id.id, name=frame.name, @@ -186,16 +185,16 @@ def dump(dbs, f, **_options): message.set("triggered", "true") message.set("interval", "%d" % int(cycle_time)) - comment_elem = etree.Element('Notes') + comment_elem = lxml.etree.Element('Notes') if frame.comment is not None: comment_elem.text = frame.comment message.append(comment_elem) - producer = etree.Element('Producer') + producer = lxml.etree.Element('Producer') for transmitter in frame.transmitters: if transmitter in node_list and len(transmitter) > 1: - node_ref = etree.Element( + node_ref = lxml.etree.Element( 'NodeRef', id=str(node_list[transmitter])) producer.append(node_ref) @@ -208,19 +207,19 @@ def dump(dbs, f, **_options): multiplexor_elem = None for signal in frame.signals: if signal.multiplex is not None and signal.multiplex == 'Multiplexor': - multiplexor_elem = etree.Element( + multiplexor_elem = lxml.etree.Element( 'Multiplex', name=signal.name, offset=str(signal.get_startbit()), length=str(int(signal.size))) - value = etree.Element('Value') + value = lxml.etree.Element('Value') if float(signal.min) != 0: value.set('min', "%g" % signal.min) # type: ignore if float(signal.max) != 1: value.set('max', "%g" % signal.max) - label_set = etree.Element('LabelSet') + label_set = lxml.etree.Element('LabelSet') for valueVal, valName in sorted(signal.values.items(), key=lambda x: int(x[0])): - label = etree.Element( + label = lxml.etree.Element( 'Label', name=valName.replace('"', ''), value=str(valueVal)) @@ -230,7 +229,7 @@ def dump(dbs, f, **_options): # ticker all potential muxgroups for i in range(0, 1 << int(multiplexor_elem.get('length'))): empty = 0 - muxgroup = etree.Element('MuxGroup', count=str(i)) + muxgroup = lxml.etree.Element('MuxGroup', count=str(i)) for signal in frame.signals: if signal.multiplex is not None and signal.multiplex == i: sig = create_signal(signal, node_list, signal_type_enums) @@ -251,7 +250,7 @@ def dump(dbs, f, **_options): bus.append(message) root.append(bus) - f.write(etree.tostring(root, pretty_print=True)) + f.write(lxml.etree.tostring(root, pretty_print=True)) def parse_signal(signal, mux, namespace, nodelist, float_factory): @@ -347,7 +346,7 @@ def load(f, **options): # type: (typing.IO, **typing.Any) -> typing.Dict[str, canmatrix.CanMatrix] float_factory = options.get("float_factory", default_float_factory) # type: typing.Callable dbs = {} # type: typing.Dict[str, canmatrix.CanMatrix] - tree = etree.parse(f) + tree = lxml.etree.parse(f) root = tree.getroot() namespace = "{" + tree.xpath('namespace-uri(.)') + "}" diff --git a/src/canmatrix/formats/scapy.py b/src/canmatrix/formats/scapy.py index a1c3d689..a13ebf96 100644 --- a/src/canmatrix/formats/scapy.py +++ b/src/canmatrix/formats/scapy.py @@ -22,6 +22,8 @@ # 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 diff --git a/src/canmatrix/formats/sym.py b/src/canmatrix/formats/sym.py index 37c8d8ba..9e058dd5 100644 --- a/src/canmatrix/formats/sym.py +++ b/src/canmatrix/formats/sym.py @@ -23,8 +23,7 @@ # 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 -from __future__ import division +from __future__ import absolute_import, division, print_function import collections import decimal diff --git a/src/canmatrix/formats/xls.py b/src/canmatrix/formats/xls.py index 9b23b6de..b92b03b9 100644 --- a/src/canmatrix/formats/xls.py +++ b/src/canmatrix/formats/xls.py @@ -23,9 +23,7 @@ # this script exports xls-files from a canmatrix-object # xls-files are the can-matrix-definitions displayed in Excel -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function +from __future__ import absolute_import, division, print_function import decimal import logging diff --git a/src/canmatrix/formats/xls_common.py b/src/canmatrix/formats/xls_common.py index 1430151a..9d804870 100644 --- a/src/canmatrix/formats/xls_common.py +++ b/src/canmatrix/formats/xls_common.py @@ -19,6 +19,8 @@ # 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 import canmatrix diff --git a/src/canmatrix/formats/xlsx.py b/src/canmatrix/formats/xlsx.py index db47eea2..5b806bec 100644 --- a/src/canmatrix/formats/xlsx.py +++ b/src/canmatrix/formats/xlsx.py @@ -23,9 +23,7 @@ # this script exports xls-files from a canmatrix-object # xls-files are the can-matrix-definitions displayed in Excel - -from __future__ import absolute_import -from __future__ import division +from __future__ import absolute_import, division, print_function import logging import typing diff --git a/src/canmatrix/formats/yaml.py b/src/canmatrix/formats/yaml.py index 261d81a7..c62b005b 100644 --- a/src/canmatrix/formats/yaml.py +++ b/src/canmatrix/formats/yaml.py @@ -23,8 +23,7 @@ # yaml-files are just object-dumps human readable. # This export is complete, no information lost - -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function import copy import typing diff --git a/src/canmatrix/j1939_decoder.py b/src/canmatrix/j1939_decoder.py index 9976a016..ef516479 100644 --- a/src/canmatrix/j1939_decoder.py +++ b/src/canmatrix/j1939_decoder.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function import canmatrix.formats import pathlib2 diff --git a/src/canmatrix/join.py b/src/canmatrix/join.py index 138bb0f8..ac5bf7f9 100644 --- a/src/canmatrix/join.py +++ b/src/canmatrix/join.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function + import typing import canmatrix diff --git a/src/canmatrix/log.py b/src/canmatrix/log.py index 5378fdaf..bbecd5d7 100644 --- a/src/canmatrix/log.py +++ b/src/canmatrix/log.py @@ -22,7 +22,7 @@ # Configurable logging # Author: Martin Hoffmann (m8ddin@gmail.com) -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function import logging diff --git a/src/canmatrix/utils.py b/src/canmatrix/utils.py index 13f699e9..d55c2a61 100644 --- a/src/canmatrix/utils.py +++ b/src/canmatrix/utils.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function + import csv import shlex import sys