示例#1
0
class WebDAVSettings(ConnectionSettings):
    ns = "webdav:"
    prefix = "webdav_"
    keys = {
        'hostname', 'login', 'password', 'token', 'root', 'cert_path',
        'key_path', 'recv_speed', 'send_speed', 'verbose'
    }

    hostname = None
    login = None
    password = None
    token = None
    root = None
    cert_path = None
    key_path = None
    recv_speed = None
    send_speed = None
    verbose = None

    def __init__(self, options):

        self.options = dict()

        for key in self.keys:
            value = options.get(key, '')
            self.options[key] = value
            self.__dict__[key] = value

        self.root = Urn(self.root).quote() if self.root else ''
        self.root = self.root.rstrip(Urn.separate)

    def is_valid(self):

        if not self.hostname:
            raise OptionNotValid(name="hostname",
                                 value=self.hostname,
                                 ns=self.ns)

        if self.cert_path and not exists(self.cert_path):
            raise OptionNotValid(name="cert_path",
                                 value=self.cert_path,
                                 ns=self.ns)

        if self.key_path and not exists(self.key_path):
            raise OptionNotValid(name="key_path",
                                 value=self.key_path,
                                 ns=self.ns)

        if self.key_path and not self.cert_path:
            raise OptionNotValid(name="cert_path",
                                 value=self.cert_path,
                                 ns=self.ns)

        if self.password and not self.login:
            raise OptionNotValid(name="login", value=self.login, ns=self.ns)

        if not self.token and not self.login:
            raise OptionNotValid(name="login", value=self.login, ns=self.ns)
class WebDAVSettings(ConnectionSettings):
    ns = "webdav:"
    prefix = "webdav_"
    keys = {'hostname', 'login', 'password', 'token', 'root', 'cert_path', 'key_path', 'recv_speed', 'send_speed',
            'verbose', 'disable_check', 'override_methods', 'timeout', 'chunk_size'}

    def __init__(self, options):
        self.hostname = None
        self.login = None
        self.password = None
        self.token = None
        self.root = None
        self.cert_path = None
        self.key_path = None
        self.recv_speed = None
        self.send_speed = None
        self.verbose = None
        self.disable_check = False
        self.override_methods = {}
        self.timeout = 30
        self.chunk_size = 65536

        self.options = dict()

        for key in self.keys:
            value = options.get(key, '')
            if not (self.__dict__[key] and not value):
                self.options[key] = value
                self.__dict__[key] = value

        self.root = Urn(self.root).quote() if self.root else ''
        self.root = self.root.rstrip(Urn.separate)
        self.hostname = self.hostname.rstrip(Urn.separate)

    def is_valid(self):
        if not self.hostname:
            raise OptionNotValid(name="hostname", value=self.hostname, ns=self.ns)

        if self.cert_path and not exists(self.cert_path):
            raise OptionNotValid(name="cert_path", value=self.cert_path, ns=self.ns)

        if self.key_path and not exists(self.key_path):
            raise OptionNotValid(name="key_path", value=self.key_path, ns=self.ns)

        if self.key_path and not self.cert_path:
            raise OptionNotValid(name="cert_path", value=self.cert_path, ns=self.ns)

        if self.password and not self.login:
            raise OptionNotValid(name="login", value=self.login, ns=self.ns)
        return True