|
From: <lu...@us...> - 2011-09-03 21:28:28
|
Revision: 541
http://pyscard.svn.sourceforge.net/pyscard/?rev=541&view=rev
Author: ludov
Date: 2011-09-03 21:28:22 +0000 (Sat, 03 Sep 2011)
Log Message:
-----------
Add CardConnection.getAttrib() method
Sample code:
card_connection = readers()[0].createConnection()
card_connection.connect(mode=SCARD_SHARE_DIRECT, disposition=SCARD_LEAVE_CARD)
vendor_name = card_connection.getAttrib(SCARD_ATTR_VENDOR_NAME)
Modified Paths:
--------------
trunk/pyscard/src/smartcard/CardConnection.py
trunk/pyscard/src/smartcard/CardConnectionDecorator.py
trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py
Modified: trunk/pyscard/src/smartcard/CardConnection.py
===================================================================
--- trunk/pyscard/src/smartcard/CardConnection.py 2011-09-03 16:44:37 UTC (rev 540)
+++ trunk/pyscard/src/smartcard/CardConnection.py 2011-09-03 21:28:22 UTC (rev 541)
@@ -174,3 +174,21 @@
Subclasses must override this method for implementing control."""
pass
+
+ def getAttrib(self, attribId):
+ """return the requested attribute
+
+ attribId: attribute id like SCARD_ATTR_VENDOR_NAME
+ """
+ Observable.setChanged(self)
+ Observable.notifyObservers(self, CardConnectionEvent('attrib', [attribId]))
+ data = self.doGetAttrib(attribId)
+ if None != self.errorcheckingchain:
+ self.errorcheckingchain[0](data)
+ return data
+
+ def doGetAttrib(self, attribId):
+ """Performs the command get attrib.
+
+ Subclasses must override this method for implementing get attrib."""
+ pass
Modified: trunk/pyscard/src/smartcard/CardConnectionDecorator.py
===================================================================
--- trunk/pyscard/src/smartcard/CardConnectionDecorator.py 2011-09-03 16:44:37 UTC (rev 540)
+++ trunk/pyscard/src/smartcard/CardConnectionDecorator.py 2011-09-03 21:28:22 UTC (rev 541)
@@ -84,3 +84,7 @@
def control(self, controlCode, bytes=[]):
"""call inner component control"""
return self.component.control(controlCode, bytes)
+
+ def getAttrib(self, attribId):
+ """call inner component getAttrib"""
+ return self.component.getAttrib(attribId)
Modified: trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py
===================================================================
--- trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py 2011-09-03 16:44:37 UTC (rev 540)
+++ trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py 2011-09-03 21:28:22 UTC (rev 541)
@@ -197,6 +197,20 @@
data = map(lambda x: (x + 256) % 256, response)
return data
+ def doGetAttrib(self, attribId):
+ """get an attribute
+
+ attribId: Identifier for the attribute to get
+
+ return: response are the attribute byte array
+ """
+ CardConnection.doGetAttrib(self, attribId)
+ hresult, response = SCardGetAttrib(self.hcard, attribId)
+ if hresult != 0:
+ raise CardConnectionException('Failed to getAttrib ' + SCardGetErrorMessage(hresult))
+ return response
+
+
if __name__ == '__main__':
"""Small sample illustrating the use of CardConnection."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|