Example #1
0
    def setUp(self):
        # Create client
        self._client = aioeasywebdav.connect(
            host="localhost", port=SERVER_PORT, username=SERVER_USERNAME, password=SERVER_PASSWORD
        )

        self.client = ClientProxy(self, self._client)
        self.client.cd("/")
Example #2
0
    def webdavc(self):
        newloop = False
        if not hasattr(self, "loop"):
            try:
                self.loop = asyncio.get_event_loop()
                if self.loop.is_running():
                    raise NotImplementedError("Cannot use aioutils in "
                                              "asynchroneous environment")
            except:
                newloop = True
                self.loop = asyncio.new_event_loop()
                asyncio.set_event_loop(self.loop)

            self.loop = asyncio.new_event_loop()
            asyncio.set_event_loop(self.loop)

        if (not hasattr(self, "conn")
                or (hasattr(self, "conn")
                    and not isinstance(self.conn, aioeasywebdav.Client))):
            # if args have been provided to remote(), use them over those given to RemoteProvider()
            args_to_use = self.provider.args
            if len(self.args):
                args_to_use = self.args

            # use kwargs passed in to remote() to override those given to the RemoteProvider()
            # default to the host and port given as part of the file, falling back to one specified
            # as a kwarg to remote() or the RemoteProvider (overriding the latter with the former if both)
            kwargs_to_use = {}
            kwargs_to_use["host"] = self.host
            kwargs_to_use["protocol"] = self.protocol
            kwargs_to_use["port"] = int(
                self.port) if self.port != None else 443
            for k, v in self.provider.kwargs.items():
                kwargs_to_use[k] = v
            for k, v in self.kwargs.items():
                kwargs_to_use[k] = v

            # easywebdav wants the protocol without "://"
            kwargs_to_use["protocol"] = kwargs_to_use["protocol"].replace(
                "://", "")

            # monkey patch aioeasywebdav to noop _rate_calc()
            # since we don't care about download progress and
            # the parent (connection) object may be removed before the
            # sleep coroutine has a chance to be scheduled/finish,
            # and aioeasywebdav only calls close() on __del__()
            async def noop(_):
                pass

            aioeasywebdav.Client._rate_calc = noop

            self.conn = aioeasywebdav.connect(*args_to_use, **kwargs_to_use)
        yield
Example #3
0
    def __init__(self, url, username, password, webdav_basedir, tmp_dir):
        self.logger = logging.getLogger(__name__)
        self.logger.info("Connecting to WebDAV server %s", url)

        self.loop = asyncio.get_event_loop()
        self.webdav_basedir = webdav_basedir
        self.tmp_dir = tmp_dir
        try:
            self.webdav = aioeasywebdav.connect(
                url,
                username=username,
                password=password,
            )
        except:
            self.logger.error("WebDAV connection failed - exiting")

        self.logger.info("WebDAV connection successfull")