# Path: sim/sim_router.py
# ROUTER_MODE_DISABLED = 0
# ROUTER_MODE_INTERACTIVE = 1
# ROUTER_MODE_TELNET = 2
# ROUTER_MODE_DBUS = 3
# CMD_SET_ATR  = 0
# CMD_SET_SKIP = 1
# CMD_HALT     = 2
# CMD_POLL     = 3
# CMD_R_APDU   = 4
# EVT_UNKNOWN  = 0
# EVT_RESET    = 2
# EVT_C_APDU   = 4
# SIMTRACE_OFFLINE = 0
# SIMTRACE_ONLINE = 1
# MAIN_INTERFACE = 0
# CTRL_INTERFACE = 1
# INJECT_READY = 0
# INJECT_NO_FORWARD = 1
# INJECT_WITH_FORWARD = 2
# INJECT_RESET = 3
# TRY_ANOTHER_CARD_ON_AUTH_FAILURE = True
# LOG_NONE_APDU_IN_FILE = True
#         LIBUSB_PATH = "/usr/lib/libusb-1.0.so"
# class SimRouter(object):
# class MainLoopThread(threading.Thread):
# class ResetThread(threading.Thread):
#     def __init__(self,
#                  cards,
#                  atr=None,
#                  type=types.TYPE_USIM,
#                  mode=SIMTRACE_ONLINE):
#     def addControlCard(self, cards):
#     def usbCtrlOut(self, req, buf):
#     def usbCtrlIn(self, req):
#     def receiveData(self, cmd):
#     def sendData(self, msg):
#     def resetCards(self, soft=True):
#     def receiveCommandApdu(self):
#     def sendResponseApdu(self, msg):
#     def command(self, tag, payload=[]):  # dummy byte
#     def aidCommon(self, card):
#     def getSoftCardDict(self):
#     def getFileHandler(self, file):
#     def getInsHandler(self, ins, apdu):
#     def addLeftHandlers(self, cards):
#     def getHandlers(self, apdu, inject=None):
#     def handleApdu(self, cardData, apdu):
#     def updateHandler(self, cardData, apdu, rapdu):
#     def tick(self):
#     def mainloop(self):
#     def getNbrOfCards(self):
#     def getSimId(self, card):
#     def getCardDictFromId(self, simId):
#     def isCardCtrl(self, card):
#     def getMainCard(self, simId):
#     def getCtrlCard(self, simId):
#     def getRelatedMainCard(self, cardCtrl):
#     def getRelatedCtrlCard(self, cardMain):
#     def swapCards(self, simId1, simId2):
#     def copyFiles(self, cardMainFrom, cardMainTo, files):
#     def getATR(self):
#     def waitInjectReady(self, timeout=15):
#     def waitRapduInject(self, timeout=30):
#     def injectApdu(self, apdu, card, mode=INJECT_NO_FORWARD):
#     def setPowerSkip(self, skip):
#     def powerHalt(self):
#     def run(self, mode=ROUTER_MODE_INTERACTIVE):
#     def getInteractiveFromMode(self, mode):
#     def startPlacServer(self, mode):
#     def setShellPrompt(self, prompt):
#     def setupLogger(self):
#     def fileName(self, apdu):
#     def pretty_apdu(self, apdu):
#     def usb_find(self, idVendor, idProduct):
# def setLoggerExtHandler(handler):
#     def __init__(self, simRouter):
#     def run(self):
#     def stop(self):
#     def __init__(self, simRouter):
#     def run(self):
#     def softReset(self):
#     def stop(self):


import os
import sys
import unittest
import logging
import traceback
import html_test_runner
        import java.lang.System
from optparse import OptionParser
from sim import sim_router
startDir = dir

def setupLogger(loggingLevel):
    if not os.path.exists(resultDir):
        os.makedirs(resultDir)
    resultFile = os.path.join(resultDir, "result.txt")
    # create logger with 'root'
    logger = logging.getLogger()
    logger.handlers = []
    logger.setLevel(loggingLevel)
    # create file handler which logs even debug messages
    fileHandler = logging.FileHandler(resultFile)
    fileHandler.setLevel(loggingLevel)
    # create console handler with a higher log level
    consoleHandler = logging.StreamHandler()
    consoleHandler.setLevel(loggingLevel)
    # create ext handler with a higher log level
    # use this handler to redirect streaming in html_test_runner
    extHandler = logging.StreamHandler(stream=html_test_runner.stdout_redirector)
    extHandler.setLevel(loggingLevel)
    # create formatter and add it to the handlers
    formatterConsole = logging.Formatter(fmt='%(message)s')
    formatter = logging.Formatter(fmt='%(asctime)s %(message)s', datefmt='%H:%M:%S')
    consoleHandler.setFormatter(formatterConsole)
    fileHandler.setFormatter(formatter)
    extHandler.setFormatter(formatter)
    # add the handlers to the logger
    logger.addHandler(fileHandler)
    logger.addHandler(consoleHandler)
    logger.addHandler(extHandler)

