15
15
# License for the specific language governing permissions and limitations
16
16
# under the License.
17
17
18
- import os
19
- import re
20
18
import csv
21
- import sys
22
- import math
19
+ import datetime
23
20
import errno
21
+ import math
22
+ import os
23
+ import platform
24
+ import re
24
25
import signal
25
26
import socket
26
- import timeit
27
- import datetime
28
- import platform
27
+ import sys
29
28
import threading
29
+ import timeit
30
30
import xml .parsers .expat
31
31
32
32
try :
36
36
gzip = None
37
37
GZIP_BASE = object
38
38
39
- __version__ = '2.1.3 '
39
+ __version__ = '2.1.4b1 '
40
40
41
41
42
42
class FakeShutdownEvent (object ):
@@ -49,13 +49,16 @@ def isSet():
49
49
"Dummy method to always return false" ""
50
50
return False
51
51
52
+ is_set = isSet
53
+
52
54
53
55
# Some global variables we use
54
56
DEBUG = False
55
57
_GLOBAL_DEFAULT_TIMEOUT = object ()
56
58
PY25PLUS = sys .version_info [:2 ] >= (2 , 5 )
57
59
PY26PLUS = sys .version_info [:2 ] >= (2 , 6 )
58
60
PY32PLUS = sys .version_info [:2 ] >= (3 , 2 )
61
+ PY310PLUS = sys .version_info [:2 ] >= (3 , 10 )
59
62
60
63
# Begin import game to handle Python 2 and Python 3
61
64
try :
@@ -266,17 +269,6 @@ def write(data):
266
269
write (arg )
267
270
write (end )
268
271
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
-
280
272
# Exception "constants" to support Python 2 through Python 3
281
273
try :
282
274
import ssl
@@ -293,6 +285,23 @@ def write(data):
293
285
ssl = None
294
286
HTTP_ERRORS = (HTTPError , URLError , socket .error , BadStatusLine )
295
287
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
+
296
305
297
306
class SpeedtestException (Exception ):
298
307
"""Base exception for this module"""
@@ -769,7 +778,7 @@ def print_dots(shutdown_event):
769
778
status
770
779
"""
771
780
def inner (current , total , start = False , end = False ):
772
- if shutdown_event . isSet ( ):
781
+ if event_is_set ( shutdown_event ):
773
782
return
774
783
775
784
sys .stdout .write ('.' )
@@ -808,7 +817,7 @@ def run(self):
808
817
try :
809
818
if (timeit .default_timer () - self .starttime ) <= self .timeout :
810
819
f = self ._opener (self .request )
811
- while (not self ._shutdown_event . isSet ( ) and
820
+ while (not event_is_set ( self ._shutdown_event ) and
812
821
(timeit .default_timer () - self .starttime ) <=
813
822
self .timeout ):
814
823
self .result .append (len (f .read (10240 )))
@@ -864,7 +873,7 @@ def data(self):
864
873
865
874
def read (self , n = 10240 ):
866
875
if ((timeit .default_timer () - self .start ) <= self .timeout and
867
- not self ._shutdown_event . isSet ( )):
876
+ not event_is_set ( self ._shutdown_event )):
868
877
chunk = self .data .read (n )
869
878
self .total .append (len (chunk ))
870
879
return chunk
@@ -902,7 +911,7 @@ def run(self):
902
911
request = self .request
903
912
try :
904
913
if ((timeit .default_timer () - self .starttime ) <= self .timeout and
905
- not self ._shutdown_event . isSet ( )):
914
+ not event_is_set ( self ._shutdown_event )):
906
915
try :
907
916
f = self ._opener (request )
908
917
except TypeError :
0 commit comments