~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http.py

  • Committer: Robert Collins
  • Date: 2005-10-17 20:38:12 UTC
  • Revision ID: robertc@robertcollins.net-20051017203812-7f01cc90974d01ca
Typo in config.py (Thanks Fabbione)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.trace import mutter
30
30
 
 
31
# velocitynet.com.au transparently proxies connections and thereby
 
32
# breaks keep-alive -- sucks!
 
33
 
31
34
 
32
35
def get_url(url):
33
36
    import urllib2
74
77
        """Return the full url to the given relative path.
75
78
        This can be supplied with a string or a list
76
79
        """
77
 
        assert isinstance(relpath, basestring)
78
80
        if isinstance(relpath, basestring):
79
 
            relpath_parts = relpath.split('/')
80
 
        else:
81
 
            # TODO: Don't call this with an array - no magic interfaces
82
 
            relpath_parts = relpath[:]
83
 
        if len(relpath_parts) > 1:
84
 
            if relpath_parts[0] == '':
85
 
                raise ValueError("path %r within branch %r seems to be absolute"
86
 
                                 % (relpath, self._path))
87
 
            if relpath_parts[-1] == '':
88
 
                raise ValueError("path %r within branch %r seems to be a directory"
89
 
                                 % (relpath, self._path))
 
81
            relpath = [relpath]
90
82
        basepath = self._path.split('/')
91
83
        if len(basepath) > 0 and basepath[-1] == '':
92
84
            basepath = basepath[:-1]
93
 
        for p in relpath_parts:
 
85
 
 
86
        for p in relpath:
94
87
            if p == '..':
95
 
                if len(basepath) == 0:
 
88
                if len(basepath) < 0:
96
89
                    # In most filesystems, a request for the parent
97
90
                    # of root, just returns root.
98
91
                    continue
99
 
                basepath.pop()
100
 
            elif p == '.' or p == '':
 
92
                if len(basepath) > 0:
 
93
                    basepath.pop()
 
94
            elif p == '.':
101
95
                continue # No-op
102
96
            else:
103
97
                basepath.append(p)
 
98
 
104
99
        # Possibly, we could use urlparse.urljoin() here, but
105
100
        # I'm concerned about when it chooses to strip the last
106
101
        # portion of the path, and when it doesn't.
126
121
            f.read()
127
122
            f.close()
128
123
            return True
129
 
        except urllib2.URLError, e:
130
 
            if e.code == 404:
131
 
                return False
132
 
            raise
 
124
        except BzrError:
 
125
            return False
 
126
        except urllib2.URLError:
 
127
            return False
133
128
        except IOError, e:
134
129
            if e.errno == errno.ENOENT:
135
130
                return False
142
137
        """
143
138
        try:
144
139
            return get_url(self.abspath(relpath))
145
 
        except urllib2.URLError, e:
146
 
            if e.code == 404:
147
 
                raise NoSuchFile(msg = "Error retrieving %s: %s" 
148
 
                                 % (self.abspath(relpath), str(e)),
149
 
                                 orig_error=e)
150
 
            raise
151
 
        except (BzrError, IOError), e:
 
140
        except (BzrError, urllib2.URLError, IOError), e:
152
141
            raise NoSuchFile(msg = "Error retrieving %s: %s" 
153
142
                             % (self.abspath(relpath), str(e)),
154
143
                             orig_error=e)
228
217
        :return: A lock object, which should be passed to Transport.unlock()
229
218
        """
230
219
        raise TransportNotPossible('http does not support lock_write()')
 
220
 
 
221
register_transport('http://', HttpTransport)
 
222
register_transport('https://', HttpTransport)