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


Python CardMonitor.deleteObserver方法代碼示例

本文整理匯總了Python中smartcard.CardMonitoring.CardMonitor.deleteObserver方法的典型用法代碼示例。如果您正苦於以下問題:Python CardMonitor.deleteObserver方法的具體用法?Python CardMonitor.deleteObserver怎麽用?Python CardMonitor.deleteObserver使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在smartcard.CardMonitoring.CardMonitor的用法示例。


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

示例1: SmartCardMonitor

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class SmartCardMonitor(CardObserver):
    def __init__ (self, dispatcher): 
        self.cards = 0
        self.dispatcher = dispatcher
        self.dispatcher.update_inserted(self.get_status(), initial=True)

    def get_status(self): 
        cards = 0
        for reader in readers():
            try: 
                connection = reader.createConnection()
                connection.connect()
                cards = cards + 1
            except NoCardException: pass
        self.cards = cards
        return (self.cards > 0)


    def monitor (self): 
        self.cardmonitor = CardMonitor()
        self.cardmonitor.addObserver(self)

    def shutdown (self): 
        self.cardmonitor.deleteObserver(self)

    def update (self, observable, (addedcards, removedcards)):
        #update the number of cards currently inserted in the system
        self.cards = self.cards + len(addedcards) - len(removedcards)
        if self.cards > 0: 
            self.dispatcher.update_inserted(True)
        else:
            self.dispatcher.update_inserted(False)
開發者ID:jeffmelville,項目名稱:badger,代碼行數:34,代碼來源:SmartCardMonitor.py

示例2: smartcardBridge

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class smartcardBridge():

    cardmonitor = None
    cardobserver = None

    """
        MainClass for the smartcardBride
    """
    def __init__(self, args):
        # feedbackHandler.setup()

        self.cardmonitor = CardMonitor()
        self.cardobserver = cardReader(args)

        self.addCardObserver(self.cardobserver)

    def shutdown(self):
        print "Shutdown"
        self.removeCardObserver(self.cardobserver)
        # feedbackHandler.shutdown()

    def addCardObserver(self, observer):
        self.cardmonitor.addObserver(observer)

    def removeCardObserver(self, observer):
        self.cardmonitor.deleteObserver(observer)
開發者ID:Uepsilon,項目名稱:smartcard-browser-bridge,代碼行數:28,代碼來源:smartcardBridge.py

示例3: daemon_body

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
def daemon_body():
	# The main loop
	try:
		cardmonitor = CardMonitor()
		cardobserver = printobserver()
		cardmonitor.addObserver(cardobserver)

		while True:
			sleep(1000000) # sleep forever

	except:
		cardmonitor.deleteObserver(cardobserver)
開發者ID:giometti,項目名稱:beaglebone_home_automation_blueprints,代碼行數:14,代碼來源:smart_card2twitter.py

示例4: daemon_body

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
def daemon_body():
        # The main loop
	logging.info("INFO waiting for card... (hit CTRL+C to stop)")

	try:
		cardmonitor = CardMonitor()
		cardobserver = printobserver()
		cardmonitor.addObserver(cardobserver)

		while True:
			sleep(1000000) # sleep forever

	except:
		cardmonitor.deleteObserver(cardobserver)
開發者ID:giometti,項目名稱:beaglebone_home_automation_blueprints,代碼行數:16,代碼來源:smart_card.py

示例5: testthread

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
    class testthread(Thread):

        def __init__(self, obsindex):
            Thread.__init__(self)
            self.readermonitor = CardMonitor()
            self.obsindex = obsindex
            self.observer = None

        def run(self):
            # create and register observer
            self.observer = printobserver(self.obsindex)
            self.readermonitor.addObserver(self.observer)
            sleep(10)
            self.readermonitor.deleteObserver(self.observer)
開發者ID:317070,項目名稱:drapri,代碼行數:16,代碼來源:CardMonitoring.py

