Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion feedreader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
try:
VERSION = __import__('pkg_resources') \
.get_distribution('sherlock').version
except Exception, e:
except (Exception):
VERSION = 'unknown'
5 changes: 4 additions & 1 deletion feedreader/feeds/rss20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
# <media:thumbnail url="http://th04.deviantart.net/fs48/300W/f/2009/207/d/7/d7400f45d945d29fa1edba98531bc887.jpg" height="399" width="300"/>
Expand Down
20 changes: 10 additions & 10 deletions feedreader/parser.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -63,12 +63,12 @@ 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:
if response.status in (301, 302):
return from_url(response.getheader('location'), **kwargs)
raise ParseError('%s %s' % (response.status, response.reason))

return from_file(response, base_url=base_url)
return from_file(response, base_url=base_url)
4 changes: 3 additions & 1 deletion feedreader/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)