예제 #1
0
    def _createConnection(self):
        """ Overwrites template method for connection creation. """

        protocol = self._configuration.protocol
        hostname = self._configuration.hostname
        port = self._configuration.port
        connection = Connection(hostname, port, protocol=protocol)
        baseCollection = CollectionStorer(self._configuration.basePath,
                                          connection)
        try:
            try:
                baseCollection.validate()
            except AuthorizationError, error:
                username = self._configuration.username or ""
                password = self._configuration.password or ""
                if error.authType == "Basic":
                    realm = re.search('realm="([^"]+)"', error.authInfo)
                    if not realm is None:
                        realm = realm.group(1)
                    connection.addBasicAuthorization(username, password, realm)
                elif error.authType == "Digest":
                    authInfo = parseDigestAuthInfo(error.authInfo)
                    connection.addDigestAuthorization(username,
                                                      password,
                                                      realm=authInfo["realm"],
                                                      qop=authInfo["qop"],
                                                      nonce=authInfo["nonce"])
                else:
                    raise PersistenceError(
                        "Cannot create connection. Authentication type '%s' is not supported."
                    )
        except (AttributeError, WebdavError), error:
            errorMessage = "Cannot create connection.\nReason:'%s'" % error.reason
            raise PersistenceError(errorMessage)
예제 #2
0
    def __init__(self, url, connection=None, validateResourceNames=True):
        """
        Creates an instance for the given URL
        User must invoke validate() after construction to check the resource on the server.
        
        @param url: Unique resource location for this storer.
        @type  url: C{string}
        @param connection: this optional parameter contains a Connection object 
            for the host part of the given URL. Passing a connection saves 
            memory by sharing this connection. (defaults to None)
        @type  connection: L{webdav.Connection}
        @raise WebdavError: If validation of resource name path parts fails.
        """

        assert connection == None or isinstance(connection, Connection)
        parts = urlsplit(url, allow_fragments=False)
        self.path = parts[2]
        self.validateResourceNames = validateResourceNames

        # validate URL path
        for part in self.path.split('/'):
            if part != '' and not "ino:" in part:  # explicitly allowing this character sequence as a part of a path (Tamino 4.4)
                if self.validateResourceNames:
                    try:
                        validateResourceName(part)
                    except WrongNameError:
                        raise WebdavError("Found invalid resource name part.")
                self.name = part
        # was: filter(lambda part: part and validateResourceName(part), self.path.split('/'))
        # but filter is deprecated

        self.defaultNamespace = None  # default XML name space of properties
        if connection:
            self.connection = connection
        else:
            conn = parts[1].split(":")
            if len(conn) == 1:
                self.connection = Connection(
                    conn[0], protocol=parts[0])  # host and protocol
            else:
                self.connection = Connection(
                    conn[0], int(conn[1]),
                    protocol=parts[0])  # host and port and protocol
        self.versionHandler = VersionHandler(self.connection, self.path)