]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - TLD_Builder/request_fetcher.py
- drop util.sendfile, use shutil.copyfileobj instead
[tld-builder.git] / TLD_Builder / request_fetcher.py
index 9877cde771572ba4e7a23ca73fa2e2251a639ee2..ae237a21331380a697430d6e657d2e307f729099 100644 (file)
@@ -4,16 +4,15 @@ import string
 import signal
 import os
 import urllib
-import urllib2
-import StringIO
 import sys
+from io import StringIO, BytesIO
 import gzip
-
 import path
 import log
 import status
 import lock
 import util
+import shutil
 import gpg
 import request
 import loop
@@ -26,14 +25,14 @@ from config import config, init_conf
 last_count = 0
 
 def alarmalarm(signum, frame):
-    raise IOError, 'TCP connection hung'
+    raise IOError('TCP connection hung')
 
 def has_new(control_url):
     global last_count
     cnt_f = open(path.last_req_no_file)
     try:
-        last_count = int(string.strip(cnt_f.readline()))
-    except ValueError, e:
+        last_count = int(cnt_f.readline().strip())
+    except ValueError as e:
         last_count = 0
 
     cnt_f.close()
@@ -43,11 +42,11 @@ def has_new(control_url):
     signal.alarm(300)
     try:
         headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
-        req = urllib2.Request(url=control_url + "/max_req_no", headers=headers)
-        f = urllib2.urlopen(req)
-        count = int(string.strip(f.readline()))
+        req = urllib.request.Request(url=control_url + "/max_req_no", headers=headers)
+        f = urllib.request.urlopen(req)
+        count = int(f.readline().strip())
         signal.alarm(0)
-    except Exception, e:
+    except Exception as e:
         signal.alarm(0)
         log.error("can't fetch %s: %s" % (control_url + "/max_req_no", e))
         sys.exit(1)
@@ -63,21 +62,21 @@ def fetch_queue(control_url):
     signal.alarm(300)
     try:
         headers = { 'Cache-Control': 'no-cache', 'Pragma': 'no-cache' }
-        req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
-        f = urllib2.urlopen(req)
+        req = urllib.request.Request(url=control_url + "/queue.gz", headers=headers)
+        f = urllib.request.urlopen(req)
         signal.alarm(0)
-    except Exception, e:
+    except Exception as e:
         signal.alarm(0)
         log.error("can't fetch %s: %s" % (control_url + "/queue.gz", e))
         sys.exit(1)
-    sio = StringIO.StringIO()
-    util.sendfile(f, sio)
+    sio = BytesIO()
+    shutil.copyfileobj(f, sio)
     f.close()
     sio.seek(0)
     f = gzip.GzipFile(fileobj = sio)
     try:
         fdata = f.read()
-    except struct.error, e:
+    except struct.error as e:
         log.alert("corrupted fetched queue.gz file")
         sys.exit(1)
     (signers, body) = gpg.verify_sig(fdata)
@@ -99,7 +98,7 @@ def handle_reqs(builder, reqs):
     q.read()
     for r in reqs:
         if r.kind != 'group':
-            raise Exception, 'handle_reqs: fatal: huh? %s' % r.kind
+            raise Exception('handle_reqs: fatal: huh? %s' % r.kind)
         need_it = 0
         for b in r.batches:
             if builder in b.builders: