def testIsValidPathWithLongPath(self): """ L{isValidPath} returns C{False} if the specified path is longer than 233 characters. """ path = 'root/' + ('x' * 229) self.assertFalse(isValidPath(path))
def testIsValidPathWithLongPath(self): """ L{isValidPath} returns C{False} if the specified path is longer than 233 characters. """ path = 'root/' + ('x' * 229) self.assertFalse(isValidPath(path))
def _getField(self, path, value, raw): """Get a Solr dynamic field name and value for a given path and value. The dynamic field name is generated using the path and a suffix according to the value type. @param path: The C{unicode} path of the tag value. @param value: The value of the tag value. @param raw: A C{bool} indicating whether the document value should be raw or full text search for fields that use one. @return: A C{(fieldName, fieldValue)} 2-tuple. """ if not isValidPath(path): raise ValueError('Path is not valid.') elif value is None: suffix = '_tag_null' value = False elif isinstance(value, bool): suffix = '_tag_bool' elif isinstance(value, (int, long, float)): suffix = '_tag_number' elif isinstance(value, basestring): suffix = '_tag_raw_str' if raw else '_tag_fts' elif isinstance(value, list): suffix = '_tag_set_str' if raw else '_tag_fts' elif isinstance(value, dict): suffix = '_tag_binary' value = value['file-id'] else: raise TypeError("Unrecognized type: %s" % type(value)) return (path + suffix), value
def checkValidPath(self, object): """Check that a given object has a correct path. @param object: A L{Tag}, L{Namespace} to check. """ if not isValidPath(object.path): self._log(object, u'Invalid path.')
def checkValidPath(self, object): """Check that a given object has a correct path. @param object: A L{Tag}, L{Namespace} to check. """ if not isValidPath(object.path): self._log(object, u'Invalid path.')
def testIsValidPathWithUnnacceptableCharacter(self): """ L{isValidPath} returns C{False} if the specified path contains unnacceptable characters. """ invalidCharacters = u'!@#$%^&*()+={}[]\;"\'?<>\\, ' for character in invalidCharacters: self.assertFalse(isValidPath(character))
def testIsValidPathWithUnnacceptableCharacter(self): """ L{isValidPath} returns C{False} if the specified path contains unnacceptable characters. """ invalidCharacters = u'!@#$%^&*()+={}[]\;"\'?<>\\, ' for character in invalidCharacters: self.assertFalse(isValidPath(character))
def testIsValidPath(self): """ L{isValidPath} returns C{True} if the specified path is not empty and is made up of upper and lower case alphanumeric characters, colon, dash, dot or underscore. """ validCharacters = letters + digits + ':-._' for character in validCharacters: self.assertTrue(isValidPath(unicode(character)))
def testIsValidPath(self): """ L{isValidPath} returns C{True} if the specified path is not empty and is made up of upper and lower case alphanumeric characters, colon, dash, dot or underscore. """ validCharacters = letters + digits + ':-._' for character in validCharacters: self.assertTrue(isValidPath(unicode(character)))
def _validateAdditionalTags(additionalTags): """Validate a list of tag paths and raise a JSONRPCError if any are invalid. """ if additionalTags is not None: for path in additionalTags: if not isinstance(path, unicode): raise JSONRPCError( "Non-unicode element found in additionalTags.") if not isValidPath(path): raise JSONRPCError( "%r is not a valid path for additionalTags." % path)
def _validateAdditionalTags(additionalTags): """Validate a list of tag paths and raise a JSONRPCError if any are invalid. """ if additionalTags is not None: for path in additionalTags: if not isinstance(path, unicode): raise JSONRPCError( "Non-unicode element found in additionalTags.") if not isValidPath(path): raise JSONRPCError( "%r is not a valid path for additionalTags." % path)
def createTag(creator, namespace, name): """Create a new L{Tag}. @param creator: The L{User} that owns the L{Tag}. @param namespace: The parent L{Namespace}. @param name: The C{unicode} name of the L{Tag}. @raise MalformedPathError: Raised if C{path} is empty or has unnacceptable characters. @return: A new L{Tag} instance persisted in the main store. """ store = getMainStore() path = u'/'.join([namespace.path, name]) if not isValidPath(path): raise MalformedPathError("'%s' is not a valid path." % path) tag = Tag(creator, namespace, path, name) return store.add(tag)
def createTag(creator, namespace, name): """Create a new L{Tag}. @param creator: The L{User} that owns the L{Tag}. @param namespace: The parent L{Namespace}. @param name: The C{unicode} name of the L{Tag}. @raise MalformedPathError: Raised if C{path} is empty or has unnacceptable characters. @return: A new L{Tag} instance persisted in the main store. """ store = getMainStore() path = u'/'.join([namespace.path, name]) if not isValidPath(path): raise MalformedPathError("'%s' is not a valid path." % path) tag = Tag(creator, namespace, path, name) return store.add(tag)
def createNamespace(creator, path, parentID=None): """Create a new root-level L{Namespace}. @param creator: The L{User} that owns the namespace. @param path: The C{unicode} path (and name) of the namespace. @param parentID: Optionally, the L{Namespace.id} of the parent namespace. @raise MalformedPathError: Raised if C{path} is empty or has unacceptable characters. @return: A new L{Namespace} instance persisted in the main store. """ if not isValidPath(path): raise MalformedPathError("'%s' is not a valid path." % path) store = getMainStore() name = getPathName(path) namespace = Namespace(creator, path, name, parentID) return store.add(namespace)
def testIsValidWithEmptyPath(self): """L{isValidPath} returns C{False} if the specified path is empty.""" self.assertFalse(isValidPath(u''))
def testIsValidWithEmptyPath(self): """L{isValidPath} returns C{False} if the specified path is empty.""" self.assertFalse(isValidPath(u''))
def testIsValidWithEmptyPathComponent(self): """L{isValidPath} returns C{False} if any path component is empty.""" self.assertFalse(isValidPath(u'one//two'))
def testIsValidWithEmptyPathComponent(self): """L{isValidPath} returns C{False} if any path component is empty.""" self.assertFalse(isValidPath(u'one//two'))