/breezy-svn/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy-svn/trunk

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Jelmer Vernooij
  • Date: 2020-01-31 19:40:01 UTC
  • Revision ID: jelmer@jelmer.uk-20200131194001-ri4z8wyq0cvymo20
More python3/breezy compat fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
169
169
        try:
170
170
            version = check_wc(transport.local_abspath('.').encode("utf-8"))
171
171
        except subvertpy.SubversionException as e:
172
 
            msg, num = e.args
173
 
            if num == subvertpy.ERR_WC_UPGRADE_REQUIRED:
 
172
            if e.args[1] == subvertpy.ERR_WC_UPGRADE_REQUIRED:
174
173
                raise UnsupportedFormatError(msg)
175
174
            raise
176
175
        from .workingtree import SvnWorkingTreeDirFormat
187
186
            return set([SvnWorkingTreeDirFormat()])
188
187
 
189
188
 
190
 
def dav_options(transport, url):
191
 
    # FIXME: Integrate this into HttpTransport.options().
192
 
    from breezy.transport.http import HttpTransport, Request
193
 
    if isinstance(transport, HttpTransport):
194
 
        req = Request('OPTIONS', url, accepted_errors=[200, 403, 404, 405])
195
 
        req.follow_redirections = True
196
 
        resp = transport._perform(req)
197
 
        if resp.code == 404:
198
 
            raise NoSuchFile(transport._path)
199
 
        if resp.code in (403, 405):
200
 
            raise InvalidHttpResponse(transport.base,
201
 
                "OPTIONS not supported or forbidden for remote URL")
202
 
        return resp.headers.getheaders('DAV')
203
 
    raise NotImplementedError
204
 
 
205
 
 
206
189
class SvnRemoteProber(SvnProber):
207
190
 
208
191
    _supported_schemes = ["http", "https", "file", "svn"]
251
234
        # that the remote end supports version control.
252
235
        if scheme in ("http", "https"):
253
236
            priv_transport = getattr(transport, "_decorated", transport)
254
 
            url = ConnectedTransport._unsplit_url(
255
 
                priv_transport._unqualified_scheme,
256
 
                None, None, priv_transport._host,
257
 
                priv_transport._port, priv_transport._path)
258
237
            try:
259
 
                dav_entries = dav_options(transport, url)
260
 
            except (InProcessTransport, NoSuchFile, urlutils.InvalidURL, InvalidHttpResponse):
261
 
                raise NotBranchError(path=transport.base)
262
 
            except NotImplementedError:
263
 
                pass # Custom http implementation?
 
238
                headers = priv_transport._options('.')
 
239
            except (errors.InProcessTransport, errors.NoSuchFile,
 
240
                    errors.InvalidHttpResponse):
 
241
                raise errors.NotBranchError(path=transport.base)
264
242
            else:
265
 
                import itertools
266
 
                dav_entries = list(itertools.chain(
267
 
                    *[entry.split(",") for entry in dav_entries]))
268
 
                if not "version-control" in dav_entries:
269
 
                    raise NotBranchError(path=transport.base)
 
243
                dav_entries = set()
 
244
                for key, value in headers:
 
245
                    if key.upper() == 'DAV':
 
246
                        dav_entries.update(
 
247
                            [x.strip() for x in value.split(',')])
 
248
                if "version-control" not in dav_entries:
 
249
                    raise errors.NotBranchError(path=transport.base)
270
250
 
271
251
        self._check_versions()
272
252
        from .transport import get_svn_ra_transport
275
255
        try:
276
256
            transport = get_svn_ra_transport(transport)
277
257
        except subvertpy.SubversionException as e:
278
 
            msg, num = e.args
 
258
            num = e.args[1]
279
259
            if num == subvertpy.ERR_RA_DAV_NOT_VCC:
280
260
                raise NotBranchError(path=transport.base)
281
261
            if num in (subvertpy.ERR_RA_ILLEGAL_URL,