text: import webdav3.client
  import tempfile
  
  from . import BaseBackend, BaseFile
  
  
  class WebDavFile(BaseFile):
      def __init__(self, backend, path, mode):
          self.backend = backend
          self.path = path
          self.mode = mode
  
          self.fp = tempfile.TemporaryFile(mode='w+b')
  
          if 'r' in mode or '+' in mode:
              client = self.backend.get_client()
              client.download_from(self.fp, self.path)
  
          self.fp.seek(0)
  
          self.writeback = False
  
      def close(self):
          if self.writeback:
              self.fp.seek(0)
  
              client = self.backend.get_client()
              client.upload_to(self.fp, self.path)
  
          self.fp.close()
  
      @classmethod
      def open(cls, backend, path, mode):
          return cls(backend, path, mode)
  
      def read(self, size=-1):
          data = self.fp.read(size)
          if 'b' not in self.mode:
              data = data.decode('utf-8')
          return data
  
      def seek(self, offset, whence=0):
          return self.fp.seek(offset, whence=whence)
  
      def tell(self):
          return self.fp.tell()
  
      def write(self, data):
          self.writeback = True
          if 'b' not in self.mode:
              data = data.encode('utf-8')
          return self.fp.write(data)
  
  
  class WebDavBackend(BaseBackend):
      readable = True
      writeable = True
      seekable = True
  
      def __init__(self, url, username, password, root=None):
          self.url = url
          self.username = username
          self.password = password
          self.root = root
  
      def get_client(self):
          options = dict(webdav_hostname=self.url, webdav_login=self.username, webdav_password=self.password, root=self.root)
          return webdav3.client.Client(options)
  
      def open(self, path, mode):
          return WebDavFile(self, path, mode)
  