~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-12 01:42:55 UTC
  • mfrom: (6055.2.12 unparsedurl)
  • Revision ID: pqm@pqm.ubuntu.com-20110812014255-y3thbw6gdn7cw6uz
(jelmer) Add a URL object for manipulating parsed URLs. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
        user and passwords are not embedded in the path provided to the server.
150
150
        """
151
151
        relative = urlutils.unescape(relpath).encode('utf-8')
152
 
        path = self._combine_paths(self._path, relative)
 
152
        path = self._combine_paths(self._parsed_url.path, relative)
153
153
        return self._unsplit_url(self._unqualified_scheme,
154
 
                                 None, None, self._host, self._port, path)
 
154
                                 None, None, self._parsed_url.host,
 
155
                                 self._parsed_url.port, path)
155
156
 
156
157
    def _create_auth(self):
157
158
        """Returns a dict containing the credentials provided at build time."""
158
 
        auth = dict(host=self._host, port=self._port,
159
 
                    user=self._user, password=self._password,
 
159
        auth = dict(host=self._parsed_url.host, port=self._parsed_url.port,
 
160
                    user=self._parsed_url.user, password=self._parsed_url.password,
160
161
                    protocol=self._unqualified_scheme,
161
 
                    path=self._path)
 
162
                    path=self._parsed_url.path)
162
163
        return auth
163
164
 
164
165
    def get_smart_medium(self):
413
414
        # HTTP URL's are externally usable as long as they don't mention their
414
415
        # implementation qualifier
415
416
        return self._unsplit_url(self._unqualified_scheme,
416
 
                                 self._user, self._password,
417
 
                                 self._host, self._port,
418
 
                                 self._path)
 
417
                                 self._parsed_url.user, self._parsed_url.password,
 
418
                                 self._parsed_url.host, self._parsed_url.port,
 
419
                                 self._parsed_url.path)
419
420
 
420
421
    def is_readonly(self):
421
422
        """See Transport.is_readonly."""
526
527
            relying on the caller to give us a proper url (i.e. one returned by
527
528
            the server mirroring the one we sent).
528
529
            """
529
 
            (scheme,
530
 
             user, password,
531
 
             host, port,
532
 
             path) = self._split_url(abspath)
533
 
            pl = len(self._path)
534
 
            return path[pl:].strip('/')
 
530
            parsed_url = self._split_url(abspath)
 
531
            pl = len(self._parsed_url.path)
 
532
            return parsed_url.path[pl:].strip('/')
535
533
 
536
534
        relpath = relpath(source)
537
535
        if not target.endswith(relpath):
539
537
            # redirection.
540
538
            return None
541
539
        new_transport = None
542
 
        (scheme,
543
 
         user, password,
544
 
         host, port,
545
 
         path) = self._split_url(target)
 
540
        parsed_url = self._split_url(target)
546
541
        # Recalculate base path. This is needed to ensure that when the
547
542
        # redirected tranport will be used to re-try whatever request was
548
543
        # redirected, we end up with the same url
549
 
        base_path = path[:-len(relpath)]
550
 
        if scheme in ('http', 'https'):
 
544
        base_path = parsed_url.path[:-len(relpath)]
 
545
        if parsed_url.scheme in ('http', 'https'):
551
546
            # Same protocol family (i.e. http[s]), we will preserve the same
552
547
            # http client implementation when a redirection occurs from one to
553
548
            # the other (otherwise users may be surprised that bzr switches
554
549
            # from one implementation to the other, and devs may suffer
555
550
            # debugging it).
556
 
            if (scheme == self._unqualified_scheme
557
 
                and host == self._host
558
 
                and port == self._port
559
 
                and (user is None or user == self._user)):
 
551
            if (parsed_url.scheme == self._unqualified_scheme
 
552
                and parsed_url.host == self._parsed_url.host
 
553
                and parsed_url.port == self._parsed_url.port
 
554
                and (parsed_url.user is None or
 
555
                     parsed_url.user == self._parsed_url.user)):
560
556
                # If a user is specified, it should match, we don't care about
561
557
                # passwords, wrong passwords will be rejected anyway.
562
558
                new_transport = self.clone(base_path)
565
561
                # credentials (if they don't apply, the redirected to server
566
562
                # will tell us, but if they do apply, we avoid prompting the
567
563
                # user)
568
 
                redir_scheme = scheme + '+' + self._impl_name
 
564
                redir_scheme = parsed_url.scheme + '+' + self._impl_name
569
565
                new_url = self._unsplit_url(redir_scheme,
570
 
                                            self._user, self._password,
571
 
                                            host, port,
 
566
                                            self._parsed_url.user,
 
567
                                            self._parsed_url.password,
 
568
                                            parsed_url.host, parsed_url.port,
572
569
                                            base_path)
573
570
                new_transport = transport.get_transport(new_url)
574
571
        else:
575
572
            # Redirected to a different protocol
576
 
            new_url = self._unsplit_url(scheme,
577
 
                                        user, password,
578
 
                                        host, port,
 
573
            new_url = self._unsplit_url(parsed_url.scheme,
 
574
                                        parsed_url.user, parsed_url.password,
 
575
                                        parsed_url.host, parsed_url.port,
579
576
                                        base_path)
580
577
            new_transport = transport.get_transport(new_url)
581
578
        return new_transport