~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ross Lagerwall
  • Date: 2012-08-07 06:32:51 UTC
  • mto: (6437.63.5 2.5)
  • mto: This revision was merged to the branch mainline in revision 6558.
  • Revision ID: rosslagerwall@gmail.com-20120807063251-x9p03ghg2ws8oqjc
Add bzrlib/locale to .bzrignore

bzrlib/locale is generated with ./setup.py build_mo which is in turn called
by ./setup.py build

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from __future__ import absolute_import
23
23
 
24
 
import os
 
24
from cStringIO import StringIO
25
25
import re
26
26
import urlparse
27
27
import sys
40
40
    ConnectedTransport,
41
41
    )
42
42
 
 
43
# TODO: This is not used anymore by HttpTransport_urllib
 
44
# (extracting the auth info and prompting the user for a password
 
45
# have been split), only the tests still use it. It should be
 
46
# deleted and the tests rewritten ASAP to stay in sync.
 
47
def extract_auth(url, password_manager):
 
48
    """Extract auth parameters from am HTTP/HTTPS url and add them to the given
 
49
    password manager.  Return the url, minus those auth parameters (which
 
50
    confuse urllib2).
 
51
    """
 
52
    if not re.match(r'^(https?)(\+\w+)?://', url):
 
53
        raise ValueError(
 
54
            'invalid absolute url %r' % (url,))
 
55
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
 
56
 
 
57
    if '@' in netloc:
 
58
        auth, netloc = netloc.split('@', 1)
 
59
        if ':' in auth:
 
60
            username, password = auth.split(':', 1)
 
61
        else:
 
62
            username, password = auth, None
 
63
        if ':' in netloc:
 
64
            host = netloc.split(':', 1)[0]
 
65
        else:
 
66
            host = netloc
 
67
        username = urlutils.unquote(username)
 
68
        if password is not None:
 
69
            password = urlutils.unquote(password)
 
70
        else:
 
71
            password = ui.ui_factory.get_password(
 
72
                prompt=u'HTTP %(user)s@%(host)s password',
 
73
                user=username, host=host)
 
74
        password_manager.add_password(None, host, username, password)
 
75
    url = urlparse.urlunsplit((scheme, netloc, path, query, fragment))
 
76
    return url
 
77
 
43
78
 
44
79
class HttpTransportBase(ConnectedTransport):
45
80
    """Base class for http implementations.
84
119
        :param relpath: The relative path to the file
85
120
        """
86
121
        code, response_file = self._get(relpath, None)
87
 
        return response_file
 
122
        # FIXME: some callers want an iterable... One step forward, three steps
 
123
        # backwards :-/ And not only an iterable, but an iterable that can be
 
124
        # seeked backwards, so we will never be able to do that.  One such
 
125
        # known client is bzrlib.bundle.serializer.v4.get_bundle_reader. At the
 
126
        # time of this writing it's even the only known client -- vila20071203
 
127
        return StringIO(response_file.read())
88
128
 
89
129
    def _get(self, relpath, ranges, tail_amount=0):
90
130
        """Get a file, or part of a file.
202
242
                    # Split the received chunk
203
243
                    for offset, size in cur_coal.ranges:
204
244
                        start = cur_coal.start + offset
205
 
                        rfile.seek(start, os.SEEK_SET)
 
245
                        rfile.seek(start, 0)
206
246
                        data = rfile.read(size)
207
247
                        data_len = len(data)
208
248
                        if data_len != size: