From fe232de1b71874b0d3763be401dc5c5ec0895755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Ates?= Date: Tue, 23 Feb 2016 13:01:37 +0100 Subject: [PATCH] Add package in imports. --- core_standard.py | 2 +- models.py | 32 +++++++++++++++++--------------- reader_configs.py | 8 ++++---- stid_readers/core.py | 4 ++-- utils.py | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/core_standard.py b/core_standard.py index 6804044..c054e46 100644 --- a/core_standard.py +++ b/core_standard.py @@ -27,7 +27,7 @@ ''' -from _exceptions import MalformedDataError +from librfid._exceptions import MalformedDataError def inventory(response): diff --git a/models.py b/models.py index 17de291..d5149a2 100644 --- a/models.py +++ b/models.py @@ -23,20 +23,22 @@ ''' -import utils from datetime import datetime - -import core_standard - from serial import (Serial, EIGHTBITS, PARITY_NONE, STOPBITS_ONE) -from _exceptions import (UnknownReaderTypeException, UnknownReaderException, + + +import librfid.core_standard + + +from librfid.utils import get_length_on_2_bytes, get_crc_16_CCITT +from librfid._exceptions import (UnknownReaderTypeException, UnknownReaderException, BadLengthMessageException, BadCRCException, CommandResponseCodeMismatchException, UnknownReaderException, StandardResponseError, UnknownResponseErrorType, ReaderResponseError) -from commands_standard import COMMANDS as STANDARD_COMMANDS -from errors_standard import ERRORS as STANDARD_ERRORS -from reader_configs import READERS +from librfid.commands_standard import COMMANDS as STANDARD_COMMANDS +from librfid.errors_standard import ERRORS as STANDARD_ERRORS +from librfid.reader_configs import READERS class RFIDReader(): @@ -155,7 +157,7 @@ class Command(): self.data = kwargs.pop('data', '') if self.data: self.process_data() - self.lout = utils.get_length_on_2_bytes(self.raw_data) + self.lout = get_length_on_2_bytes(self.raw_data) self.command = self.rfu + self.type_cmd + self.code_cmd + \ self.reserved + self.lout + self.raw_data @@ -164,17 +166,17 @@ class Command(): def process_data(self): try: - getattr(core_standard, self.command_name.lower())(self) + getattr(librfid.core_standard, self.command_name.lower())(self) except: pass def build_message(self): self.sof = '\x02' - self.length = utils.get_length_on_2_bytes(self.command) + self.length = get_length_on_2_bytes(self.command) self.ctrl_addr = '\x00' # RS232 only self.ctrl_mode = '\x00' # Unsecure mode message = self.length + self.ctrl_addr + self.ctrl_mode + self.command - self.crc = utils.get_crc_16_CCITT(message) + self.crc = get_crc_16_CCITT(message) self.message = self.sof + message + self.crc def get_message(self): @@ -227,7 +229,7 @@ class ReaderCommand(Command): self.data = kwargs.pop('data', '') if self.data: self.process_data() - self.lout = utils.get_length_on_2_bytes(self.raw_data) + self.lout = get_length_on_2_bytes(self.raw_data) self.command = self.rfu + self.type_cmd + self.code_cmd + \ self.reserved + self.lout + self.raw_data @@ -259,7 +261,7 @@ class Response(): self.response = message[5:-2] self.crc = message[-2:] str_to_check = self.message[1:-2] # [Len ... Commande] - crc = utils.get_crc_16_CCITT(str_to_check) + crc = get_crc_16_CCITT(str_to_check) if self.crc != crc: raise BadCRCException('CRC checking failed') self.code = self.response[0:2] @@ -313,7 +315,7 @@ class Response(): if isinstance(self.command, ReaderCommand): module = self.command.reader.core else: - module = core_standard + module = librfid.core_standard getattr(module, core_method_name)(self) except Exception, e: pass diff --git a/reader_configs.py b/reader_configs.py index 22c3329..3ada4c9 100644 --- a/reader_configs.py +++ b/reader_configs.py @@ -22,10 +22,10 @@ ''' -from stid_readers.commands_basic import COMMANDS as BASIC_STID_COMMANDS -from stid_readers.params_basic import PARAMS as BASIC_STID_PARAMS -from stid_readers.errors_basic import ERRORS as BASIC_STID_ERRORS -from stid_readers import core as BASIC_STID_CORE +from librfid.stid_readers.commands_basic import COMMANDS as BASIC_STID_COMMANDS +from librfid.stid_readers.params_basic import PARAMS as BASIC_STID_PARAMS +from librfid.stid_readers.errors_basic import ERRORS as BASIC_STID_ERRORS +from librfid.stid_readers import core as BASIC_STID_CORE READERS = { diff --git a/stid_readers/core.py b/stid_readers/core.py index e2f5ebb..29ce587 100644 --- a/stid_readers/core.py +++ b/stid_readers/core.py @@ -27,8 +27,8 @@ ''' -from _exceptions import MalformedDataError, BadParameterException -from utils import get_integer_on_two_bytes, hex_to_int +from librfid._exceptions import MalformedDataError, BadParameterException +from librfid.utils import get_integer_on_two_bytes, hex_to_int def get_rfsettings(response): diff --git a/utils.py b/utils.py index b420dfd..ae0bd34 100644 --- a/utils.py +++ b/utils.py @@ -25,7 +25,7 @@ import crc16 from binascii import unhexlify -from _exceptions import OverheadException +from librfid._exceptions import OverheadException def get_length_on_2_bytes(string):