66from django .contrib .auth .models import User
77from django .db import transaction
88
9- import httplib
10- import socket
11- import urllib
9+ import requests
1210import json
1311
1412from pgcommitfest .auth import user_search
@@ -24,36 +22,26 @@ class Http503(Exception):
2422
2523def _archivesAPI (suburl , params = None ):
2624 try :
27- socket .setdefaulttimeout (settings .ARCHIVES_TIMEOUT )
28- if settings .ARCHIVES_PORT != 443 :
29- h = httplib .HTTPConnection (host = settings .ARCHIVES_SERVER ,
30- port = settings .ARCHIVES_PORT ,
31- strict = True ,
32- timeout = settings .ARCHIVES_TIMEOUT )
33- else :
34- h = httplib .HTTPSConnection (host = settings .ARCHIVES_SERVER ,
35- port = settings .ARCHIVES_PORT ,
36- strict = True ,
37- timeout = settings .ARCHIVES_TIMEOUT )
38- if params :
39- url = "%s?%s" % (suburl , urllib .urlencode (params ))
40- else :
41- url = suburl
42- h .request ('GET' , url , headers = {
43- 'Host' : settings .ARCHIVES_HOST ,
44- })
45- resp = h .getresponse ()
46- if resp .status != 200 :
47- if resp .status == 404 :
25+ resp = requests .get ("http{0}://{1}:{2}{3}" .format (settings .ARCHIVES_PORT == 443 and 's' or '' ,
26+ settings .ARCHIVES_SERVER ,
27+ settings .ARCHIVES_PORT ,
28+ suburl ),
29+ params = params ,
30+ headers = {
31+ 'Host' : settings .ARCHIVES_HOST ,
32+ },
33+ timeout = settings .ARCHIVES_TIMEOUT ,
34+ )
35+ if resp .status_code != 200 :
36+ if resp .status_code == 404 :
4837 raise Http404 ()
49- raise Exception ("JSON call failed: %s" % resp .status )
38+ raise Exception ("JSON call failed: %s" % resp .status_code )
5039
51- r = json . load ( resp )
52- resp . close ()
53- h . close ()
54- except socket . error , e :
40+ return resp . json ( )
41+ except Http404 :
42+ raise
43+ except Exception as e :
5544 raise Http503 ("Failed to communicate with archives backend: %s" % e )
56- return r
5745
5846def getThreads (request ):
5947 search = request .GET .has_key ('s' ) and request .GET ['s' ] or None
0 commit comments