[pycrypto] Once again: Python3 with PyCrypto
Thorsten Behrens
sbehrens at gmx.li
Fri Dec 24 18:24:43 CST 2010
Still crashing, just not on importing winrandom any more. I found the
typo there. More errors remain, clearly.
I have a question regarding the str/bytes situation in Python 3. Take
this example from Counter.py:
if sys.version_info[0] is 2:
if little_endian:
return _counter._newLE(str(prefix), str(suffix), initval,
allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
else:
return _counter._newBE(str(prefix), str(suffix), initval,
allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
else:
if little_endian:
return _counter._newLE(prefix.encode(), suffix.encode(),
initval.encode(), allow_wraparound=allow_wraparound,
disable_shortcut=disable_shortcut)
else:
return _counter._newBE(prefix.encode(), suffix.encode(),
initval.encode(), allow_wraparound=allow_wraparound,
disable_shortcut=disable_shortcut)
Not having had that much exposure to this code, my question is: Would it
be safe to just use .encode() throughout, without the check for Python
version? From all I can tell, it'll work as desired - but there may be a
corner case I haven't considered. Essentially, can I collapse the above
again to:
if little_endian:
return _counter._newLE(prefix.encode(), suffix.encode(),
initval.encode(), allow_wraparound=allow_wraparound,
disable_shortcut=disable_shortcut)
else:
return _counter._newBE(prefix.encode(), suffix.encode(),
initval.encode(), allow_wraparound=allow_wraparound,
disable_shortcut=disable_shortcut)
for all versions of Python, 2.x and 3.x.
Dwayne, can you shed some light?
Thorsten
More information about the pycrypto
mailing list