示例6: startLoop

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
def startLoop():
    now = datetime.datetime.today()
    directory = "%04u-%02u-%02u_%02uh%02um%02us" % (now.year, now.month, now.day, now.hour, now.minute, now.second)
    os.makedirs(directory)
    cardmonitor = CardMonitor()
    cardobserver = observer(directory)
    cardmonitor.addObserver(cardobserver)
    while True:
        try:
            time.sleep(60)
        except:
            break

    cardmonitor.deleteObserver(cardobserver)
開發者ID:Zengwn,項目名稱:pssi,代碼行數:16,代碼來源:loop.py

示例7: testthread

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class testthread(threading.Thread):

    def __init__(self, obsindex, testcase):
        threading.Thread.__init__(self)
        self.obsindex = obsindex
        self.testcase = testcase
        self.cardmonitor = CardMonitor()
        self.observer = None

    def run(self):
        # create and register observer
        self.observer = printobserver(self.obsindex, self.testcase)
        self.cardmonitor.addObserver(self.observer)
        time.sleep(1)
        self.cardmonitor.deleteObserver(self.observer)
開發者ID:12019,項目名稱:pyscard,代碼行數:17,代碼來源:testcase_CardMonitor.py

示例8: entry_point

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
def entry_point():        
    print u"Smartcard monitor applet by Lauri Võsandi <[email protected]>"
    if not os.path.exists(PCSCD):
        print "Unable to find", PCSCD, "are you sure it is installed"
        
    applet = SmartcardApplet()
    reader_monitor = ReaderMonitor()
    reader_monitor.addObserver(applet.reader_observer)
    card_monitor = CardMonitor()
    card_monitor.addObserver(applet.card_observer)
    try:
        gtk.main()
    except KeyboardInterrupt:
        pass
    card_monitor.deleteObserver(applet.card_observer)
    reader_monitor.deleteObserver(applet.reader_observer)
開發者ID:laurivosandi,項目名稱:esteidtray,代碼行數:18,代碼來源:applet.py

示例9: Webconnector

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class Webconnector():

    cardmonitor = None
    cardobserver = None

    """
        MainClass for the Webconnector
    """
    def __init__(self, args):
        feedbackHandler.setup()

        self.cardmonitor = CardMonitor()
        self.cardobserver = cardWebconnector(args)

        self.addCardObserver(self.cardobserver)

    def shutdown(self):
        print "Shutdown"
        self.removeCardObserver(self.cardobserver)
        feedbackHandler.shutdown()

    def addCardObserver(self, observer):
        self.cardmonitor.addObserver(observer)

    def removeCardObserver(self, observer):
        self.cardmonitor.deleteObserver(observer)

    def checkConnection(self, url):
        try:
            # Try connection
            response = urllib2.urlopen(url, timeout=1)

            # Connection successful, activate Connection-LED
            feedbackHandler.setFeedback(feedbackHandler.CONNECTION, feedbackHandler.ACTIVE)

            return True
        except urllib2.URLError as e:
            # No Connection to Server
            feedbackHandler.setFeedback(feedbackHandler.CONNECTION, feedbackHandler.INACTIVE)
        finally:
            return False
開發者ID:StuffCard,項目名稱:smartcard-webconnector-python,代碼行數:43,代碼來源:webconnector.py

示例10: toHexString

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
            apdu = SELECT + DF_TELECOM
            response, sw1, sw2 = card.connection.transmit(apdu)
            if sw1 == 0x9F:
                apdu = GET_RESPONSE + [sw2]
                response, sw1, sw2 = card.connection.transmit(apdu)

        for card in removedcards:
            print "-Removed: ", toHexString(card.atr)

try:
    print "Insert or remove a SIM card in the system."
    print "This program will exit in 60 seconds"
    print ""
    cardmonitor = CardMonitor()
    selectobserver = selectDFTELECOMObserver()
    cardmonitor.addObserver(selectobserver)

    sleep(60)

    # don't forget to remove observer, or the
    # monitor will poll forever...
    cardmonitor.deleteObserver(selectobserver)

    import sys
    if 'win32' == sys.platform:
        print 'press Enter to continue'
        sys.stdin.read(1)

except:
    print exc_info()[0], ':', exc_info()[1]
開發者ID:12019,項目名稱:pyscard,代碼行數:32,代碼來源:sample_MonitorCardsAndTransmit.py

