# Path: FabLabKasse/shopping/backend/abstract.py
# def float_to_decimal(number, digits):
#     """
#     convert float to decimal with rounding and strict error tolerances
# 
#     If the given number cannot be represented as decimal with an error
#     within 1/1000 of the last digit, :exc:`ValueError` is raised.
# 
#     :param number: a float that is nearly equal to a decimal number
#     :type number: float | Decimal
#     :param digits: number of decimal places of the resulting value (max. 9)
#     :type digits: int
# 
#     :raise: ValueError
# 
#     >>> float_to_decimal(1.424, 3)
#     Decimal('1.424')
#     >>> float_to_decimal(0.7, 1)
#     Decimal('0.7')
#     """
# 
#     # conversion is guaranteed to be accurate at 1e12 for 0 digits
#     # larger values are maybe not correctly represented in a float, so we are careful here
#     assert isinstance(digits, int)
#     assert 0 <= digits < 10, "invalid number of digits"
#     result = Decimal(int(round(number * (10 ** digits)))) / (10 ** digits)
#     if not abs(number) < 10 ** (10 + digits):
#         raise ValueError("cannot precisely convert such a large float to Decimal")
#     if not abs(float(result) - float(number)) < (10 ** -(digits + 3)):
#         raise ValueError("attempted inaccurate conversion from {0} to {1}".format(repr(number), repr(result)))
#     return result
# 
# Path: FabLabKasse/scriptHelper.py
# def setupLogging(logfile):
# def setupSigInt():
#     def sigint(num, frame):
# def setupGraphicalExceptHook():
#     def myNewExceptionHook(exctype, value, tb):
# def getConfig(path="./"):
# def getDB():
#     def __init__(self, name):
# class FileLock(object):


import codecs
import logging
import sqlite3
from PyQt4 import QtCore, Qt
from decimal import Decimal
from datetime import datetime
from faucardStates import Status, Info
from MagPosLog import MagPosLog
from ..shopping.backend.abstract import float_to_decimal
    from magpos import magpos, codes
    from dinterface import magpos, codes
from FabLabKasse import scriptHelper
from ConfigParser import ConfigParser
        except self.CheckLastTransactionFailed as e:
            self.response_ready.emit([Info.check_transaction_failed])
            self.info = Info.check_transaction_failed
            self.quit()
        except NotImplementedError as e:
            logging.error("FAUcardThread: MagPos not implemented, maybe dummy loaded.")
            self.terminate()
        except Exception:
            self.terminate()
            raise
        else:
            # close the connection to MagnaBox
            if self.pos is not None:
                self.pos.close()

        if self.info is not Info.OK:
            self.process_aborted.emit()
        logging.info("Fau-Terminal: thread finished")

    @staticmethod
    def check_last_transaction(cur, con):
        """
        Prüfe auf Fehler bei Zahlung mit der FAU-Karte und speichere das Ergebnis in MagPosLog
        :return: True if the check could be performed, False otherwise (does not take result of check into account)
        :rtype: bool
        :param cur: database cursor
        :type cur: sqlite3.Cursor
        :param con: database connection
        :type con: sqlite3.Connection
        """

# Path: FabLabKasse/shopping/backend/abstract.py
# def float_to_decimal(number, digits):
#     """
#     convert float to decimal with rounding and strict error tolerances
# 
#     If the given number cannot be represented as decimal with an error
#     within 1/1000 of the last digit, :exc:`ValueError` is raised.
# 
#     :param number: a float that is nearly equal to a decimal number
#     :type number: float | Decimal
#     :param digits: number of decimal places of the resulting value (max. 9)
#     :type digits: int
# 
#     :raise: ValueError
# 
#     >>> float_to_decimal(1.424, 3)
#     Decimal('1.424')
#     >>> float_to_decimal(0.7, 1)
#     Decimal('0.7')
#     """
# 
#     # conversion is guaranteed to be accurate at 1e12 for 0 digits
#     # larger values are maybe not correctly represented in a float, so we are careful here
#     assert isinstance(digits, int)
#     assert 0 <= digits < 10, "invalid number of digits"
#     result = Decimal(int(round(number * (10 ** digits)))) / (10 ** digits)
#     if not abs(number) < 10 ** (10 + digits):
#         raise ValueError("cannot precisely convert such a large float to Decimal")
#     if not abs(float(result) - float(number)) < (10 ** -(digits + 3)):
#         raise ValueError("attempted inaccurate conversion from {0} to {1}".format(repr(number), repr(result)))
#     return result
# 
# Path: FabLabKasse/scriptHelper.py
# def setupLogging(logfile):
# def setupSigInt():
#     def sigint(num, frame):
# def setupGraphicalExceptHook():
#     def myNewExceptionHook(exctype, value, tb):
# def getConfig(path="./"):
# def getDB():
#     def __init__(self, name):
# class FileLock(object):


# Path: FabLabKasse/faucardPayment/FAUcardPaymentThread.py
import codecs
import logging
import sqlite3
from PyQt4 import QtCore, Qt
from decimal import Decimal
from datetime import datetime
from faucardStates import Status, Info
from MagPosLog import MagPosLog
from ..shopping.backend.abstract import float_to_decimal
    from magpos import magpos, codes
    from dinterface import magpos, codes
from FabLabKasse import scriptHelper
from ConfigParser import ConfigParser

        except self.CheckLastTransactionFailed as e:
            self.response_ready.emit([Info.check_transaction_failed])
            self.info = Info.check_transaction_failed
            self.quit()
        except NotImplementedError as e:
            logging.error("FAUcardThread: MagPos not implemented, maybe dummy loaded.")
            self.terminate()
        except Exception:
            self.terminate()
            raise
        else:
            # close the connection to MagnaBox
            if self.pos is not None:
                self.pos.close()

        if self.info is not Info.OK:
            self.process_aborted.emit()
        logging.info("Fau-Terminal: thread finished")

    @staticmethod
    def check_last_transaction(cur, con):
        """
        Prüfe auf Fehler bei Zahlung mit der FAU-Karte und speichere das Ergebnis in MagPosLog
        :return: True if the check could be performed, False otherwise (does not take result of check into account)
        :rtype: bool
        :param cur: database cursor
        :type cur: sqlite3.Cursor
        :param con: database connection
        :type con: sqlite3.Connection
        """

        cfg = scriptHelper.getConfig()