當前位置: 首頁>>代碼示例>>Python>>正文


Python Observer.Observable類代碼示例

本文整理匯總了Python中smartcard.Observer.Observable的典型用法代碼示例。如果您正苦於以下問題:Python Observable類的具體用法?Python Observable怎麽用?Python Observable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Observable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: addObserver

    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, []))
開發者ID:AnnePieter,項目名稱:P4Pkoffiekaart,代碼行數:26,代碼來源:ReaderMonitoring.py

示例2: deleteObserver

 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
開發者ID:AnnePieter,項目名稱:P4Pkoffiekaart,代碼行數:10,代碼來源:ReaderMonitoring.py

示例3: connect

    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'))
開發者ID:12019,項目名稱:pyscard,代碼行數:10,代碼來源:CardConnection.py

示例4: __init__

    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
開發者ID:12019,項目名稱:pyscard,代碼行數:10,代碼來源:CardConnection.py

示例5: deleteObserver

        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
開發者ID:AnnePieter,項目名稱:P4Pkoffiekaart,代碼行數:11,代碼來源:CardMonitoring.py

示例6: __init__

 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()
開發者ID:daniel-hartmann,項目名稱:pyscard,代碼行數:11,代碼來源:ReaderMonitoring.py

示例7: addObserver

        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, []))
開發者ID:c0deh4xor,項目名稱:pyscard,代碼行數:12,代碼來源:CardMonitoring.py

示例8: connect

    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'))
開發者ID:benmehlman,項目名稱:pyscard,代碼行數:14,代碼來源:CardConnection.py

示例9: getAttrib

    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
開發者ID:benmehlman,項目名稱:pyscard,代碼行數:14,代碼來源:CardConnection.py

示例10: transmit

    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
開發者ID:benmehlman,項目名稱:pyscard,代碼行數:26,代碼來源:CardConnection.py

示例11: control

    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
開發者ID:12019,項目名稱:pyscard,代碼行數:17,代碼來源:CardConnection.py

示例12: disconnect

 def disconnect(self):
     """Disconnect from card."""
     Observable.setChanged(self)
     Observable.notifyObservers(self, CardConnectionEvent('disconnect'))
開發者ID:benmehlman,項目名稱:pyscard,代碼行數:4,代碼來源:CardConnection.py

示例13: deleteObserver

 def deleteObserver(self, observer):
     """Remove a CardConnection observer."""
     Observable.deleteObserver(self, observer)
開發者ID:benmehlman,項目名稱:pyscard,代碼行數:3,代碼來源:CardConnection.py

示例14: addObserver

 def addObserver(self, observer):
     """Add a CardConnection observer."""
     Observable.addObserver(self, observer)
開發者ID:benmehlman,項目名稱:pyscard,代碼行數:3,代碼來源:CardConnection.py

示例15: __init__

 def __init__(self):
     Observable.__init__(self)
     if _START_ON_DEMAND_:
         self.rmthread = None
     else:
         self.rmthread = CardMonitoringThread(self)
開發者ID:c0deh4xor,項目名稱:pyscard,代碼行數:6,代碼來源:CardMonitoring.py


注:本文中的smartcard.Observer.Observable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。