# Path: sim/sim_router.py
# ROUTER_MODE_DISABLED = 0
# ROUTER_MODE_INTERACTIVE = 1
# ROUTER_MODE_TELNET = 2
# ROUTER_MODE_DBUS = 3
# CMD_SET_ATR  = 0
# CMD_SET_SKIP = 1
# CMD_HALT     = 2
# CMD_POLL     = 3
# CMD_R_APDU   = 4
# EVT_UNKNOWN  = 0
# EVT_RESET    = 2
# EVT_C_APDU   = 4
# SIMTRACE_OFFLINE = 0
# SIMTRACE_ONLINE = 1
# MAIN_INTERFACE = 0
# CTRL_INTERFACE = 1
# INJECT_READY = 0
# INJECT_NO_FORWARD = 1
# INJECT_WITH_FORWARD = 2
# INJECT_RESET = 3
# TRY_ANOTHER_CARD_ON_AUTH_FAILURE = True
# LOG_NONE_APDU_IN_FILE = True
#         LIBUSB_PATH = "/usr/lib/libusb-1.0.so"
# class SimRouter(object):
# class MainLoopThread(threading.Thread):
# class ResetThread(threading.Thread):
#     def __init__(self,
#                  cards,
#                  atr=None,
#                  type=types.TYPE_USIM,
#                  mode=SIMTRACE_ONLINE):
#     def addControlCard(self, cards):
#     def usbCtrlOut(self, req, buf):
#     def usbCtrlIn(self, req):
#     def receiveData(self, cmd):
#     def sendData(self, msg):
#     def resetCards(self, soft=True):
#     def receiveCommandApdu(self):
#     def sendResponseApdu(self, msg):
#     def command(self, tag, payload=[]):  # dummy byte
#     def aidCommon(self, card):
#     def getSoftCardDict(self):
#     def getFileHandler(self, file):
#     def getInsHandler(self, ins, apdu):
#     def addLeftHandlers(self, cards):
#     def getHandlers(self, apdu, inject=None):
#     def handleApdu(self, cardData, apdu):
#     def updateHandler(self, cardData, apdu, rapdu):
#     def tick(self):
#     def mainloop(self):
#     def getNbrOfCards(self):
#     def getSimId(self, card):
#     def getCardDictFromId(self, simId):
#     def isCardCtrl(self, card):
#     def getMainCard(self, simId):
#     def getCtrlCard(self, simId):
#     def getRelatedMainCard(self, cardCtrl):
#     def getRelatedCtrlCard(self, cardMain):
#     def swapCards(self, simId1, simId2):
#     def copyFiles(self, cardMainFrom, cardMainTo, files):
#     def getATR(self):
#     def waitInjectReady(self, timeout=15):
#     def waitRapduInject(self, timeout=30):
#     def injectApdu(self, apdu, card, mode=INJECT_NO_FORWARD):
#     def setPowerSkip(self, skip):
#     def powerHalt(self):
#     def run(self, mode=ROUTER_MODE_INTERACTIVE):
#     def getInteractiveFromMode(self, mode):
#     def startPlacServer(self, mode):
#     def setShellPrompt(self, prompt):
#     def setupLogger(self):
#     def fileName(self, apdu):
#     def pretty_apdu(self, apdu):
#     def usb_find(self, idVendor, idProduct):
# def setLoggerExtHandler(handler):
#     def __init__(self, simRouter):
#     def run(self):
#     def stop(self):
#     def __init__(self, simRouter):
#     def run(self):
#     def softReset(self):
#     def stop(self):


# Path: tests/runner.py
import os
import sys
import unittest
import logging
import traceback
import html_test_runner
        import java.lang.System
from optparse import OptionParser
from sim import sim_router

startDir = dir

def setupLogger(loggingLevel):
    if not os.path.exists(resultDir):
        os.makedirs(resultDir)
    resultFile = os.path.join(resultDir, "result.txt")
    # create logger with 'root'
    logger = logging.getLogger()
    logger.handlers = []
    logger.setLevel(loggingLevel)
    # create file handler which logs even debug messages
    fileHandler = logging.FileHandler(resultFile)
    fileHandler.setLevel(loggingLevel)
    # create console handler with a higher log level
    consoleHandler = logging.StreamHandler()
    consoleHandler.setLevel(loggingLevel)
    # create ext handler with a higher log level
    # use this handler to redirect streaming in html_test_runner
    extHandler = logging.StreamHandler(stream=html_test_runner.stdout_redirector)
    extHandler.setLevel(loggingLevel)
    # create formatter and add it to the handlers
    formatterConsole = logging.Formatter(fmt='%(message)s')
    formatter = logging.Formatter(fmt='%(asctime)s %(message)s', datefmt='%H:%M:%S')
    consoleHandler.setFormatter(formatterConsole)
    fileHandler.setFormatter(formatter)
    extHandler.setFormatter(formatter)
    # add the handlers to the logger
    logger.addHandler(fileHandler)
    logger.addHandler(consoleHandler)
    logger.addHandler(extHandler)

    sim_router.setLoggerExtHandler(extHandler)