# Path: yubioath/core/ccid.py
# class ScardDevice(object):
# 
#     """
#     Pyscard based backend.
#     """
# 
#     def __init__(self, connection):
#         self._conn = connection
# 
#     def send_apdu(self, cl, ins, p1, p2, data):
#         header = [cl, ins, p1, p2, len(data)]
#         # from binascii import b2a_hex
#         # print("SEND:", b2a_hex(''.join(map(int2byte, header)) + data))
#         resp, sw1, sw2 = self._conn.transmit(
#             header + [byte2int(b) for b in data])
#         # print("RECV:", b2a_hex(b''.join(map(int2byte, resp + [sw1, sw2]))))
#         return b''.join(int2byte(i) for i in resp), sw1 << 8 | sw2
# 
#     def close(self):
#         self._conn.disconnect()
# 
#     def __del__(self):
#         self.close()


from ..core.ccid import ScardDevice
from smartcard import System
from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver
from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.Exceptions import SmartcardException
from smartcard.pcsc.PCSCExceptions import EstablishContextException
from PySide import QtCore
import weakref
                    return

    @property
    def status(self):
        return self._status

    def _set_status(self, value):
        if self._status != value:
            self._status = value
            self.status_changed.emit(value)

    @property
    def reader(self):
        return self._reader

    @reader.setter
    def reader(self, value):
        self._reader = value
        self._callback(self, value)

    def open(self):
        dev = self._device()
        if dev is not None:
            return dev

        if self._reader:
            conn = self._reader.createConnection()
            try:
                conn.connect()
                self._set_status(CardStatus.Present)

# Path: yubioath/core/ccid.py
# class ScardDevice(object):
# 
#     """
#     Pyscard based backend.
#     """
# 
#     def __init__(self, connection):
#         self._conn = connection
# 
#     def send_apdu(self, cl, ins, p1, p2, data):
#         header = [cl, ins, p1, p2, len(data)]
#         # from binascii import b2a_hex
#         # print("SEND:", b2a_hex(''.join(map(int2byte, header)) + data))
#         resp, sw1, sw2 = self._conn.transmit(
#             header + [byte2int(b) for b in data])
#         # print("RECV:", b2a_hex(b''.join(map(int2byte, resp + [sw1, sw2]))))
#         return b''.join(int2byte(i) for i in resp), sw1 << 8 | sw2
# 
#     def close(self):
#         self._conn.disconnect()
# 
#     def __del__(self):
#         self.close()


# Path: yubioath/gui/ccid.py
from ..core.ccid import ScardDevice
from smartcard import System
from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver
from smartcard.CardMonitoring import CardMonitor, CardObserver
from smartcard.Exceptions import SmartcardException
from smartcard.pcsc.PCSCExceptions import EstablishContextException
from PySide import QtCore
import weakref

                    return

    @property
    def status(self):
        return self._status

    def _set_status(self, value):
        if self._status != value:
            self._status = value
            self.status_changed.emit(value)

    @property
    def reader(self):
        return self._reader

    @reader.setter
    def reader(self, value):
        self._reader = value
        self._callback(self, value)

    def open(self):
        dev = self._device()
        if dev is not None:
            return dev

        if self._reader:
            conn = self._reader.createConnection()
            try:
                conn.connect()
                self._set_status(CardStatus.Present)

                dev = ScardDevice(conn)