Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- """
- Sample script that monitors smartcard insertion/removal.
- This script is used for testing memory leak.
- """
- from __future__ import print_function
- from time import sleep
- from smartcard.CardMonitoring import CardMonitor, CardObserver
- from smartcard.util import toHexString
- # a simple card observer that prints inserted/removed cards
- 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 run forever")
- print("")
- cardmonitor = CardMonitor()
- cardobserver = PrintObserver()
- cardmonitor.addObserver(cardobserver)
- while True:
- sleep(600)
- # 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement