4Suite™ API Documentation

# ► Module Ft.Xml.InputSource

Classes providing a standard interface and encapsulation of metadata for document/entity streams intended for input to various XML processors.
Copyright 2005 Fourthought, Inc. (USA).
Detailed license and copyright information: http://4suite.org/COPYRIGHT
Project home, documentation, distributions: http://4suite.org/

Classes: InputSource, InputSourceFactory, NullInputSource |  |  |  | Fields: DefaultFactory, NoCatalogFactory

## Classes

class InputSource
An input source is an encapsulation of a source of content. It includes a stream (Python file-like object) from which the content can be read, a URI to identify the stream and facilitate resolution of relative URI references / system IDs encountered within the stream, and parameters used by the processors of the stream (XML parsers, XSLT processors).
It is designed to be overridden as applications need different
functionality from sources.

### Methods

__getstate__(self)
#Pickle routines. We need to be able to pickle an input source #but cannot pickle a stream
__init__(self, stream, uri=None, processIncludes=True, stripElements=None, factory=None, resolver=<Ft.Lib.Uri.FtUriResolver instance at 0x48a04fac>, catalog=None, encoding=None)
stream - the stream associated with this input source uri - the absolute URI of the input source processIncludes - Whether or not XIncludes should be expanded stripElements - Space stripping rules factory - The factory that created this instance resolver - URI resolver; defaults to Ft.Lib.Uri.BASIC_RESOLVER catalog - TR9401/XML Catalog object for resolving public IDs encoding - a string externally declaring the stream's encoding
clone(self, stream, uri=None, hint=None)
Clones this input source, creating a new instance with the known params.
If your derived InputSource requires additional state information
then you have to override how it is cloned and pickled.
close(self)
getUriResolver(self)
This method returns the URI resolver that is used by this input source to normalize (resolve to absolute form) and resolve (dereference) URI references. This is the public method to use if just URI resolution is needed.
read(self, bufsiz=-1)
#Stream protocol methods
readline(self)
resolve(self, sysid, pubid=None, hint=None, ignoreErrors=False)
Resolves a system identifier (fragmentless URI reference) or a public identifier into a new input source. It is typically used when a URI reference is encountered in the original stream and needs to be resolved (e.g. to support an external entity reference, XInclude, xsl:include/import, document(), etc.).
The hint parameter is used to give a hint as to what the
resolution will be used for.
The default implementation ignores the hint, and will resolve
against a catalog, if one is available.
If the ignoreErrors flag is set, an error during resolution
(such as "file not found") will result in None's being returned,
rather than a raised exception.
resolveEntity(self, pubid, sysid)
#xml.sax.EntityResolver method

class InputSourceFactory
A factory for creating new InputSource instances.

### Methods

__init__(self, inputSourceClass=None, resolver=<Ft.Lib.Uri.FtUriResolver instance at 0x48a04fac>, catalog=None)
fromStream(self, stream, uri=None, *v_args, **kw_args)
Creates an InputSource from the given stream. The uri argument is the URI to use for the stream (one should always be given, even if it's bogus).
fromString(self, st, uri=None, *v_args, **kw_args)
Creates an InputSource from a stream derived from the given string. The uri argument is the URI to use for the stream (one should always be given, even if it's bogus).
fromUri(self, uri, *v_args, **kw_args)
Creates an InputSource from the stream resulting from the resolution of the given URI.
uri - a URI from which the input will be read. Important: a file
path is generally not a URI. To be safe, if you wish to read
from a file, use the following pattern:
from Ft.Lib import Uri
uri = Uri.OsPathToUri("/path/to/file.ext")
OR uri = Uri.OsPathToUri("C:\path\to\file.ext")

class NullInputSource(InputSource)
An InputSource that simulates an empty stream.

### Methods

__init__(self, uri=None)

### Methods inherited from class InputSource

__getstate__, clone, close, getUriResolver, read, readline, resolve, resolveEntity

## Fields

DefaultFactory = <Ft.Xml.InputSource.InputSourceFactory instance>
NoCatalogFactory = <Ft.Xml.InputSource.InputSourceFactory instance>