Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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.')
Ejemplo n.º 5
0
    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.')
Ejemplo n.º 6
0
 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))
Ejemplo n.º 7
0
 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))
Ejemplo n.º 8
0
 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)))
Ejemplo n.º 9
0
 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)))
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
 def testIsValidWithEmptyPath(self):
     """L{isValidPath} returns C{False} if the specified path is empty."""
     self.assertFalse(isValidPath(u''))
Ejemplo n.º 16
0
 def testIsValidWithEmptyPath(self):
     """L{isValidPath} returns C{False} if the specified path is empty."""
     self.assertFalse(isValidPath(u''))
Ejemplo n.º 17
0
 def testIsValidWithEmptyPathComponent(self):
     """L{isValidPath} returns C{False} if any path component is empty."""
     self.assertFalse(isValidPath(u'one//two'))
Ejemplo n.º 18
0
 def testIsValidWithEmptyPathComponent(self):
     """L{isValidPath} returns C{False} if any path component is empty."""
     self.assertFalse(isValidPath(u'one//two'))