Esempio n. 1
0
def get_local_dependencies(xsd_string):
    """Get local dependencies from an xsd.

    Args:
        xsd_string: XSD as string.

    Returns:
        Local dependencies

    """
    # declare list of dependencies
    dependencies = []
    # Get includes and imports
    imports, includes = get_imports_and_includes(xsd_string)
    # list of includes and imports
    xsd_includes_imports = imports + includes

    # get pattern to match the url to download a template
    pattern = get_template_download_pattern()

    for xsd_include_import in xsd_includes_imports:
        if xsd_include_import.attrib["schemaLocation"].startswith(SERVER_URI):
            try:
                # parse dependency url
                url = urlparse(xsd_include_import.attrib["schemaLocation"])
                # get id from url
                object_id = pattern.match(url.path).group("pk")
                # add id to list of internal dependencies
                dependencies.append(object_id)
            except Exception:
                raise XMLError("Local dependency schemaLocation is not well formed.")

    return dependencies
Esempio n. 2
0
    def get_dependency_content(self, uri):
        """ Get the content of the dependency from the database or from the URL. Try to get the content from the
        database first and then try to download it from the provided URI.

        Args:
            uri: Content URI.

        Returns:
            Content.

        """
        # parse url
        url = urlparse(uri)
        # get pattern to match a template download url
        pattern = get_template_download_pattern()
        # match url
        match = pattern.match(url.path)
        # if match
        if match:
            try:
                # get pk from match
                object_id = match.group('pk')
                # get template object using pk
                template = template_api.get(object_id)
                # get template content
                content = template.content
            except (exceptions.DoesNotExist, exceptions.ModelError, Exception):
                content = super(XSDFlattenerDatabaseOrURL,
                                self).get_dependency_content(uri)
        else:
            content = super(XSDFlattenerDatabaseOrURL,
                            self).get_dependency_content(uri)

        return content
Esempio n. 3
0
def _get_dependencies_ids(list_dependencies):
    """Return list of type ids from list of dependencies.

    Args:
        list_dependencies:

    Returns:

    """
    # declare list of dependencies
    dependencies = []
    # get pattern to match a template download
    pattern = get_template_download_pattern()
    # get all type ids
    for uri in list_dependencies:
        # parse dependency url
        url = urlparse(uri)
        try:
            # get object id from url
            object_id = pattern.match(url.path).group('pk')
            # get type by id, exception raised if not found
            type_object = type_api.get(object_id)
            # add id to list of internal dependencies
            dependencies.append(type_object)
        except:
            # id not found, don't add it to list of dependencies
            pass

    return dependencies
Esempio n. 4
0
def _get_dependencies_ids(list_dependencies, request):
    """Return list of type ids from list of dependencies.

    Args:
        list_dependencies:

    Returns:

    """
    # declare list of dependencies
    dependencies = []
    # get pattern to match a template download
    pattern = get_template_download_pattern()
    # get all type ids
    for uri in list_dependencies:
        # parse dependency url
        url = urlparse(uri)
        try:
            # get object id from url
            object_id = pattern.match(url.path).group("pk")
            # get type by id, exception raised if not found
            type_object = type_api.get(object_id, request=request)
            # add id to list of internal dependencies
            dependencies.append(type_object)
        except Exception as e:
            # id not found, don't add it to list of dependencies
            logger.warning(
                "_get_dependencies_ids threw an exception: {0}".format(str(e)))

    return dependencies