aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>2011-01-18 20:52:37 +0100
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>2011-01-18 20:52:37 +0100
commit7b531c0be61b84884302b564a9fc89edde2cfc67 (patch)
tree1d53b34a00369da69af83b3f31ab301d096101f6
parent0d14e225fa031f37c34242551565b6dadbfa51af (diff)
downloadyoutube-dl-7b531c0be61b84884302b564a9fc89edde2cfc67.tar.xz
Wrap call to addinfourl for compatibility with Python 2.4
-rwxr-xr-xyoutube-dl10
1 files changed, 8 insertions, 2 deletions
diff --git a/youtube-dl b/youtube-dl
index 8bdde1704..1b20025e7 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -189,6 +189,12 @@ class YoutubeDLHandler(urllib2.HTTPHandler):
except zlib.error:
return zlib.decompress(data)
+ @staticmethod
+ def addinfourl_wrapper(stream, headers, url, code):
+ if hasattr(urllib2.addinfourl, 'getcode'):
+ return urllib2.addinfourl(stream, headers, url, code)
+ return urllib2.addinfourl(stream, headers, url)
+
def http_request(self, req):
for h in std_headers:
if h in req.headers:
@@ -205,12 +211,12 @@ class YoutubeDLHandler(urllib2.HTTPHandler):
# gzip
if resp.headers.get('Content-encoding', '') == 'gzip':
gz = gzip.GzipFile(fileobj=StringIO.StringIO(resp.read()), mode='r')
- resp = urllib2.addinfourl(gz, old_resp.headers, old_resp.url)
+ resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
resp.msg = old_resp.msg
# deflate
if resp.headers.get('Content-encoding', '') == 'deflate':
gz = StringIO.StringIO(self.deflate(resp.read()))
- resp = urllib2.addinfourl(gz, old_resp.headers, old_resp.url)
+ resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code)
resp.msg = old_resp.msg
return resp