|
From: <jda...@us...> - 2010-06-07 17:04:28
|
Revision: 445
http://pyscard.svn.sourceforge.net/pyscard/?rev=445&view=rev
Author: jdaussel
Date: 2010-06-07 17:04:20 +0000 (Mon, 07 Jun 2010)
Log Message:
-----------
Added three new exceptions
Modified Paths:
--------------
trunk/pyscard/src/smartcard/pcsc/PCSCExceptions.py
trunk/pyscard/src/smartcard/pcsc/PCSCReader.py
Modified: trunk/pyscard/src/smartcard/pcsc/PCSCExceptions.py
===================================================================
--- trunk/pyscard/src/smartcard/pcsc/PCSCExceptions.py 2010-06-06 18:53:08 UTC (rev 444)
+++ trunk/pyscard/src/smartcard/pcsc/PCSCExceptions.py 2010-06-07 17:04:20 UTC (rev 445)
@@ -46,6 +46,18 @@
smartcard.scard.SCardGetErrorMessage(self.hresult))
+class AddReaderToGroupException(BaseSCardException):
+ """Raised when scard fails to add a new reader to a PCSC reader group."""
+
+ def __init__( self, hresult, readername="", groupname="" ):
+ BaseSCardException.__init__( self, hresult )
+ self.readername = readername
+ self.groupname = groupname
+
+ def __str__(self):
+ return repr('Failure to add reader: ' + self.readername + ' to group: ' + self.groupname + ' ' +
+ smartcard.scard.SCardGetErrorMessage(self.hresult))
+
class EstablishContextException(BaseSCardException):
"""Raised when scard failed to establish context with PCSC."""
@@ -63,11 +75,15 @@
smartcard.scard.SCardGetErrorMessage(self.hresult))
-class EstablishContextException(BaseSCardException):
- """Raised when scard failed to establish a PCSC context."""
+class IntroduceReaderException(BaseSCardException):
+ """Raised when scard fails to introduce a new reader to PCSC."""
+ def __init__( self, hresult, readername="" ):
+ BaseSCardException.__init__( self, hresult )
+ self.readername = readername
+
def __str__(self):
- return repr('Failure to establish context: ' +
+ return repr('Failure to introduce a new reader: ' + self.readername + ' ' +
smartcard.scard.SCardGetErrorMessage(self.hresult))
@@ -78,6 +94,18 @@
return repr('Failure to release context: ' +
smartcard.scard.SCardGetErrorMessage(self.hresult))
+class RemoveReaderFromGroupException(BaseSCardException):
+ """Raised when scard fails to remove a reader from a PCSC reader group."""
+
+ def __init__( self, hresult, readername="", groupname="" ):
+ BaseSCardException.__init__( self, hresult )
+ self.readername = readername
+ self.groupname = groupname
+
+ def __str__(self):
+ return repr('Failure to remove reader: ' + self.readername + ' from group: ' + self.groupname + ' ' +
+ smartcard.scard.SCardGetErrorMessage(self.hresult))
+
if __name__ == "__main__":
import sys
try:
Modified: trunk/pyscard/src/smartcard/pcsc/PCSCReader.py
===================================================================
--- trunk/pyscard/src/smartcard/pcsc/PCSCReader.py 2010-06-06 18:53:08 UTC (rev 444)
+++ trunk/pyscard/src/smartcard/pcsc/PCSCReader.py 2010-06-07 17:04:20 UTC (rev 445)
@@ -67,10 +67,10 @@
try:
hresult = SCardIntroduceReader(hcontext, self.name, self.name)
if 0 != hresult and SCARD_E_DUPLICATE_READER != hresult:
- raise error, 'Unable to introduce reader: ' + self.name + ' : ' + SCardGetErrorMessage(hresult)
+ raise IntroduceReaderException(hresult,self.name)
hresult = SCardAddReaderToGroup(hcontext, self.name, groupname)
if 0 != hresult:
- raise error, 'Unable to add reader to group: ' + SCardGetErrorMessage(hresult)
+ raise AddReaderToGroupException(hresult,self.name,groupname)
finally:
hresult = SCardReleaseContext(hcontext)
if 0 != hresult:
@@ -85,7 +85,7 @@
try:
hresult = SCardRemoveReaderFromGroup(hcontext, self.name, groupname)
if 0 != hresult:
- raise error, 'Unable to add reader to group: ' + SCardGetErrorMessage(hresult)
+ raise RemoveReaderFromGroupException(hresult,self.name,groupname)
finally:
hresult = SCardReleaseContext(hcontext)
if 0 != hresult:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|