aboutsummaryrefslogtreecommitdiffstats
path: root/gg_scraper.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2014-02-11 09:34:59 +0100
committerMatěj Cepl <mcepl@redhat.com>2014-02-13 02:01:54 +0100
commit23a64455b1d30b5ed71ac58cb786aeeb54f168c2 (patch)
treef736d340a7cf8e2ae69a10a851a1c7f003316a76 /gg_scraper.py
parent31152dadf548370abb25e93bbdf4359c8b155433 (diff)
downloadgg_scraper-23a64455b1d30b5ed71ac58cb786aeeb54f168c2.tar.gz
Fix setup.py.RunTests.run() to return proper exit code.
The previous situation didn't fail on Travis-CI. But this does, so I had to include also a number of fixes for revealed issues. Fixing #314, #315, #316, and #317
Diffstat (limited to 'gg_scraper.py')
-rwxr-xr-xgg_scraper.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/gg_scraper.py b/gg_scraper.py
index 563229f..cb6bc4e 100755
--- a/gg_scraper.py
+++ b/gg_scraper.py
@@ -54,12 +54,11 @@ MANGLED_ADDR_RE = re.compile(
r'([a-zA-Z0-9_.+-]+\.\.\.@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)',
re.IGNORECASE)
-__version__ = '0.6'
+__version__ = '0.7'
-if sys.version_info[:2] < (2, 7):
- py26 = True
-else:
- py26 = False
+pyver = sys.version_info
+py26 = pyver[:2] < (2, 7)
+py3k = pyver[0] == 3
class Page(object):
@@ -112,15 +111,19 @@ class Article(Page):
result = None
try:
res = self.opener.open(self.root)
- if not py26:
+ if not py3k:
raw_msg = res.read().decode('utf8')
else:
raw_msg = res.read()
proc = subprocess.Popen(['/usr/bin/formail'],
stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- universal_newlines=True)
+ stdout=subprocess.PIPE)
+ #universal_newlines=True)
+ if not(py3k and isinstance(raw_msg, bytes)):
+ raw_msg = raw_msg.encode('utf8')
result = proc.communicate(raw_msg)[0]
+ if not py3k:
+ result = result.decode('utf8')
res.close()
except HTTPError as exc:
logging.warning('Exception on downloading {0}:\n{1}'.format(
@@ -298,7 +301,7 @@ class MBOX(mailbox.mbox):
else:
self.add(mbx_str.encode('utf8'))
except UnicodeDecodeError:
- logging.debug('mbx_str = type {0}'.format(type(mbx_str)))
+ logging.warning('mbx_str = type {0}'.format(type(mbx_str)))
self.unlock()
self.close()