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


Python CardMonitor.addObserver方法代碼示例

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


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

示例1: APDUShell

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [as 別名]
class APDUShell(cmd.Cmd):
    """Command shell to communicate with smartcard via APDU.

    Reader selection will be performed on shell start.
    Prompt will contain a selected reader's name and FID of latest selected EF or DF.
    Response data and SW for each APDU will be printed in console.
    """

    def __init__(self, *args, **kwargs):
        # base classes are old style classes so super() not allowed here
        cmd.Cmd.__init__(self, *args, **kwargs)

        self.reader = select_reader()
        self.card = None
        self.connection = None
        self.sel_obj = ''
        self.card_monitor = CardMonitor()
        self.card_monitor.addObserver(self)

    def _card_observer_update(self, observable, (addedcards, removedcards)):
        """CardObserver interface implementation"""

        if self.card and self.card in removedcards:
            self.sel_obj = ''
            self.card = None
            self.connection = None

        for card in addedcards:
            if card.reader == self.reader:
                self.card = card
                self._set_up_connection()
                break
開發者ID:12019,項目名稱:python-apducmd,代碼行數:34,代碼來源:apducmd.py

示例2: triggered_decorator

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [as 別名]
def triggered_decorator(func):
    # print("Starting observation of reader %s" % func.__defaults__[0])
    class SimpleObserver(CardObserver):
        reader = func.__defaults__[0]
        def update(self, observable, actions):
            added_cards, removed_cards = actions

            # all readers involved in actions
            action_readers = [c.reader for c in added_cards] + [c.reader for c in removed_cards]

            # if the one we observe is not the list, we return None
            if not self.reader in action_readers:
                return None

            # card added
            if len(added_cards):
                for c in added_cards:
                    if c.reader == self.reader:
                        return func(action="inserted", card=c, reader=self.reader)

            # card removed
            if len(removed_cards):
                for c in removed_cards:
                    if c.reader == self.reader:
                        return func(action="removed", card=c, reader=self.reader)
            return None
    # installing observer
    cm = CardMonitor()
    so = SimpleObserver()
    cm.addObserver(so)
    return so.update
開發者ID:Lapin-Blanc,項目名稱:pidoor,代碼行數:33,代碼來源:beid.py

示例3: main

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [as 別名]
def 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 )
開發者ID:HeesangLee,項目名稱:nfcPython,代碼行數:9,代碼來源:nfcTest.py

示例4: SmartCardMonitor

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例5: smartcardBridge

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例6: CardManager

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

    def __init__(self, card_list_env, auto_connect_env):
        self.cardmonitor = CardMonitor()
        self.card_list_env = card_list_env
        self.auto_connect_env = auto_connect_env  # TODO
        # self.enable = True
        # self.card_list = []
        self.cardmonitor.addObserver(self)
        # self.autocon = False

    def update(self, observable, xxx_todo_changeme):
        # FIXME should raise an event and no more (WAIT FOR EVENT MANAGER)
        #    the business should not occured here (because of lock, etc..)

        (addedcards, removedcards) = xxx_todo_changeme
        r = ""  # card connected or removed
        # ac = "" #autoconnect result
        if addedcards is not None and len(addedcards) > 0:
            r += "Added card(s) " + str(addedcards)

            # TODO should be in critical section
            card_list = self.card_list_env.getValue()[:]

            for c in addedcards:
                card_list.append(c)

            self.card_list_env.setValue(card_list)
            # XXX

            # ac = self.autoConnect()

        if removedcards is not None and len(removedcards) > 0:

            if len(r) > 0:
                r += "\n"

            r += "Removed cards" + str(removedcards)

            # TODO should be in critical section
            card_list = self.card_list_env.getValue()[:]

            for c in removedcards:
                card_list.remove(c)

            self.card_list_env.setValue(card_list)
            # XXX

            # if hasattr(c,'connection'):
            #    disconnectReaderFromCardFun(Executer.envi)
            #    print("WARNING : the card has been removed, the connection "
            #          "is broken")

        if len(r) > 0:
            notice(r)
開發者ID:djoproject,項目名稱:RFIDShell,代碼行數:61,代碼來源:pcsc.py

示例7: daemon_body

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例8: __init__

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [as 別名]
class ContactPoint:
    """
    ContactPoint is the central class of the application.
    """
    debug = False
    local_config = {}
    listening = False

    def __init__(self):
        '''
        Initialises the debug mode, logger.
        '''
        self.env = environ['CONTACTPOINT_ENV']
        if self.env == 'development':
            self.debug = True
        self.init_emulator()
        self.logger = Logger(self.debug)
        self.logger.log('System started...')
        self.server = Server(self, self.debug)
        self.listen()

    def process(self, action, tag_id=None):
        '''
        The process function is called each time an action happens on the RFID
        reader.
        '''
        response = dict(action=action)
        if tag_id is not None:
            response['tag_id'] = tag_id
        self.logger.debug(response)
        self.server.send_msg('listen_taps', response)

    def init_emulator(self):
        '''
        If the application is running in development mode, the process method is
        aliased as emulate too. This is for nomenclature convenience. This
        function shall be called as emulate, to emulate card taps in development
        mode.
        '''
        if self.debug is True:
            self.emulate = self.process

    def listen(self):
        '''
        The listen function is called during initialisation of the class & the
        application. It initialises the process of starting to listen to card
        taps on the reader.
        '''
        self.monitor = CardMonitor()
        self.observer = Observer(self)
        self.monitor.addObserver(self.observer)
開發者ID:hasgeek,項目名稱:contactpoint,代碼行數:53,代碼來源:__init__.py

示例9: testthread

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例10: startLoop

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例11: daemon_body

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例12: testthread

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例13: _CcidCardObserver

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

    def __init__(self, controller):
        self._controller = weakref.ref(controller)
        self._monitor = CardMonitor()
        self._monitor.addObserver(self)

    def update(self, observable, tup):
        (added, removed) = tup
        c = self._controller()
        if c:
            c._update([card.reader for card in added],
                      [r.reader for r in removed])

    def delete(self):
        self._monitor.deleteObservers()
開發者ID:Yubico,項目名稱:yubioath-desktop-dpkg,代碼行數:18,代碼來源:ccid.py

示例14: entry_point

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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

示例15: Webconnector

# 需要導入模塊: from smartcard.CardMonitoring import CardMonitor [as 別名]
# 或者: from smartcard.CardMonitoring.CardMonitor import addObserver [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


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