/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib2_wrappers.py

  • Committer: Robert Collins
  • Date: 2008-04-04 00:43:07 UTC
  • mfrom: (3331 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3333.
  • Revision ID: robertc@robertcollins.net-20080404004307-0whomfhm3yal2rvw
Resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
    )
65
65
 
66
66
 
 
67
class _BufferedMakefileSocket(object):
 
68
 
 
69
    def __init__(self, sock):
 
70
        self.sock = sock
 
71
 
 
72
    def makefile(self, mode='r', bufsize=-1):
 
73
        return self.sock.makefile(mode, 65536)
 
74
 
 
75
    def __getattr__(self, name):
 
76
        return getattr(self.sock, name)
 
77
 
 
78
 
67
79
# We define our own Response class to keep our httplib pipe clean
68
80
class Response(httplib.HTTPResponse):
69
81
    """Custom HTTPResponse, to avoid the need to decorate.
81
93
    # 8k chunks should be fine.
82
94
    _discarded_buf_size = 8192
83
95
 
 
96
    def __init__(self, sock, *args, **kwargs):
 
97
        # httplib creates a fileobject that doesn't do buffering, which
 
98
        # makes fp.readline() very expensive because it only reads one byte
 
99
        # at a time.  So we wrap the socket in an object that forces
 
100
        # sock.makefile to make a buffered file.
 
101
        sock = _BufferedMakefileSocket(sock)
 
102
        httplib.HTTPResponse.__init__(self, sock, *args, **kwargs)
 
103
 
84
104
    def begin(self):
85
105
        """Begin to read the response from the server.
86
106
 
534
554
            req = request
535
555
            r = response
536
556
            r.recv = r.read
537
 
            fp = socket._fileobject(r)
 
557
            fp = socket._fileobject(r, bufsize=65536)
538
558
            resp = urllib2.addinfourl(fp, r.msg, req.get_full_url())
539
559
            resp.code = r.status
540
560
            resp.msg = r.reason