Example #1
0
def determineResourceType(resourceStorer, includeChildren=False):
    """ 
    Helper method to determine resource type (link, resource, collection) 
    of the given WebDAV resource (including or excluding its children).
    
    @param resourceStorer: 
    @type resourceStorer: instance of L{ResourceStorer<webdav.WebdavClient.ResourceStorer>}
    @param includeChildren: Flag indicating that the resource type of the children is determined as well.
    @type includeChildren: C{bool}
    """

    depth = 0
    if includeChildren:
        depth = 1
    body = createFindBody([LINK_TARGET_PROPERTY, RESOURCE_TYPE_PROPERTY])
    response = resourceStorer.connection.propfind(resourceStorer.path,
                                                  body,
                                                  depth=depth)
    result = dict()
    for path, properties in response.msr.items():
        isCollection = None
        linkTargetPath = None
        if RESOURCE_TYPE_PROPERTY in properties:
            isCollection = len(properties[RESOURCE_TYPE_PROPERTY].children) > 0
        if LINK_TARGET_PROPERTY in properties:
            linkTargetPath = properties[LINK_TARGET_PROPERTY].textof()
        result[path] = isCollection, linkTargetPath
    return result
Example #2
0
def determineResourceType(resourceStorer, includeChildren=False):
    """ 
    Helper method to determine resource type (link, resource, collection) 
    of the given WebDAV resource (including or excluding its children).
    
    @param resourceStorer: 
    @type resourceStorer: instance of L{ResourceStorer<webdav.WebdavClient.ResourceStorer>}
    @param includeChildren: Flag indicating that the resource type of the children is determined as well.
    @type includeChildren: C{bool}
    """
    
    depth = 0
    if includeChildren:
        depth = 1
    body = createFindBody([LINK_TARGET_PROPERTY, RESOURCE_TYPE_PROPERTY])
    response = resourceStorer.connection.propfind(resourceStorer.path, body, depth=depth)
    result = dict()
    for path, properties in response.msr.items():
        isCollection = None
        linkTargetPath = None
        if RESOURCE_TYPE_PROPERTY in properties:
            isCollection = len(properties[RESOURCE_TYPE_PROPERTY].children) > 0
        if LINK_TARGET_PROPERTY in properties:
            linkTargetPath = properties[LINK_TARGET_PROPERTY].textof()
        result[path] = isCollection, linkTargetPath
    return result
Example #3
0
 def readStandardProperties(self):
     """
     Read all WebDAV live properties.
     
     @return: A L{LiveProperties} instance which contains a getter method for each live property.
     """
     body = createFindBody(LiveProperties.NAMES, Constants.NS_DAV)
     response = self.connection.propfind(self.path, body, depth=0)
     properties = response.msr.values()[0]
     return LiveProperties(properties)
Example #4
0
    def readStandardProperties(self):
        """
        Read all WebDAV live properties.

        @return: A L{LiveProperties} instance which contains a getter method for each live property.
        """
        body = createFindBody(LiveProperties.NAMES, Constants.NS_DAV)
        response = self.connection.propfind(self.path, body, depth=0)
        properties = response.msr.values()[0]
        return LiveProperties(properties)
Example #5
0
 def findProperties(self, *names):
     """
     Retrieve given properties for this collection and all directly contained resources.
     
     @param names: a list of property names
     @return: a map from resource URI to a map from property name to value.
     """
     assert isinstance(names, types.ListType) or isinstance(names, types.TupleType), \
             "Argument name has type %s" % str(type(names))
     body = createFindBody(names, self.defaultNamespace)
     response = self.connection.propfind(self.path, body, depth=1)
     return response.msr
Example #6
0
    def findProperties(self, *names):
        """
        Retrieve given properties for this collection and all directly contained resources.

        @param names: a list of property names
        @return: a map from resource URI to a map from property name to value.
        """
        assert isinstance(names, types.ListType) or isinstance(names, types.TupleType), \
                "Argument name has type %s" % str(type(names))
        body = createFindBody(names, self.defaultNamespace)
        response = self.connection.propfind(self.path, body, depth=1)
        return response.msr
