Răsfoiți Sursa

Wrap call to addinfourl for compatibility with Python 2.4

Ricardo Garcia 14 ani în urmă
părinte
comite
7b531c0be6
1 a modificat fișierele cu 8 adăugiri și 2 ștergeri
  1. 8 2
      youtube-dl

+ 8 - 2
youtube-dl

@@ -189,6 +189,12 @@ class YoutubeDLHandler(urllib2.HTTPHandler):
 		except zlib.error:
 		except zlib.error:
 			return zlib.decompress(data)
 			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):
 	def http_request(self, req):
 		for h in std_headers:
 		for h in std_headers:
 			if h in req.headers:
 			if h in req.headers:
@@ -205,12 +211,12 @@ class YoutubeDLHandler(urllib2.HTTPHandler):
 		# gzip
 		# gzip
 		if resp.headers.get('Content-encoding', '') == 'gzip':
 		if resp.headers.get('Content-encoding', '') == 'gzip':
 			gz = gzip.GzipFile(fileobj=StringIO.StringIO(resp.read()), mode='r')
 			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
 			resp.msg = old_resp.msg
 		# deflate
 		# deflate
 		if resp.headers.get('Content-encoding', '') == 'deflate':
 		if resp.headers.get('Content-encoding', '') == 'deflate':
 			gz = StringIO.StringIO(self.deflate(resp.read()))
 			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
 			resp.msg = old_resp.msg
 		return resp
 		return resp