当前位置: 首页>>代码示例>>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;未经允许,请勿转载。