Package tlslite :: Package utils :: Module compat
[hide private]
[frames] | no frames]

Source Code for Module tlslite.utils.compat

 1  # Author: Trevor Perrin 
 2  # See the LICENSE file for legal information regarding use of this file. 
 3   
 4  """Miscellaneous functions to mask Python version differences.""" 
 5   
 6  import sys 
 7  import os 
 8  import math 
 9   
10  # Requires Python 2.5 
11  from hashlib import md5 
12  from hashlib import sha1  
13   
14  # Requires Python 2.6, will need to be changed for Python 3 
15 -def createByteArraySequence(seq):
16 return bytearray(seq)
17 -def createByteArrayZeros(howMany):
18 return bytearray(howMany)
19
20 -def bytesToString(bytes):
21 return str(bytes)
22 -def stringToBytes(s):
23 bytes = bytearray(s) 24 return bytes
25
26 -def numBits(n):
27 if n==0: 28 return 0 29 s = "%x" % n 30 return ((len(s)-1)*4) + \ 31 {'0':0, '1':1, '2':2, '3':2, 32 '4':3, '5':3, '6':3, '7':3, 33 '8':4, '9':4, 'a':4, 'b':4, 34 'c':4, 'd':4, 'e':4, 'f':4, 35 }[s[0]] 36 return int(math.floor(math.log(n, 2))+1)
37 38 import traceback
39 -def formatExceptionTrace(e):
40 newStr = "".join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) 41 return newStr
42