Permalink
Browse files

CheckSum: cleared some old code for Python < v2.5

  • Loading branch information...
1 parent 683a9a3 commit 598ffae520adf7b5ff57a5b944a48d695197fc67 @etal etal committed Nov 4, 2012
Showing with 7 additions and 20 deletions.
  1. +7 −20 Bio/SeqUtils/CheckSum.py
View
27 Bio/SeqUtils/CheckSum.py
@@ -88,37 +88,24 @@ def seguid(seq):
For more information about SEGUID, see:
http://bioinformatics.anl.gov/seguid/
DOI: 10.1002/pmic.200600032 """
- try:
- #Python 2.5 sha1 is in hashlib
- import hashlib
- m = hashlib.sha1()
- except:
- #For older versions
- import sha
- m = sha.new()
+ import hashlib
import base64
+ m = hashlib.sha1()
try:
- #Assume its a Seq object
+ #Assume it's a Seq object
seq = str(seq)
except AttributeError:
- #Assume its a string
+ #Assume it's a string
pass
m.update(_as_bytes(seq.upper()))
try:
#For Python 3+
return base64.encodebytes(m.digest()).decode().replace("\n","").rstrip("=")
except AttributeError:
pass
- try:
- #For Python 2.5+
- return base64.b64encode(m.digest()).rstrip("=")
- except:
- #For older versions
- import os
- #Note: Using os.linesep doesn't work on Windows,
- #where os.linesep= "\r\n" but the encoded string
- #contains "\n" but not "\r\n"
- return base64.encodestring(m.digest()).replace("\n","").rstrip("=")
+ # For all other Pythons
+ return base64.b64encode(m.digest()).rstrip("=")
+
if __name__ == "__main__":
print "Quick self test"

0 comments on commit 598ffae

Please sign in to comment.