Advertisement
valdur55

minimal-leak.py

Feb 8th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1.  #! /usr/bin/env python
  2. """
  3. Sample script that monitors smartcard insertion/removal.
  4.  
  5. This script is used for testing memory leak.
  6.  
  7. """
  8.  
  9. from __future__ import print_function
  10. from time import sleep
  11.  
  12. from smartcard.CardMonitoring import CardMonitor, CardObserver
  13. from smartcard.util import toHexString
  14.  
  15.  
  16. # a simple card observer that prints inserted/removed cards
  17. class PrintObserver(CardObserver):
  18.     """A simple card observer that is notified
  19.    when cards are inserted/removed from the system and
  20.    prints the list of cards
  21.    """
  22.  
  23.     def update(self, observable, actions):
  24.         (addedcards, removedcards) = actions
  25.         for card in addedcards:
  26.             print("+Inserted: ", toHexString(card.atr))
  27.         for card in removedcards:
  28.             print("-Removed: ", toHexString(card.atr))
  29.  
  30. if __name__ == '__main__':
  31.     print("Insert or remove a smartcard in the system.")
  32.     print("This program will run forever")
  33.     print("")
  34.     cardmonitor = CardMonitor()
  35.     cardobserver = PrintObserver()
  36.     cardmonitor.addObserver(cardobserver)
  37.  
  38.     while True:
  39.         sleep(600)
  40.  
  41.     # don't forget to remove observer, or the
  42.     # monitor will poll forever...
  43.     cardmonitor.deleteObserver(cardobserver)
  44.  
  45.     import sys
  46.     if 'win32' == sys.platform:
  47.         print('press Enter to continue')
  48.         sys.stdin.read(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement