Patched http response read to deal with search providers hanging up and trashing our data

This commit is contained in:
rembo10
2012-10-24 13:26:27 -03:00
parent dd76db450f
commit 07ee4adc81
+12 -2
View File
@@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Headphones. If not, see <http://www.gnu.org/licenses/>. # along with Headphones. If not, see <http://www.gnu.org/licenses/>.
import urllib, urllib2, urlparse import urllib, urllib2, urlparse, httplib
import lib.feedparser as feedparser import lib.feedparser as feedparser
from lib.pygazelle import api as gazelleapi from lib.pygazelle import api as gazelleapi
from lib.pygazelle import encoding as gazelleencoding 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) scheme, netloc, path, qs, anchor = urlparse.urlsplit(s)
path = urllib.quote(path, '/%') path = urllib.quote(path, '/%')
qs = urllib.quote_plus(qs, ':&=') 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): def searchforalbum(albumid=None, new=False, lossless=False):