示例11: PrintObserver

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class PrintObserver(CardObserver):
    """A simple card observer that is notified
    when cards are inserted/removed from the system and
    prints the list of cards
    """

    def update(self, observable, actions):
        (addedcards, removedcards) = actions
        for card in addedcards:
            print("+Inserted: ", toHexString(card.atr))
        for card in removedcards:
            print("-Removed: ", toHexString(card.atr))

if __name__ == '__main__':
    print("Insert or remove a smartcard in the system.")
    print("This program will exit in 10 seconds")
    print("")
    cardmonitor = CardMonitor()
    cardobserver = PrintObserver()
    cardmonitor.addObserver(cardobserver)

    sleep(10)

    # don't forget to remove observer, or the
    # monitor will poll forever...
    cardmonitor.deleteObserver(cardobserver)

    import sys
    if 'win32' == sys.platform:
        print('press Enter to continue')
        sys.stdin.read(1)
開發者ID:fjcamillo,項目名稱:Python-RFID,代碼行數:33,代碼來源:pytry.py

示例12: CardAndReaderTreePanel

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class CardAndReaderTreePanel(wx.Panel):
    """Panel containing the smart card and reader tree controls."""

    class _CardObserver(CardObserver):
        """Inner CardObserver. Gets notified of card insertion
        removal by the CardMonitor."""

        def __init__(self, cardtreectrl):
            self.cardtreectrl = cardtreectrl

        def update(self, observable, handlers):
            """CardObserver callback that is notified
            when cards are added or removed."""
            addedcards, removedcards = handlers
            self.cardtreectrl.OnRemoveCards(removedcards)
            self.cardtreectrl.OnAddCards(addedcards)

    class _ReaderObserver(ReaderObserver):
        """Inner ReaderObserver. Gets notified of reader insertion/removal
        by the ReaderMonitor."""

        def __init__(self, readertreectrl):
            self.readertreectrl = readertreectrl

        def update(self, observable, handlers):
            """ReaderObserver callback that is notified when
            readers are added or removed."""
            addedcards, removedcards = handlers
            self.readertreectrl.OnRemoveReaders(removedreaders)
            self.readertreectrl.OnAddReaders(addedreaders)

    def __init__(self, parent, appstyle, clientpanel):
        """Constructor. Create a smartcard and reader tree control on the
        left-hand side of the application main frame.
        @param parent: the tree panel parent
        @param appstyle: a combination of the following styles (bitwise or |)
          - TR_SMARTCARD: display a smartcard tree panel
          - TR_READER: display a reader tree panel
          - default is TR_DEFAULT = TR_SMARTCARD
        @param clientpanel: the client panel to notify of smartcard and reader events
        """
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)

        sizer = wx.BoxSizer(wx.VERTICAL)

        # create the smartcard tree
        if appstyle & smartcard.wx.SimpleSCardApp.TR_SMARTCARD:
            self.cardtreectrl = CardTreeCtrl(self, clientpanel=clientpanel)

            # create the smartcard insertion observer
            self.cardtreecardobserver = self._CardObserver(self.cardtreectrl)

            # register as a CardObserver; we will ge
            # notified of added/removed cards
            self.cardmonitor = CardMonitor()
            self.cardmonitor.addObserver(self.cardtreecardobserver)

            sizer.Add(
                self.cardtreectrl, flag=wx.EXPAND | wx.ALL, proportion=1)

        # create the reader tree
        if appstyle & smartcard.wx.SimpleSCardApp.TR_READER:
            self.readertreectrl = ReaderTreeCtrl(
                                        self, clientpanel=clientpanel)

            # create the reader insertion observer
            self.readertreereaderobserver = self._ReaderObserver(
                                                    self.readertreectrl)

            # register as a ReaderObserver; we will ge
            # notified of added/removed readers
            self.readermonitor = ReaderMonitor()
            self.readermonitor.addObserver(self.readertreereaderobserver)

            # create the smartcard insertion observer
            self.readertreecardobserver = self._CardObserver(
                                                self.readertreectrl)

            # register as a CardObserver; we will get
            # notified of added/removed cards
            self.cardmonitor = CardMonitor()
            self.cardmonitor.addObserver(self.readertreecardobserver)

            sizer.Add(
                self.readertreectrl, flag=wx.EXPAND | wx.ALL, proportion=1)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)

    def OnDestroy(self, event):
        """Called on panel destruction."""
        # deregister observers
        if hasattr(self, 'cardmonitor'):
            self.cardmonitor.deleteObserver(self.cardtreecardobserver)
        if hasattr(self, 'readermonitor'):
            self.readermonitor.deleteObserver(self.readertreereaderobserver)
            self.cardmonitor.deleteObserver(self.readertreecardobserver)
        event.Skip()
