68
68
# The content is written into temporary files. It returns a list of
69
69
# readable file objects.
71
# TODO: If we try pipelined or keepalive and the connection drop out
72
# then retry the request on a new connection; eventually we should perhaps
73
# learn that a given host or network just won't allow keepalive.
72
77
import socket, string, time, sys
74
79
import mimetools, urlparse, urllib
82
logging.basicConfig(level=logging.DEBUG,
83
format='%(asctime)s %(levelname)s %(message)s',
84
filename='/tmp/http_client.log',
77
87
logger = logging.getLogger('bzr.http_client')
78
88
debug = logger.debug
135
145
def _make_channel(self):
136
146
# proxy2 203.17.154.69
138
return HttpChannel('82.211.81.161', 80, self)
147
# return HttpChannel('82.211.81.161', 80, self) # bazaar-ng.org
139
148
# return HttpChannel('203.17.154.69', 8080, self)
140
# return HttpChannel('localhost', 8000, self)
149
return HttpChannel('127.0.0.1', 8000, self) # forwarded
143
152
def _wake_up_channel(self):
226
235
debug("can't handle response status %r" % r.status)
227
236
raise NotImplementedError()
229
if r.content_length == None:
238
if r.content_length is None:
230
239
raise NotImplementedError()
232
241
if r.content_length == 0:
397
debug('pass back %d bytes of %s' % (len(got_data),
398
self.sent_requests[0][0]))
406
self.content_remaining -= len(got_data)
408
debug('pass back %d bytes of %s, %d remain'
410
self.sent_requests[0][0],
411
self.content_remaining))
399
412
consumer.feed(data)
401
self.content_remaining -= len(got_data)
403
414
if self.content_remaining == 0:
404
415
del self.sent_requests[0]
417
debug('content complete')
418
consumer.content_complete()
406
420
# reset lots of things and try to get the next response header
407
421
if self.response.connection_reply == 'close':
408
422
debug('server requested close')
445
def __init__(self, url, pb):
450
def feed(self, data):
451
# print "feed", repr(data)
452
# print "feed", repr(data[:20]), repr(data[-20:]), len(data)
454
base = self.url[self.url.rindex('/')+1:]
455
self.outf = file('/tmp/download/' + base, 'wb')
456
self.outf.write(data)
458
def error(self, err_info):
460
error('error reported to consumer')
461
traceback.print_exception(err_info[0], err_info[1], err_info[2])
464
def content_complete(self):
465
info('content complete from %s' % self.url)
468
# using last_cnt is cheating
469
self._pb.update('downloading inventory',
431
475
if __name__ == "__main__":
432
class dummy_consumer:
433
def __init__(self, url):
436
def feed(self, data):
437
# print "feed", repr(data)
438
# print "feed", repr(data[:20]), repr(data[-20:]), len(data)
441
def error(self, err_info):
443
traceback.print_exception(err_info[0], err_info[1], err_info[2])
445
def content_complete(self):
446
debug('content complete from %s' % self.url)
449
476
logging.basicConfig(level=logging.DEBUG)
451
478
mgr = DownloadManager()
453
480
from bzrlib.branch import Branch
481
from bzrlib.progress import ProgressBar
454
484
revs = Branch('/home/mbp/work/bzr').revision_history()
485
pb.update('downloading inventories', 0, len(revs))
488
url = 'http://www.bazaar-ng.org/bzr/bzr.dev/.bzr/inventory-store/' \
490
mgr.enqueue(url, DummyConsumer(url, pb))
458
497
# for url in ['http://www.bazaar-ng.org/',
459
498
# 'http://www.bazaar-ng.org/tutorial.html',
460
499
# 'http://www.bazaar-ng.org/download.html',
461
500
# 'http://www.bazaar-ng.org/bzr/bzr.dev/.bzr/revision-store/mbp@hope-20050415013653-3b3c9c3d33fae0a6.gz',
465
# url = 'http://www.bazaar-ng.org/bzr/bzr.dev/.bzr/revision-store/' \
466
url = 'http://www.bazaar-ng.org/bzr/bzr.dev/.bzr/inventory-store/' \
468
mgr.enqueue(url, dummy_consumer(url))