diff --git a/feedreader/__init__.py b/feedreader/__init__.py index 5866371..4f766e0 100644 --- a/feedreader/__init__.py +++ b/feedreader/__init__.py @@ -1,5 +1,5 @@ try: VERSION = __import__('pkg_resources') \ .get_distribution('sherlock').version -except Exception, e: +except (Exception): VERSION = 'unknown' \ No newline at end of file diff --git a/feedreader/feeds/rss20.py b/feedreader/feeds/rss20.py index b9dbfc5..8048b6f 100644 --- a/feedreader/feeds/rss20.py +++ b/feedreader/feeds/rss20.py @@ -22,7 +22,10 @@ def author(self): @property def description(self): - return unicode(self._xml.description).strip() + if(isinstance(self._xml.description, str)): + return self._xml.description.strip() + else: + return self._xml.description.encode('utf8').strip() def _process_links(self): # diff --git a/feedreader/parser.py b/feedreader/parser.py index b73adb7..9061e40 100644 --- a/feedreader/parser.py +++ b/feedreader/parser.py @@ -1,15 +1,15 @@ import lxml.objectify -import httplib -import urlparse +import http.client +import urllib.parse as urlparse -from utils.dates import * -from feeds import InvalidFeed +from .utils.dates import * +from .feeds import InvalidFeed __all__ = ('ParseError', 'InvalidFeed', 'from_string', 'from_url', 'from_file', 'parse_date') # TODO: change the feeds to a registration model -from feeds.atom10 import Atom10Feed -from feeds.rss20 import RSS20Feed +from .feeds.atom10 import Atom10Feed +from .feeds.rss20 import RSS20Feed feeds = (RSS20Feed, Atom10Feed) @@ -40,9 +40,9 @@ def from_file(fp, *args, **kwargs): def from_url(url, **kwargs): url = urlparse.urlparse(url) if url.scheme == 'https': - conn = httplib.HTTPSConnection + conn = http.client.HTTPSConnection elif url.scheme == 'http': - conn = httplib.HTTPConnection + conn = http.client.HTTPConnection else: raise NotImplementedError @@ -63,7 +63,7 @@ def from_url(url, **kwargs): connection.request(method, path, query, headers) try: response = connection.getresponse() - except httplib.BadStatusLine, exc: + except (http.client.BadStatusLine, exc): raise ParseError('Bad status line: %s' % (exc,)) if response.status != 200: @@ -71,4 +71,4 @@ def from_url(url, **kwargs): return from_url(response.getheader('location'), **kwargs) raise ParseError('%s %s' % (response.status, response.reason)) - return from_file(response, base_url=base_url) \ No newline at end of file + return from_file(response, base_url=base_url) diff --git a/feedreader/utils/dates.py b/feedreader/utils/dates.py index bc32b38..ea4c072 100644 --- a/feedreader/utils/dates.py +++ b/feedreader/utils/dates.py @@ -3,6 +3,8 @@ __all__ = ('parse_date',) def parse_date(date_string): - date_string = unicode(date_string) + if(not isinstance(date_string, str)): + date_string = date_string.encode('utf8') + date_string = date_string return dateutil.parser.parse(date_string) \ No newline at end of file