summaryrefslogtreecommitdiff
path: root/loader/lib/varnish.py
diff options
context:
space:
mode:
authorMagnus Hagander2019-01-03 10:04:29 +0000
committerMagnus Hagander2019-01-03 10:04:29 +0000
commitbb5775efe5f938461537e0c95c7c110875e4718b (patch)
treed6159fc5773caa5fe50c113c3790bd1bc63a7653 /loader/lib/varnish.py
parent46372add400ffa5295969aa2e4e8c468d4ada937 (diff)
Update loader scripts to use python3 syntax
Some minor cleanups as well, but mostly just the output of the 2to3 tool and some manual changes.
Diffstat (limited to 'loader/lib/varnish.py')
-rw-r--r--loader/lib/varnish.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/loader/lib/varnish.py b/loader/lib/varnish.py
index b49938b..f2a06c3 100644
--- a/loader/lib/varnish.py
+++ b/loader/lib/varnish.py
@@ -1,5 +1,4 @@
-import urllib
-import urllib2
+import requests
from lib.log import log
@@ -23,13 +22,12 @@ class VarnishPurger(object):
else:
# Purging individual thread
exprlist.append('obj.http.x-pgthread ~ :%s:' % p)
- purgedict = dict(zip(['p%s' % n for n in range(0, len(exprlist))], exprlist))
+ purgedict = dict(list(zip(['p%s' % n for n in range(0, len(exprlist))], exprlist)))
purgedict['n'] = len(exprlist)
- r = urllib2.Request(purgeurl, data=urllib.urlencode(purgedict))
- r.add_header('Content-type', 'application/x-www-form-urlencoded')
- r.add_header('Host', 'www.postgresql.org')
- r.get_method = lambda: 'POST'
- u = urllib2.urlopen(r)
- if u.getcode() != 200:
+ r = requests.post(purgeurl, data=purgedict, headers={
+ 'Content-type': 'application/x-www-form-urlencoded',
+ 'Host': 'www.postgresql.org',
+ })
+ if r.status_code != 200:
log.error("Failed to send purge request!")