Esempio n. 1
0
def dav_options(transport, url):
    # FIXME: Integrate this into HttpTransport.options().
    from breezy.transport.http import HttpTransport, Request
    if isinstance(transport, HttpTransport):
        req = Request('OPTIONS', url, accepted_errors=[200, 403, 404, 405])
        req.follow_redirections = True
        resp = transport._perform(req)
        if resp.code == 404:
            raise NoSuchFile(transport._path)
        if resp.code in (403, 405):
            raise InvalidHttpResponse(
                transport.base,
                "OPTIONS not supported or forbidden for remote URL")
        return resp.headers.getheaders('DAV')
    else:
        try:
            from breezy.transport.http._pycurl import PyCurlTransport
        except DependencyNotPresent:
            pass
        else:
            import pycurl
            from cStringIO import StringIO
            if isinstance(transport, PyCurlTransport):
                conn = transport._get_curl()
                try:
                    conn.setopt(pycurl.URL, url)
                    conn.setopt(pycurl.FOLLOWLOCATION, 0)
                    transport._set_curl_options(conn)
                    conn.setopt(pycurl.CUSTOMREQUEST, 'OPTIONS')
                    header = StringIO()
                    data = StringIO()
                    conn.setopt(pycurl.HEADERFUNCTION, header.write)
                    conn.setopt(pycurl.WRITEFUNCTION, data.write)
                    transport._curl_perform(conn, header)
                    code = conn.getinfo(pycurl.HTTP_CODE)
                    if code == 404:
                        raise NoSuchFile(transport._path)
                    if code in (403, 405):
                        raise InvalidHttpResponse(
                            transport.base,
                            "OPTIONS not supported or forbidden for remote URL"
                        )
                    if code == 200:
                        headers = transport._parse_headers(header)
                        return headers.getheaders('DAV')
                    raise InvalidHttpResponse(
                        transport.base, "Invalid HTTP response: %d" % code)
                finally:
                    conn.unsetopt(pycurl.CUSTOMREQUEST)
    raise NotImplementedError
Esempio n. 2
0
def Connection(url, auth=None, config=None, readonly=False):
    progress_cb = SubversionProgressReporter(url).update
    try:
        ret = RemoteAccess(
            _url_escape_uri(url),
            auth=auth,
            client_string_func=breezy.plugins.svn.get_client_string,
            progress_cb=progress_cb,
            config=config)
        if 'transport' in debug.debug_flags:
            ret = MutteringRemoteAccess(ret)
        if readonly:
            ret = ReadonlyRemoteAccess(ret)
    except subvertpy.SubversionException as e:
        msg, num = e.args
        if num in (subvertpy.ERR_RA_SVN_REPOS_NOT_FOUND, ):
            raise NoSvnRepositoryPresent(url=url)
        if num == subvertpy.ERR_BAD_URL:
            raise urlutils.InvalidURL(url)
        if num in (subvertpy.ERR_RA_DAV_PATH_NOT_FOUND,
                   subvertpy.ERR_FS_NOT_FOUND):
            raise NoSuchFile(url)
        if num == subvertpy.ERR_RA_ILLEGAL_URL:
            raise urlutils.InvalidURL(url, msg)
        if num == subvertpy.ERR_RA_DAV_RELOCATED:
            raise convert_relocate_error(url, num, msg)
        raise convert_error(e)
    from . import lazy_check_versions
    lazy_check_versions()
    return ret
Esempio n. 3
0
 def list_dir(self, relpath):
     assert len(relpath) == 0 or relpath[0] != "/"
     try:
         (dirents, _, _) = self.get_dir(relpath, self.get_latest_revnum())
     except subvertpy.SubversionException as e:
         msg, num = e.args
         if num == ERR_FS_NOT_DIRECTORY:
             raise NoSuchFile(relpath)
         raise
     return dirents.keys()
Esempio n. 4
0
 def mkdir(self, relpath, mode=None, message=u"Creating directory"):
     relpath = urlutils.join(self.repos_path, relpath)
     dirname, basename = urlutils.split(relpath)
     conn = self.get_connection(dirname.strip("/"))
     try:
         with conn.get_commit_editor({"svn:log": message}) as ce:
             try:
                 with ce.open_root(-1) as node:
                     node.add_directory(relpath, None, -1).close()
             except subvertpy.SubversionException as e:
                 msg, num = e.args
                 if num == ERR_FS_NOT_FOUND:
                     raise NoSuchFile(msg)
                 if num == ERR_FS_NOT_DIRECTORY:
                     raise NoSuchFile(msg)
                 if num == subvertpy.ERR_FS_ALREADY_EXISTS:
                     raise FileExists(msg)
                 raise
     finally:
         self.add_connection(conn)
Esempio n. 5
0
 def get(self, relpath):
     """See Transport.get()."""
     # TODO: Raise TransportNotPossible here instead and
     # catch it in bzrdir.py
     raise NoSuchFile(path=relpath)