コード例 #1
0
ファイル: schema.py プロジェクト: crudbug/canopsis
    def push_schema(self, name, schema):
        """
        Store a schema on server and cache it

        :param str name: name of schema file
        :param str schema: xml content in a string
        :raises ValueError: if schema name already exists
        :raises SyntaxError: if xml cannot be read by lxml
        :raises AttributeError: if unique_key does not exist
        :raises ValueError: if unique_key exists in an other schema
        """

        if is_name_available(name):
            raise ValueError("Provided schema name : '{}' already exists".format(name))

        if self.validate_schema(schema)[0] is False:
            raise SyntaxError("Provided xml can neither be interpreted as " "XMLSchema nor as XSLT")

        xschema = parse(StringIO(schema))
        unique_key = get_unique_key(xschema)
        if unique_key is None:
            raise AttributeError("Unique key (targetNamespace attribute of " "root element) does not exist")

        if self.is_unique_key_existing(unique_key):
            raise ValueError("Unique key ('{}') already exists".format(unique_key))

        # if no exception has been raised until here, we can write the
        # schema and add it to cache
        self.cache_schema(xschema)
        with open(get_schema_path(name), "w") as schema_file:
            schema_file.write(schema)
コード例 #2
0
ファイル: schema.py プロジェクト: merouaneagar/canopsis
    def push_schema(self, name, schema):
        """
        Store a schema on server and cache it

        :param str name: name of schema file
        :param str schema: xml content in a string
        :raises ValueError: if schema name already exists
        :raises SyntaxError: if xml cannot be read by lxml
        :raises AttributeError: if unique_key does not exist
        :raises ValueError: if unique_key exists in an other schema
        """

        if is_name_available(name):
            raise ValueError(
                'Provided schema name : \'{}\' already exists'.format(name))

        if self.validate_schema(schema)[0] is False:
            raise SyntaxError('Provided xml can neither be interpreted as '
                              'XMLSchema nor as XSLT')

        xschema = parse(StringIO(schema))
        unique_key = get_unique_key(xschema)
        if unique_key is None:
            raise AttributeError('Unique key (targetNamespace attribute of '
                                 'root element) does not exist')

        if self.is_unique_key_existing(unique_key):
            raise ValueError(
                'Unique key (\'{}\') already exists'.format(unique_key))

        # if no exception has been raised until here, we can write the
        # schema and add it to cache
        self.cache_schema(xschema)
        with open(get_schema_path(name), 'w') as schema_file:
            schema_file.write(schema)
コード例 #3
0
 def test_is_name_available(self, get_schema_path):
     self.assertTrue(is_name_available('profile.xsd'))
     self.assertTrue(is_name_available('profile_to_name.xsl'))
     self.assertFalse(is_name_available('a_wrong_query_token'))