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
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
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)
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)
def _connect(self): if self._webdavURL[-4:] == '.ics': self.connection = ResourceStorer(self._webdavURL, validateResourceNames=False) else: self.connection = CollectionStorer(self._webdavURL, validateResourceNames=False) if self._username and self._password: self.connection.connection.addBasicAuthorization( self._username, self._password) self.connection.connection.logger.setLevel(logging.WARNING)
def createResourceStorer(persistenceIdentifier, connection, validate=False): """ Creates a C{ResourceStorer} object to manage a WebDAV resource. @param persistenceIdentifier: URL identifying the collection. @type persistenceIdentifier: C{unicode} @param connection: Connection used to perform WebDAV server requests. @type connection: L{Connection<webdav.Connection.Connection>} @param validate: Flag indicating automatic existence validation. Default is C{False}. @type validate: C{bool} @return: Object representing the WebDAV resource. @rtype: instance of L{ResourceStorer<webdav.WebdavClient.ResourceStorer>} @raise PersistenceError - Indicating problems with WebDAV connection. """ webdavStorer = ResourceStorer(persistenceIdentifier, connection) if validate: _checkWebdavConnection(webdavStorer) return webdavStorer
def getMembers(self): print "Get members" items = self.resource.findProperties((NS_DAV, PROP_RESOURCE_TYPE)) for item in items.keys(): self.storers.append(ResourceStorer(item, Buri.connection)) print "Path ", item