Skip to content

Commit

Permalink
Merge pull request #14 from pculture/hotfix/http_errors
Browse files Browse the repository at this point in the history
Hotfix/http errors
  • Loading branch information
paulswartz committed May 27, 2012
2 parents b874c01 + a184f28 commit 5ed3fcc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = '0.5.1'
version = '0.5.2'
# The full version, including alpha/beta/rc tags.
release = '0.5.1'
release = '0.5.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

version = '0.5.1'
version = '0.5.2'

setup(
name="vidscraper",
Expand Down
2 changes: 1 addition & 1 deletion vidscraper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from vidscraper.suites import Video, registry, VideoSearch, VideoFeed


__version__ = '0.5.1'
__version__ = '0.5.2'


def handles_video_url(url):
Expand Down
14 changes: 11 additions & 3 deletions vidscraper/suites/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def __init__(self, url, suite=None, fields=None, api_keys=None):
# from a feed or a search.
self._loaded = False

# This private attribute is filled with any errors that show up during
# data loading. The keys will be the methods, and the values will be
# the exceptions.
self._errors = {}

@property
def missing_fields(self):
"""
Expand Down Expand Up @@ -753,9 +758,12 @@ def _run_methods(self, video, methods):
try:
response_text = urllib2.urlopen(url, timeout=5).read()
except Exception, exc:
# if an exception is raised in this method, it isn't caught and
# shows up to the user
data = getattr(self, 'parse_%s_error' % method)(exc)
# If an error is raised, pass it on to the suite for handling.
# If it gets reraised, store it and go on to the next method.
try:
data = getattr(self, 'parse_%s_error' % method)(exc)
except Exception, exc:
video._errors[method] = exc
else:
data = getattr(self, "parse_%s_response" % method)(response_text)
self.apply_video_data(video, data)
Expand Down
3 changes: 2 additions & 1 deletion vidscraper/tests/functional/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ def test_auto_feed(self):
self.assertEqual(
feed.thumbnail_url,
'http://www.youtube.com/img/pic_youtubelogo_123x63.gif')
self.assertTrue('AssociatedPress' in feed.webpage)
# YouTube changes this sometimes, so just make sure it's there
self.assertTrue(feed.webpage)
self.assertTrue(feed.entry_count > 50000)
4 changes: 2 additions & 2 deletions vidscraper/tests/functional/test_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ def test_feed(self):
'url': u'http://gdata.youtube.com/feeds/base/users/AssociatedPress/uploads?alt=rss&v=2',
'title': u'Uploads by AssociatedPress',
'description': u'',
'webpage': u'http://www.youtube.com/user/AssociatedPress/videos',
'thumbnail_url': u'http://www.youtube.com/img/pic_youtubelogo_123x63.gif',
'guid': u'tag:youtube.com,2008:user:AssociatedPress:uploads',
}
for key, value in expected.items():
self.assertEqual(value, getattr(feed, key), '%s: %r != %r' % (
key, value, getattr(feed, key)))

# YouTube changes this sometimes, so just make sure it's there
self.assertTrue(feed.webpage)
self.assertTrue(feed.entry_count > 55000, feed.entry_count)

def test_feed_18790(self):
Expand Down

0 comments on commit 5ed3fcc

Please sign in to comment.