コード例 #1
0
    def addObserver(self, observer):
        """Add an observer."""
        Observable.addObserver(self, observer)

        # If self.startOnDemand is True, the reader monitoring
        # thread only runs when there are observers.
        if self.startOnDemand:
            if 0 < self.countObservers():
                if not self.rmthread:
                    self.rmthread = ReaderMonitoringThread(
                        self, self.readerProc, self.period)

                    # start reader monitoring thread in another thread to
                    # avoid a deadlock; addObserver and notifyObservers called
                    # in the ReaderMonitoringThread run() method are
                    # synchronized
                    try:
                        # Python 3.x
                        import _thread
                        _thread.start_new_thread(self.rmthread.start, ())
                    except:
                        # Python 2.x
                        import thread
                        thread.start_new_thread(self.rmthread.start, ())
        else:
            observer.update(self, (self.rmthread.readers, []))
コード例 #2
0
    def addObserver(self, observer):
        """Add an observer."""
        Observable.addObserver(self, observer)

        # If self.startOnDemand is True, the reader monitoring
        # thread only runs when there are observers.
        if self.startOnDemand:
            if 0 < self.countObservers():
                if not self.rmthread:
                    self.rmthread = ReaderMonitoringThread(self,
                        self.readerProc, self.period)

                    # start reader monitoring thread in another thread to
                    # avoid a deadlock; addObserver and notifyObservers called
                    # in the ReaderMonitoringThread run() method are
                    # synchronized
                    try:
                        # Python 3.x
                        import _thread
                        _thread.start_new_thread(self.rmthread.start, ())
                    except:
                        # Python 2.x
                        import thread
                        thread.start_new_thread(self.rmthread.start, ())
        else:
            observer.update(self, (self.rmthread.readers, []))
コード例 #3
0
 def deleteObserver(self, observer):
     """Remove an observer."""
     Observable.deleteObserver(self, observer)
     # If self.startOnDemand is True, the reader monitoring
     # thread is stopped when there are no more observers.
     if self.startOnDemand:
         if 0 == self.countObservers():
             self.rmthread.stop()
             del self.rmthread
             self.rmthread = None
コード例 #4
0
 def deleteObserver(self, observer):
     """Remove an observer."""
     Observable.deleteObserver(self, observer)
     # If self.startOnDemand is True, the reader monitoring
     # thread is stopped when there are no more observers.
     if self.startOnDemand:
         if 0 == self.countObservers():
             self.rmthread.stop()
             del self.rmthread
             self.rmthread = None
コード例 #5
0
ファイル: CardConnection.py プロジェクト: jgiannuzzi/pyscard
    def connect(self, protocol=None, mode=None, disposition=None):
        """Connect to card.
        protocol: a bit mask of the protocols to use, from
        CardConnection.T0_protocol, CardConnection.T1_protocol,
        CardConnection.RAW_protocol, CardConnection.T15_protocol

        mode: passed as-is to the PC/SC layer
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self, CardConnectionEvent('connect'))
コード例 #6
0
ファイル: CardConnection.py プロジェクト: 12019/pyscard
    def connect(self, protocol=None, mode=None, disposition=None):
        """Connect to card.
        protocol: a bit mask of the protocols to use, from
        CardConnection.T0_protocol, CardConnection.T1_protocol,
        CardConnection.RAW_protocol, CardConnection.T15_protocol

        mode: passed as-is to the PC/SC layer
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self, CardConnectionEvent('connect'))
コード例 #7
0
    def __init__(self, reader):
        """Construct a new card connection.

        readerName: name of the reader in which the smartcard to connect
        to is located.
        """
        Observable.__init__(self)
        self.reader = reader
        self.errorcheckingchain = None
        self.defaultprotocol = CardConnection.T0_protocol | CardConnection.T1_protocol
コード例 #8
0
        def deleteObserver(self, observer):
            """Remove an observer.

            We delete the CardMonitoringThread reference when there
            are no more observers.
            """
            Observable.deleteObserver(self, observer)
            if _START_ON_DEMAND_:
                if self.countObservers() == 0:
                    if self.rmthread != None:
                        self.rmthread = None
コード例 #9
0
        def deleteObserver(self, observer):
            """Remove an observer.

            We delete the CardMonitoringThread reference when there
            are no more observers.
            """
            Observable.deleteObserver(self, observer)
            if _START_ON_DEMAND_:
                if self.countObservers() == 0:
                    if self.rmthread != None:
                        self.rmthread = None
