|
1 | | -#!/usr/bin/env python |
| 1 | +#!/usr/bin/env python3 |
2 | 2 | # |
3 | 3 | # check_patches_in_archives.py |
4 | 4 | # |
|
9 | 9 |
|
10 | 10 | import os |
11 | 11 | import sys |
12 | | -import socket |
13 | | -import httplib |
| 12 | +import requests |
14 | 13 | import magic |
15 | 14 | import logging |
16 | 15 |
|
|
33 | 32 | level=debug and logging.DEBUG or logging.INFO, |
34 | 33 | stream=sys.stdout) |
35 | 34 |
|
36 | | - socket.setdefaulttimeout(settings.ARCHIVES_TIMEOUT) |
37 | 35 | mag = magic.open(magic.MIME) |
38 | 36 | mag.load() |
39 | 37 |
|
|
48 | 46 | url = "/message-id/attachment/%s/attach" % a.attachmentid |
49 | 47 | logging.debug("Checking attachment %s" % a.attachmentid) |
50 | 48 |
|
51 | | - if settings.ARCHIVES_PORT != 443: |
52 | | - h = httplib.HTTPConnection(host=settings.ARCHIVES_SERVER, |
53 | | - port=settings.ARCHIVES_PORT, |
54 | | - strict=True, |
55 | | - timeout=settings.ARCHIVES_TIMEOUT) |
56 | | - else: |
57 | | - h = httplib.HTTPSConnection(host=settings.ARCHIVES_SERVER, |
58 | | - port=settings.ARCHIVES_PORT, |
59 | | - strict=True, |
60 | | - timeout=settings.ARCHIVES_TIMEOUT) |
61 | | - h.request('GET', url, headers={ |
62 | | - 'Host': settings.ARCHIVES_HOST, |
63 | | - }) |
64 | | - resp = h.getresponse() |
65 | | - if resp.status != 200: |
66 | | - logging.error("Failed to get %s: %s" % (url, resp.status)) |
67 | | - continue |
| 49 | + resp = requests.get( |
| 50 | + "http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '', |
| 51 | + settings.ARCHIVES_SERVER, |
| 52 | + settings.ARCHIVES_PORT, |
| 53 | + url), |
| 54 | + headers={ |
| 55 | + 'Host': settings.ARCHIVES_HOST, |
| 56 | + }, |
| 57 | + timeout=settings.ARCHIVES_TIMEOUT, |
| 58 | + ) |
68 | 59 |
|
69 | | - contents = resp.read() |
70 | | - resp.close() |
71 | | - h.close() |
| 60 | + if resp.status_code != 200: |
| 61 | + logging.error("Failed to get %s: %s" % (url, resp.status_code)) |
| 62 | + continue |
72 | 63 |
|
73 | 64 | # Attempt to identify the file using magic information |
74 | | - mtype = mag.buffer(contents) |
| 65 | + mtype = mag.buffer(resp.content) |
75 | 66 | logging.debug("Detected MIME type is %s" % mtype) |
76 | 67 |
|
77 | 68 | # We don't support gzipped or tar:ed patches or anything like |
|
0 commit comments