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.
77
72
import socket, string, time, sys
79
74
import mimetools, urlparse, urllib
82
logging.basicConfig(level=logging.DEBUG,
83
format='%(asctime)s %(levelname)s %(message)s',
84
filename='/tmp/http_client.log',
87
77
logger = logging.getLogger('bzr.http_client')
88
78
debug = logger.debug
145
135
def _make_channel(self):
146
136
# proxy2 203.17.154.69
147
# return HttpChannel('82.211.81.161', 80, self) # bazaar-ng.org
138
return HttpChannel('82.211.81.161', 80, self)
148
139
# return HttpChannel('203.17.154.69', 8080, self)
149
return HttpChannel('127.0.0.1', 8000, self) # forwarded
140
# return HttpChannel('localhost', 8000, self)
152
143
def _wake_up_channel(self):
397
debug('pass back %d bytes of %s' % (len(got_data),
398
self.sent_requests[0][0]))
406
401
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))
414
403
if self.content_remaining == 0:
415
404
del self.sent_requests[0]
417
debug('content complete')
418
consumer.content_complete()
420
406
# reset lots of things and try to get the next response header
421
407
if self.response.connection_reply == 'close':
422
408
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',
475
431
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)
476
449
logging.basicConfig(level=logging.DEBUG)
478
451
mgr = DownloadManager()
480
453
from bzrlib.branch import Branch
481
from bzrlib.progress import ProgressBar
484
454
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))
497
458
# for url in ['http://www.bazaar-ng.org/',
498
459
# 'http://www.bazaar-ng.org/tutorial.html',
499
460
# 'http://www.bazaar-ng.org/download.html',
500
461
# '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))