コード例 #10
0
 def __init__(self, startOnDemand=True, readerProc=smartcard.System.readers, period=1):
     self.__dict__ = self.__shared_state
     Observable.__init__(self)
     self.startOnDemand = startOnDemand
     self.readerProc = readerProc
     self.period = period
     if self.startOnDemand:
         self.rmthread = None
     else:
         self.rmthread = ReaderMonitoringThread(self, self.readerProc, self.period)
         self.rmthread.start()
コード例 #11
0
ファイル: CardMonitoring.py プロジェクト: c0deh4xor/pyscard
        def addObserver(self, observer):
            """Add an observer.

            We only start the card monitoring thread when
            there are observers.
            """
            Observable.addObserver(self, observer)
            if _START_ON_DEMAND_:
                if self.countObservers() > 0 and self.rmthread is None:
                    self.rmthread = CardMonitoringThread(self)
            else:
                observer.update(self, (self.rmthread.cards, []))
コード例 #12
0
        def addObserver(self, observer):
            """Add an observer.

            We only start the card monitoring thread when
            there are observers.
            """
            Observable.addObserver(self, observer)
            if _START_ON_DEMAND_:
                if self.countObservers() > 0 and self.rmthread == None:
                    self.rmthread = CardMonitoringThread(self)
            else:
                observer.update(self, (self.rmthread.cards, []))
コード例 #13
0
    def getAttrib(self, attribId):
        """return the requested attribute

        @param attribId: attribute id like SCARD_ATTR_VENDOR_NAME
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self,
                                   CardConnectionEvent('attrib', [attribId]))
        data = self.doGetAttrib(attribId)
        if None != self.errorcheckingchain:
            self.errorcheckingchain[0](data)
        return data
コード例 #14
0
ファイル: CardConnection.py プロジェクト: benmehlman/pyscard
    def transmit(self, bytes, protocol=None):
        """Transmit an apdu. Internally calls doTransmit() class method
        and notify observers upon command/response APDU events.
        Subclasses must override the doTransmit() class method.

        bytes:      list of bytes to transmit

        protocol:   the transmission protocol, from
                    CardConnection.T0_protocol,
                    CardConnection.T1_protocol, or
                    CardConnection.RAW_protocol
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self,
                                   CardConnectionEvent(
                                       'command',
                                       [bytes, protocol]))
        data, sw1, sw2 = self.doTransmit(bytes, protocol)
        Observable.setChanged(self)
        Observable.notifyObservers(self,
                                   CardConnectionEvent(
                                       'response',
                                       [data, sw1, sw2]))
        if None != self.errorcheckingchain:
            self.errorcheckingchain[0](data, sw1, sw2)
        return data, sw1, sw2
コード例 #15
0
ファイル: CardConnection.py プロジェクト: ntzwq/pyscard
    def reconnect(self, protocol=None, mode=None, disposition=None):
        """Reconnect to card.
        @param protocol: a bit mask of the protocols to use, from
        L{CardConnection.T0_protocol}, L{CardConnection.T1_protocol},
        L{CardConnection.RAW_protocol}, L{CardConnection.T15_protocol}

        @param mode: SCARD_SHARE_SHARED (default), SCARD_SHARE_EXCLUSIVE or
        SCARD_SHARE_DIRECT

        @param disposition: SCARD_LEAVE_CARD, SCARD_RESET_CARD (default),
        SCARD_UNPOWER_CARD or SCARD_EJECT_CARD
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self, CardConnectionEvent('reconnect'))
コード例 #16
0
ファイル: CardConnection.py プロジェクト: ntzwq/pyscard
    def transmit(self, bytes, protocol=None):
        """Transmit an apdu. Internally calls doTransmit() class method
        and notify observers upon command/response APDU events.
        Subclasses must override the doTransmit() class method.

        @param bytes:      list of bytes to transmit

        @param protocol:   the transmission protocol, from
                    CardConnection.T0_protocol,
                    CardConnection.T1_protocol, or
                    CardConnection.RAW_protocol
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self,
                                   CardConnectionEvent(
                                       'command',
                                       [bytes, protocol]))
        data, sw1, sw2 = self.doTransmit(bytes, protocol)
        Observable.setChanged(self)
        Observable.notifyObservers(self,
                                   CardConnectionEvent(
                                       'response',
                                       [data, sw1, sw2]))
        if self.errorcheckingchain is not None:
            self.errorcheckingchain[0](data, sw1, sw2)
        return data, sw1, sw2
