Browse Source

Fix exception on transmission abort with python3

With python3 sys.exc_value does no longer exist, but we can replace it
with sys.exc_info().
Sebastian Lohff 11 months ago
parent
commit
058de2f39c
3 changed files with 29 additions and 1 deletions
  1. 6
    0
      ChangeLog
  2. 2
    1
      servefile/servefile.py
  3. 21
    0
      tests/test_servefile.py

+ 6
- 0
ChangeLog View File

@@ -2,6 +2,12 @@ servefile changelog
2 2
 ===================
3 3
 
4 4
 
5
+Unreleased
6
+----------
7
+
8
+	* fixed bug where exception was shown on transmission abort with python3
9
+
10
+
5 11
 2020-10-30 v0.5.1
6 12
 -----------------
7 13
 

+ 2
- 1
servefile/servefile.py View File

@@ -714,7 +714,8 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler):
714 714
 
715 715
 class ThreadedHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
716 716
 	def handle_error(self, request, client_address):
717
-		print("%s ABORTED transmission (Reason: %s)" % (client_address[0], sys.exc_value))
717
+		_, exc_value, _ = sys.exc_info()
718
+		print("%s ABORTED transmission (Reason: %s)" % (client_address[0], exc_value))
718 719
 
719 720
 
720 721
 def catchSSLErrors(BaseSSLClass):

+ 21
- 0
tests/test_servefile.py View File

@@ -356,3 +356,24 @@ def test_https_big_download(run_servefile, datadir):
356 356
 
357 357
     urllib3.disable_warnings()
358 358
     check_download(data, protocol='https', verify=False)
359
+
360
+
361
+def test_abort_download(run_servefile, datadir):
362
+    data = "x" * (10 * 1024 ** 2)
363
+    p = datadir({'testfile': data}) / 'testfile'
364
+    env = os.environ.copy()
365
+    env['PYTHONUNBUFFERED'] = '1'
366
+    proc = run_servefile(str(p), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
367
+
368
+    # provoke a connection abort
369
+    # hopefully the buffers will not fill up with all of the 10mb
370
+    sock = socket.socket(socket.AF_INET)
371
+    sock.connect(("localhost", 8080))
372
+    sock.send(b"GET /testfile HTTP/1.0\n\n")
373
+    resp = sock.recv(100)
374
+    assert resp != b''
375
+    sock.close()
376
+    time.sleep(0.1)
377
+    proc.kill()
378
+    out = proc.stdout.read().decode()
379
+    assert "127.0.0.1 ABORTED transmission" in out

Loading…
Cancel
Save