def resourceExists(node, name = None, resourceType = PROP_RESOURCE_TYPE_RESOURCE):
    """
    Check if resource exists.
    
    Usage:
      - resourceExists(ResourceStorer-object):
        check if resource exists
      - resourceExists(CollectionStorer-object, name):
        check if resource name exists in collection
    
    @param node: node that has to be checked or node of collection
    @type node: L{ResourceStorer<webdav.WebdavClient.ResourceStorer>}
    @param name: name of resource (in collection node) that has to be checked
    @type name: string
    
    @return: boolean
    
    @raise WebdavError: all WebDAV errors except WebDAV error 404 (not found)
    """
    
    exists = False
    if not node:
        return exists
    try:
        myResourceType = ""
        if name:
            # make sure it's unicode:
            if not isinstance(name, str):
                name = name.decode(sys.getfilesystemencoding())
            url = node.url
            if url.endswith("/"):
                url = url  + name
            else:
                url = url + "/" + name
            newNode = ResourceStorer(url, node.connection)
            element = newNode.readProperty(NS_DAV, PROP_RESOURCE_TYPE)
        else: # name is "None":
            element = node.readProperty(NS_DAV, PROP_RESOURCE_TYPE)
        
        if len(element.children) > 0:
            myResourceType = element.children[0].name
        if resourceType == myResourceType or resourceType == PROP_RESOURCE_TYPE_RESOURCE:
            exists = True
        else:
            exists = False
    except WebdavError as wderr:
        if wderr.code == CODE_NOT_FOUND:
            # node doesn't exist -> exists = False:
            exists = False
        else:
            # another exception occured -> "re-raise" it:
            raise
    return exists
Exemple #2
0
def _insertAclDisplaynames(acl):
    """
    Modifies the ACL by adding the human readable names 
    (DAV:displayname property) of each principal found in an ACL.
    
    This should be done with the REPORT method, but it is not supported by 
    Jacarta Slide, yet. (As of Aug. 1, 2003 in CVS repository)
    
    So we are going to do it differently by foot the harder way ...
    
    @param acl: An ACL object for which the displaynames should be retrieved.
    @type  acl: L{ACL} object
    """
    ## This is redundant code to be still kept for the REPORT method way of doing it ...
    ## property = '''<D:prop><D:displayname/></D:prop>'''
    ## return self.getReport(REPORT_ACL_PRINCIPAL_PROP_SET, property)
    for ace in acl.aces:
        if not ace.principal.property:
            principalConnection = ResourceStorer(ace.principal.principalURL)
            ace.principal.displayname = principalConnection.readProperty(Constants.NS_DAV, Constants.PROP_DISPLAY_NAME)