Example #7
0
 def readProperties(self, *names):
     """
     Reads the given properties.
     
     @param names: a list of property names.
                   A property name is a (XmlNameSpace, propertyName) tuple.
     @return: a map from property names to DOM Element or String values.
     """
     assert names, "Property names are missing."
     body = createFindBody(names, self.defaultNamespace)
     response = self.connection.propfind(self.path, body, depth=0)
     properties = response.msr.values()[0]
     if  properties.errorCount > 0:
         raise WebdavError("Property is missing on '%s': %s" % (self.path, properties.reason), properties.code)
     return properties
Example #8
0
 def deepFindProperties(self, *names):
     """
     Retrieve given properties for this collection and all contained (nested) resources.
     
     Note:
     =====
       This operation can take a long time if used with recursive=true and is therefore
       disabled on some WebDAV servers.
     
     @param names: a list of property names
     @return: a map from resource URI to a map from property name to value.
     """
     assert isinstance(names, types.ListType.__class__) or isinstance(names, types.TupleType), \
             "Argument name has type %s" % str(type(names))
     body = createFindBody(names, self.defaultNamespace)
     response = self.connection.propfind(self.path, body, depth=Constants.HTTP_HEADER_DEPTH_INFINITY)
     return response.msr
Example #9
0
 def readProperties(self, *names):
     """
     Reads the given properties.
     
     @param names: a list of property names.
                   A property name is a (XmlNameSpace, propertyName) tuple.
     @return: a map from property names to DOM Element or String values.
     """
     assert names, "Property names are missing."
     body = createFindBody(names, self.defaultNamespace)
     response = self.connection.propfind(self.path, body, depth=0)
     properties = response.msr.values()[0]
     if properties.errorCount > 0:
         raise WebdavError(
             "Property is missing on '%s': %s" %
             (self.path, properties.reason), properties.code)
     return properties
Example #10
0
    def deepFindProperties(self, *names):
        """
        Retrieve given properties for this collection and all contained (nested) resources.

        Note:
        =====
          This operation can take a long time if used with recursive=true and is therefore
          disabled on some WebDAV servers.

        @param names: a list of property names
        @return: a map from resource URI to a map from property name to value.
        """
        assert isinstance(names, types.ListType.__class__) or isinstance(names, types.TupleType), \
                "Argument name has type %s" % str(type(names))
        body = createFindBody(names, self.defaultNamespace)
        response = self.connection.propfind(self.path, body, depth=Constants.HTTP_HEADER_DEPTH_INFINITY)
        return response.msr
Example #11
0
 def readProperties(self, *names, **kwargs):
     """
     Reads the given properties.
     
     @param names: a list of property names.
                   A property name is a (XmlNameSpace, propertyName) tuple.
     @param ignore404: a boolean flag.
                   Indicates if an error should be raised for missing properties.
     @return: a map from property names to DOM Element or String values.
     """
     assert names, "Property names are missing."
     ignore404 = kwargs.pop('ignore404', False)
     body = createFindBody(names, self.defaultNamespace)
     response = self.connection.propfind(self.path, body, depth=0)
     properties = response.msr.values()[0]
     if  not ignore404 and properties.errorCount > 0 :
         raise WebdavError("Property is missing on '%s': %s" % (self.path, properties.reason), properties.code)
     return properties
Example #12
0
    def readProperties(self, *names, **kwargs):
        """
        Reads the given properties.

        @param names: a list of property names.
                      A property name is a (XmlNameSpace, propertyName) tuple.
        @param ignore404: a boolean flag.
                      Indicates if an error should be raised for missing properties.
        @return: a map from property names to DOM Element or String values.
        """
        assert names, "Property names are missing."
        ignore404 = kwargs.pop('ignore404', False)
        body = createFindBody(names, self.defaultNamespace)
        response = self.connection.propfind(self.path, body, depth=0)
        properties = response.msr.values()[0]
        if  not ignore404 and properties.errorCount > 0 :
            raise WebdavError("Property is missing on '%s': %s" % (self.path, properties.reason), properties.code)
        return properties