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


Python CardMonitoring.CardMonitor類代碼示例

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


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

示例1: smartcardBridge

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,代碼行數:26,代碼來源:smartcardBridge.py

示例2: APDUShell

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,代碼行數:32,代碼來源:apducmd.py

示例3: triggered_decorator

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,代碼行數:31,代碼來源:beid.py

示例4: main

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,代碼行數:7,代碼來源:nfcTest.py

示例5: SmartCardMonitor

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,代碼行數:32,代碼來源:SmartCardMonitor.py

示例6: CardManager

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,代碼行數:59,代碼來源:pcsc.py

示例7: __init__

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

示例8: daemon_body

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,代碼行數:12,代碼來源:smart_card2twitter.py

示例9: __init__

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,代碼行數:51,代碼來源:__init__.py

示例10: daemon_body

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,代碼行數:14,代碼來源:smart_card.py

示例11: testthread

    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,代碼行數:14,代碼來源:CardMonitoring.py

示例12: startLoop

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,代碼行數:14,代碼來源:loop.py

示例13: testthread

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,代碼行數:15,代碼來源:testcase_CardMonitor.py

示例14: __init__

 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)
開發者ID:djoproject,項目名稱:RFIDShell,代碼行數:7,代碼來源:pcsc.py

示例15: __init__

    def __init__(self, args):
        feedbackHandler.setup()

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

        self.addCardObserver(self.cardobserver)
開發者ID:StuffCard,項目名稱:smartcard-webconnector-python,代碼行數:7,代碼來源:webconnector.py


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