1515# License for the specific language governing permissions and limitations
1616# under the License.
1717
18- import os
19- import re
2018import csv
21- import sys
22- import math
19+ import datetime
2320import errno
21+ import math
22+ import os
23+ import platform
24+ import re
2425import signal
2526import socket
26- import timeit
27- import datetime
28- import platform
27+ import sys
2928import threading
29+ import timeit
3030import xml .parsers .expat
3131
3232try :
3636 gzip = None
3737 GZIP_BASE = object
3838
39- __version__ = '2.1.3 '
39+ __version__ = '2.1.4b1 '
4040
4141
4242class FakeShutdownEvent (object ):
@@ -49,13 +49,16 @@ def isSet():
4949 "Dummy method to always return false" ""
5050 return False
5151
52+ is_set = isSet
53+
5254
5355# Some global variables we use
5456DEBUG = False
5557_GLOBAL_DEFAULT_TIMEOUT = object ()
5658PY25PLUS = sys .version_info [:2 ] >= (2 , 5 )
5759PY26PLUS = sys .version_info [:2 ] >= (2 , 6 )
5860PY32PLUS = sys .version_info [:2 ] >= (3 , 2 )
61+ PY310PLUS = sys .version_info [:2 ] >= (3 , 10 )
5962
6063# Begin import game to handle Python 2 and Python 3
6164try :
@@ -266,17 +269,6 @@ def write(data):
266269 write (arg )
267270 write (end )
268271
269- if PY32PLUS :
270- etree_iter = ET .Element .iter
271- elif PY25PLUS :
272- etree_iter = ET_Element .getiterator
273-
274- if PY26PLUS :
275- thread_is_alive = threading .Thread .is_alive
276- else :
277- thread_is_alive = threading .Thread .isAlive
278-
279-
280272# Exception "constants" to support Python 2 through Python 3
281273try :
282274 import ssl
@@ -293,6 +285,23 @@ def write(data):
293285 ssl = None
294286 HTTP_ERRORS = (HTTPError , URLError , socket .error , BadStatusLine )
295287
288+ if PY32PLUS :
289+ etree_iter = ET .Element .iter
290+ elif PY25PLUS :
291+ etree_iter = ET_Element .getiterator
292+
293+ if PY26PLUS :
294+ thread_is_alive = threading .Thread .is_alive
295+ else :
296+ thread_is_alive = threading .Thread .isAlive
297+
298+
299+ def event_is_set (event ):
300+ try :
301+ return event .is_set ()
302+ except AttributeError :
303+ return event .isSet ()
304+
296305
297306class SpeedtestException (Exception ):
298307 """Base exception for this module"""
@@ -769,7 +778,7 @@ def print_dots(shutdown_event):
769778 status
770779 """
771780 def inner (current , total , start = False , end = False ):
772- if shutdown_event . isSet ( ):
781+ if event_is_set ( shutdown_event ):
773782 return
774783
775784 sys .stdout .write ('.' )
@@ -808,7 +817,7 @@ def run(self):
808817 try :
809818 if (timeit .default_timer () - self .starttime ) <= self .timeout :
810819 f = self ._opener (self .request )
811- while (not self ._shutdown_event . isSet ( ) and
820+ while (not event_is_set ( self ._shutdown_event ) and
812821 (timeit .default_timer () - self .starttime ) <=
813822 self .timeout ):
814823 self .result .append (len (f .read (10240 )))
@@ -864,7 +873,7 @@ def data(self):
864873
865874 def read (self , n = 10240 ):
866875 if ((timeit .default_timer () - self .start ) <= self .timeout and
867- not self ._shutdown_event . isSet ( )):
876+ not event_is_set ( self ._shutdown_event )):
868877 chunk = self .data .read (n )
869878 self .total .append (len (chunk ))
870879 return chunk
@@ -902,7 +911,7 @@ def run(self):
902911 request = self .request
903912 try :
904913 if ((timeit .default_timer () - self .starttime ) <= self .timeout and
905- not self ._shutdown_event . isSet ( )):
914+ not event_is_set ( self ._shutdown_event )):
906915 try :
907916 f = self ._opener (request )
908917 except TypeError :
0 commit comments