Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 61845 | Differences between
and this patch

Collapse All | Expand All

(-)getbinpkg.py.beforeme (-8 / +37 lines)
Lines 111-121 Link Here
111
			  ),
111
			  ),
112
		}
112
		}
113
113
114
	port = None
115
	proxy_host = os.environ.get("http_proxy")
116
	if proxy_host:
117
		# Do not send user/password here
118
		address = baseurl
119
		#address = protocol + "://" + host + "/" + address
120
		hostport = string.split(proxy_host, ":")
121
		if len(hostport) > 2:
122
			raise ValueError, "Unable to interpret proxy:port from http_proxy."
123
		elif len(hostport) == 2:
124
			host = hostport[0]
125
			port = hostport[1]
126
		elif len(hostport) == 1:
127
			host = hostport[0]
128
		del hostport, proxy_host
129
		
114
	if not conn:
130
	if not conn:
115
		if protocol == "https":
131
		if protocol == "https":
116
			conn = httplib.HTTPSConnection(host)
132
			conn = httplib.HTTPSConnection(host, port)
117
		elif protocol == "http":
133
		elif protocol == "http":
118
			conn = httplib.HTTPConnection(host)
134
			conn = httplib.HTTPConnection(host, port)
119
		elif protocol == "ftp":
135
		elif protocol == "ftp":
120
			passive = 1
136
			passive = 1
121
			if(host[-1] == "*"):
137
			if(host[-1] == "*"):
Lines 181-187 Link Here
181
		return None,int(str(e)[:4]),str(e)
197
		return None,int(str(e)[:4]),str(e)
182
	
198
	
183
199
184
def make_http_request(conn, address, params={}, headers={}, dest=None):
200
def make_http_request(conn, address, params={}, headers={}, dest=None, method="GET"):
185
	"""(conn,address,params,headers) --- uses the conn object to request
201
	"""(conn,address,params,headers) --- uses the conn object to request
186
	the data from address, performing Location forwarding and using the
202
	the data from address, performing Location forwarding and using the
187
	optional params and headers."""
203
	optional params and headers."""
Lines 192-198 Link Here
192
		try:
208
		try:
193
			if (rc != 0):
209
			if (rc != 0):
194
				conn,ignore,ignore,ignore,ignore = create_conn(address)
210
				conn,ignore,ignore,ignore,ignore = create_conn(address)
195
			conn.request("GET", address, params, headers)
211
			conn.request(method, address, params, headers)
196
		except SystemExit, e:
212
		except SystemExit, e:
197
			raise
213
			raise
198
		except Exception, e:
214
		except Exception, e:
Lines 224-229 Link Here
224
		dest.write(response.read())
240
		dest.write(response.read())
225
		return "",0,""
241
		return "",0,""
226
242
243
	if method != "GET":
244
		return response,0,""
227
	return response.read(),0,""
245
	return response.read(),0,""
228
246
229
247
Lines 303-309 Link Here
303
321
304
	return listing
322
	return listing
305
323
306
def file_get_metadata(baseurl,conn=None, chunk_size=3000):
324
def file_get_metadata(baseurl,conn=None, chunk_size=3000, file_size=-1):
307
	"""(baseurl[,connection]) -- Takes a base url to connect to and read from.
325
	"""(baseurl[,connection]) -- Takes a base url to connect to and read from.
308
	URL should be in the for <proto>://<site>[:port]<path>
326
	URL should be in the for <proto>://<site>[:port]<path>
309
	Connection is used for persistent connection instances."""
327
	Connection is used for persistent connection instances."""
Lines 316-323 Link Here
316
	conn,protocol,address,params,headers = create_conn(baseurl, conn)
334
	conn,protocol,address,params,headers = create_conn(baseurl, conn)
317
335
318
	if protocol in ["http","https"]:
336
	if protocol in ["http","https"]:
319
		headers["Range"] = "bytes=-"+str(chunk_size)
337
		if file_size==-1:
320
		data,rc,msg = make_http_request(conn, address, params, headers)
338
			data,rc,msg = make_http_request(conn, address, params, headers, method="HEAD")
339
			if data:
340
				file_size = int(data.getheader("content-length"))
341
				del data
342
		# If it's still -1, we were unable to get file_size, fallback to old method
343
		if file_size==-1:
344
			headers["Range"] = "bytes=-"+str(chunk_size)
345
			data,rc,msg = make_http_request(conn, address, params, headers)
346
		else:
347
			headers["Range"] = "bytes="+str(file_size-chunk_size)+"-"
348
			data,rc,msg = make_http_request(conn, address, params, headers)
349
			
321
	elif protocol in ["ftp"]:
350
	elif protocol in ["ftp"]:
322
		data,rc,msg = make_ftp_request(conn, address, -chunk_size)
351
		data,rc,msg = make_ftp_request(conn, address, -chunk_size)
323
	else:
352
	else:
Lines 326-332 Link Here
326
	if data:
355
	if data:
327
		xpaksize = xpak.decodeint(data[-8:-4])
356
		xpaksize = xpak.decodeint(data[-8:-4])
328
		if (xpaksize+8) > chunk_size:
357
		if (xpaksize+8) > chunk_size:
329
			myid = file_get_metadata(baseurl, conn, (xpaksize+8))
358
			myid = file_get_metadata(baseurl, conn, (xpaksize+8), file_size)
330
			if not keepconnection:
359
			if not keepconnection:
331
				conn.close()
360
				conn.close()
332
			return myid
361
			return myid

Return to bug 61845