Keep py3.X compatibility for urllib

Change-Id: Iba10637688ada66f2e3003cd87bbba7d4db4abc7
Closes-Bug: #1280105
This commit is contained in:
Yatin Kumbhare 2016-05-30 22:45:58 +05:30
parent c2e17e7f7a
commit 2e2c83a527
2 changed files with 8 additions and 8 deletions

View File

@ -20,8 +20,8 @@ import gzip
import os import os
import re import re
import six import six
import six.moves.urllib.request as urlreq
import sys import sys
import urllib2
import yaml import yaml
@ -67,9 +67,9 @@ def process_files(file_specs, url_specs, whitelists):
logs_with_errors.append(name) logs_with_errors.append(name)
for (name, url) in url_specs: for (name, url) in url_specs:
whitelist = whitelists.get(name, []) whitelist = whitelists.get(name, [])
req = urllib2.Request(url) req = urlreq.Request(url)
req.add_header('Accept-Encoding', 'gzip') req.add_header('Accept-Encoding', 'gzip')
page = urllib2.urlopen(req) page = urlreq.urlopen(req)
buf = six.StringIO(page.read()) buf = six.StringIO(page.read())
f = gzip.GzipFile(fileobj=buf) f = gzip.GzipFile(fileobj=buf)
if scan_content(name, f.read().splitlines(), regexp, whitelist): if scan_content(name, f.read().splitlines(), regexp, whitelist):
@ -95,7 +95,7 @@ def scan_content(name, content, regexp, whitelist):
def collect_url_logs(url): def collect_url_logs(url):
page = urllib2.urlopen(url) page = urlreq.urlopen(url)
content = page.read() content = page.read()
logs = re.findall('(screen-[\w-]+\.txt\.gz)</a>', content) logs = re.findall('(screen-[\w-]+\.txt\.gz)</a>', content)
return logs return logs

View File

@ -19,8 +19,8 @@ import gzip
import pprint import pprint
import re import re
import six import six
import six.moves.urllib.request as urlreq
import sys import sys
import urllib2
pp = pprint.PrettyPrinter() pp = pprint.PrettyPrinter()
@ -65,9 +65,9 @@ class StackTrace(object):
def hunt_for_stacktrace(url): def hunt_for_stacktrace(url):
"""Return TRACE or ERROR lines out of logs.""" """Return TRACE or ERROR lines out of logs."""
req = urllib2.Request(url) req = urlreq.Request(url)
req.add_header('Accept-Encoding', 'gzip') req.add_header('Accept-Encoding', 'gzip')
page = urllib2.urlopen(req) page = urlreq.urlopen(req)
buf = six.StringIO(page.read()) buf = six.StringIO(page.read())
f = gzip.GzipFile(fileobj=buf) f = gzip.GzipFile(fileobj=buf)
content = f.read() content = f.read()
@ -105,7 +105,7 @@ def log_url(url, log):
def collect_logs(url): def collect_logs(url):
page = urllib2.urlopen(url) page = urlreq.urlopen(url)
content = page.read() content = page.read()
logs = re.findall('(screen-[\w-]+\.txt\.gz)</a>', content) logs = re.findall('(screen-[\w-]+\.txt\.gz)</a>', content)
return logs return logs