[pycrypto] Once again: Python3 with PyCrypto

Thorsten Behrens sbehrens at gmx.li
Thu Dec 23 22:51:33 CST 2010

On 12/23/2010 9:18 PM, Dwayne C. Litzenberger wrote:
> Also, down the road, I could be convinced to drop Python 2.1 support, if I
> had some concrete examples showing that the result would be substantially
> less error-prone, easier to maintain, etc.
So far, it doesn't look like that's needed. dict.has_key() cannot be 
replaced with "in" for 2.1, but 2to3 seems to handle it fine.

Does "setup.py test" touch all of the pycrypto library, or only part of 
it? That is, can I rely on its output to know whether a conversion to 
Python 3.x was successful?

I can use some assistance with asn1.py. It defines the magic slice 
methods. These are gone for good in Python 3.x (deprecated since Python 
2.0). My understanding is that in Python 2.x, it's still necessary to 
define these, as they may get called when the parent class has them. 
Fair enough.

As I understand it, in 3.x, the item methods are called with a sequence 
wherever a slice method would have been called before. Given this code, 
then, is that going to cause issues? Do the item methods need to be 
changed to make sure the class still behaves as expected under 3.x?

class DerSequence(DerObject):
     def __init__(self):
         DerObject.__init__(self, 'SEQUENCE')
         self._seq = []
     def __delitem__(self, n):
         del self._seq[n]
     def __getitem__(self, n):
         return self._seq[n]
     def __setitem__(self, key, value):
         self._seq[key] = value
     def __setslice__(self,i,j,sequence):
         self._seq[i:j] = sequence
     def __delslice__(self,i,j):
         del self._seq[i:j]
     def __getslice__(self, i, j):
         return self._seq[max(0, i):max(0, j)]
     def __len__(self):
         return len(self._seq)
     def append(self, item):
         return self._seq.append(item)

More information about the pycrypto mailing list