Package xmlschema_acue :: Module resources

Module resources

source code

Classes
  XMLResource
XML resource reader based on ElementTree and urllib.
Functions
 
is_remote_url(url) source code
 
url_path_is_directory(url) source code
 
url_path_is_file(url) source code
 
normalize_url(url, base_url=None, keep_relative=False)
Returns a normalized URL doing a join with a base URL.
source code
 
fetch_resource(location, base_url=None, timeout=30)
Fetch a resource trying to accessing it.
source code
 
fetch_schema_locations(source, locations=None, **resource_options)
Fetches the schema URL for the source's root of an XML data source and a list of location hints.
source code
 
fetch_schema(source, locations=None, **resource_options)
Fetches the schema URL for the source's root of an XML data source.
source code
 
fetch_namespaces(source, **resource_options)
Extracts namespaces with related prefixes from the XML data source.
source code
 
load_xml_resource(source, element_only=True, **resource_options)
Load XML data source into an Element tree, returning the root Element, the XML text and an url, if available.
source code
Variables
  DEFUSE_MODES = 'always', 'remote', 'never'
Function Details

normalize_url(url, base_url=None, keep_relative=False)

source code 

Returns a normalized URL doing a join with a base URL. URL scheme defaults to 'file' and backslashes are replaced with slashes. For file paths the os.path.join is used instead of urljoin.

:param url: a relative or absolute URL. :param base_url: the reference base URL for construct the normalized URL from the argument. For compatibility between "os.path.join" and "urljoin" a trailing '/' is added to not empty paths. :param keep_relative: if set to `True` keeps relative file paths, which would not strictly conformant to URL format specification. :return: A normalized URL.

Decorators:

fetch_resource(location, base_url=None, timeout=30)

source code 

Fetch a resource trying to accessing it. If the resource is accessible returns the URL, otherwise raises an error (XMLSchemaURLError).

:param location: an URL or a file path. :param base_url: reference base URL for normalizing local and relative URLs. :param timeout: the timeout in seconds for the connection attempt in case of remote data. :return: a normalized URL.

Decorators:

fetch_schema_locations(source, locations=None, **resource_options)

source code 

Fetches the schema URL for the source's root of an XML data source and a list of location hints. If an accessible schema location is not found raises a ValueError.

:param source: an Element or an Element Tree with XML data or an URL or a file-like object. :param locations: a dictionary or dictionary items with Schema location hints. :param resource_options: keyword arguments for providing :class:`XMLResource` class init options. :return: A tuple with the URL referring to the first reachable schema resource, a list of dictionary items with normalized location hints.

Decorators:

fetch_schema(source, locations=None, **resource_options)

source code 

Fetches the schema URL for the source's root of an XML data source. If an accessible schema location is not found raises a ValueError.

:param source: An an Element or an Element Tree with XML data or an URL or a file-like object. :param locations: A dictionary or dictionary items with schema location hints. :param resource_options: keyword arguments for providing :class:`XMLResource` class init options. :return: An URL referring to a reachable schema resource.

Decorators:

fetch_namespaces(source, **resource_options)

source code 

Extracts namespaces with related prefixes from the XML data source. If the source is an lxml's ElementTree/Element returns the nsmap attribute of the root. If a duplicate prefix declaration is encountered then adds the namespace using a different prefix, but only in the case if the namespace URI is not already mapped by another prefix.

:param source: a string containing the XML document or file path or an url or a file like object or an ElementTree or Element. :param resource_options: keyword arguments for providing :class:`XMLResource` init options. :return: A dictionary for mapping namespace prefixes to full URI.

Decorators:

load_xml_resource(source, element_only=True, **resource_options)

source code 

Load XML data source into an Element tree, returning the root Element, the XML text and an url, if available. Usable for XML data files of small or medium sizes, as XSD schemas.

:param source: an URL, a filename path or a file-like object. :param element_only: if True the function returns only the root Element of the tree. :param resource_options: keyword arguments for providing :class:`XMLResource` init options. :return: a tuple with three items (root Element, XML text and XML URL) or only the root Element if 'element_only' argument is True.

Decorators: