From 07ee4adc812655fea6e90deaa86ef53c6010cdbb Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 24 Oct 2012 13:26:27 -0300 Subject: [PATCH] Patched http response read to deal with search providers hanging up and trashing our data --- headphones/searcher.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index 22737fe1..1bf0eb74 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . -import urllib, urllib2, urlparse +import urllib, urllib2, urlparse, httplib import lib.feedparser as feedparser from lib.pygazelle import api as gazelleapi from lib.pygazelle import encoding as gazelleencoding @@ -84,7 +84,17 @@ def url_fix(s, charset='utf-8'): scheme, netloc, path, qs, anchor = urlparse.urlsplit(s) path = urllib.quote(path, '/%') qs = urllib.quote_plus(qs, ':&=') - return urlparse.urlunsplit((scheme, netloc, path, qs, anchor)) + return urlparse.urlunsplit((scheme, netloc, path, qs, anchor)) + +def patch_http_response_read(func): + def inner(*args): + try: + return func(*args) + except httplib.IncompleteRead, e: + return e.partial + + return inner +httplib.HTTPResponse.read = patch_http_response_read(httplib.HTTPResponse.read) def searchforalbum(albumid=None, new=False, lossless=False):