開發者ID:LudovicRousseau,項目名稱:pyscard,代碼行數:100,代碼來源:CardAndReaderTreePanel.py

示例13: Command

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import deleteObserver [as 別名]
class Command(BaseCommand):
    args = ''
    help = 'This program puts a default order (one coffee or tea) when a card is read.'

    def _enter_state(self, state):
        states = {
            STATE_NONE: {
                'name': 'STATE_NONE',
                # no call
            },
            STATE_INITIAL: {
                'name': 'STATE_INITIAL',
                'call': self._enter_initial, 
            },
            STATE_WAITING_FOR_READER: {
                'name': 'STATE_WAITING_FOR_READER',
                'call': self._enter_waiting_for_reader, 
            },
            STATE_READING_CARDS: {
                'name': 'STATE_READING_CARDS',
                'call': self._enter_reading_cards, 
            },
            STATE_EXIT: {
                'name': 'STATE_EXIT',
                'call': self._enter_exit, 
            },
        }

        if states.has_key(state):
            state_msg = 'state change: %s -> %s' % (
                states[self.state]['name'],
                states[state]['name'],
            )
            log.info(state_msg)
        else:
            err_msg = 'bad state: %r' % state
            log.error(err_msg)
            raise StateChangeError(err_msg)

        self.state = state
        states[state]['call']()

    def _setup_card_monitor_and_observer(self):
        self.card_monitor = CardMonitor()
        self.card_observer = OrderObserver()
        self.card_observer.initialize()
        self.card_monitor.addObserver(self.card_observer)

    def _tear_down_card_monitor_and_observer(self):
        if self.card_observer is not None and self.card_monitor is not None:
            self.card_monitor.deleteObserver(self.card_observer)
        self.card_monitor = None
        self.card_observer = None

    def _enter_waiting_for_reader(self):
        tasks.blipper_waiting.delay()
        while len(scsystem.readers()) == 0:
            sleep(1)
        self._enter_state(STATE_READING_CARDS)

    def _enter_reading_cards(self):
        self._setup_card_monitor_and_observer()
        tasks.blipper_reading_cards.delay()

        while len(scsystem.readers()) != 0:
            sleep(1)

        self._tear_down_card_monitor_and_observer()
        self._enter_state(STATE_WAITING_FOR_READER)

    def _enter_exit(self):
        self._tear_down_card_monitor_and_observer()
        log.info('finished program, normal exit')

    def _enter_initial(self):
        initial_readers = scsystem.readers()
        log.info('connected readers: %r' % initial_readers)
        tasks.blipper_ready.delay()
        try:
            if len(initial_readers) == 0:
                initial_state = STATE_WAITING_FOR_READER
            elif len(initial_readers) == 1:
                initial_state = STATE_READING_CARDS
            else:
                err_msg = '%d readers connected' % len(initial_readers)
                raise CardReaderError(err_msg)

            self._enter_state(initial_state)
        except KeyboardInterrupt:
            log.info('user exit')
        self._enter_state(STATE_EXIT)

    def handle(self, *args, **options):
        valid = True 
        if not valid:
            raise CommandError('invalid config')

        if settings.CARDREADER_PREFETCH:
            log.info('prefetch enabled')
            tasks.blipper_prefetch_users.delay()
#.........這裏部分代碼省略.........
開發者ID:Baljan,項目名稱:cafesys-fork,代碼行數:103,代碼來源:cardreader.py


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