Merge pull request #12 from tomas-edwardsson/master

Python older than 2.5 fails, struct.unpack_from not available
This commit is contained in:
Joel Martin 2011-10-06 07:33:39 -07:00
commit 1658649d0c
1 changed files with 13 additions and 1 deletions

View File

@ -17,7 +17,7 @@ as taken from http://docs.python.org/dev/library/ssl.html#certificates
'''
import os, sys, time, errno, signal, socket, traceback, select
import struct, array
import array
from cgi import parse_qsl
from base64 import b64encode, b64decode
@ -50,6 +50,18 @@ else:
from md5 import md5
from sha import sha as sha1
if sys.hexversion >= 0x2050000:
# python >= 2.5
import struct
else:
# python < 2.5
import struct
# unpack_from was introduced in python 2.5
def _unpack_from(fmt, buf, offset=0):
slice = buffer(buf, offset, struct.calcsize(fmt))
return struct.unpack(fmt, slice)
struct.unpack_from = _unpack_from
# Degraded functionality if these imports are missing
for mod, sup in [('numpy', 'HyBi protocol'),
('ssl', 'TLS/SSL/wss'), ('resource', 'daemonizing')]: