本文整理汇总了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)
示例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
示例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
示例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 )
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例15: __init__
def __init__(self, args):
feedbackHandler.setup()
self.cardmonitor = CardMonitor()
self.cardobserver = cardWebconnector(args)
self.addCardObserver(self.cardobserver)