コード例 #17
0
ファイル: CardConnection.py プロジェクト: benmehlman/pyscard
    def getAttrib(self, attribId):
        """return the requested attribute

        attribId: attribute id like SCARD_ATTR_VENDOR_NAME
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self,
                                   CardConnectionEvent(
                                       'attrib',
                                       [attribId]))
        data = self.doGetAttrib(attribId)
        if None != self.errorcheckingchain:
            self.errorcheckingchain[0](data)
        return data
コード例 #18
0
ファイル: CardConnection.py プロジェクト: benmehlman/pyscard
    def connect(self, protocol=None, mode=None, disposition=None):
        """Connect to card.
        protocol: a bit mask of the protocols to use, from
        CardConnection.T0_protocol, CardConnection.T1_protocol,
        CardConnection.RAW_protocol, CardConnection.T15_protocol

        mode: SCARD_SHARE_SHARED (default), SCARD_SHARE_EXCLUSIVE or
        SCARD_SHARE_DIRECT

        disposition: SCARD_LEAVE_CARD (default), SCARD_RESET_CARD,
        SCARD_UNPOWER_CARD or SCARD_EJECT_CARD
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self, CardConnectionEvent('connect'))
コード例 #19
0
 def __init__(self,
              startOnDemand=True,
              readerProc=smartcard.System.readers,
              period=1):
     self.__dict__ = self.__shared_state
     Observable.__init__(self)
     self.startOnDemand = startOnDemand
     self.readerProc = readerProc
     self.period = period
     if self.startOnDemand:
         self.rmthread = None
     else:
         self.rmthread = ReaderMonitoringThread(self, self.readerProc,
                                                self.period)
         self.rmthread.start()
コード例 #20
0
    def control(self, controlCode, bytes=[]):
        """Send a control command and buffer.  Internally calls doControl()
        class method and notify observers upon command/response events.
        Subclasses must override the doControl() class method.

        controlCode: command code

        bytes:       list of bytes to transmit
        """
        Observable.setChanged(self)
        Observable.notifyObservers(self, CardConnectionEvent('command', [controlCode, bytes]))
        data = self.doControl(controlCode, bytes)
        Observable.setChanged(self)
        Observable.notifyObservers(self, CardConnectionEvent('response', data))
        if None != self.errorcheckingchain:
            self.errorcheckingchain[0](data)
        return data
コード例 #21
0
ファイル: CardConnection.py プロジェクト: ntzwq/pyscard
 def deleteObserver(self, observer):
     """Remove a CardConnection observer."""
     Observable.deleteObserver(self, observer)
コード例 #22
0
ファイル: CardConnection.py プロジェクト: ntzwq/pyscard
 def addObserver(self, observer):
     """Add a CardConnection observer."""
     Observable.addObserver(self, observer)
コード例 #23
0
ファイル: CardConnection.py プロジェクト: ntzwq/pyscard
 def disconnect(self):
     """Disconnect from card."""
     Observable.setChanged(self)
     Observable.notifyObservers(self, CardConnectionEvent('disconnect'))
コード例 #24
0
 def __init__(self):
     Observable.__init__(self)
     if _START_ON_DEMAND_:
         self.rmthread = None
     else:
         self.rmthread = CardMonitoringThread(self)
コード例 #25
0
ファイル: CardMonitoring.py プロジェクト: c0deh4xor/pyscard
 def __init__(self):
     Observable.__init__(self)
     if _START_ON_DEMAND_:
         self.rmthread = None
     else:
         self.rmthread = CardMonitoringThread(self)
コード例 #26
0
ファイル: CardConnection.py プロジェクト: benmehlman/pyscard
 def disconnect(self):
     """Disconnect from card."""
     Observable.setChanged(self)
     Observable.notifyObservers(self, CardConnectionEvent('disconnect'))
コード例 #27
0
ファイル: CardConnection.py プロジェクト: benmehlman/pyscard
 def deleteObserver(self, observer):
     """Remove a CardConnection observer."""
     Observable.deleteObserver(self, observer)
コード例 #28
0
ファイル: CardConnection.py プロジェクト: benmehlman/pyscard
 def addObserver(self, observer):
     """Add a CardConnection observer."""
     Observable.addObserver(self, observer)