~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

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