"NMTOKENS": minidom.TypeInfo(None, "nmtokens"),
}
-class ElementInfo(NewStyle):
+class ElementInfo(object):
__slots__ = '_attr_info', '_model', 'tagName'
def __init__(self, tagName, model=None):
# where allowed.
_ALLOWED_FILTER_RETURNS = (FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP)
-class FilterVisibilityController(NewStyle):
+class FilterVisibilityController(object):
"""Wrapper around a DOMBuilderFilter which implements the checks
to make the whatToShow filter attribute work."""
}
-class FilterCrutch(NewStyle):
+class FilterCrutch(object):
__slots__ = '_builder', '_level', '_old_start', '_old_end'
def __init__(self, builder):
raise ParseEscape()
-def parse(file, namespaces=1):
+def parse(file, namespaces=True):
"""Parse a document, returning the resulting Document node.
'file' may be either a file name or an open file object.
return result
-def parseString(string, namespaces=1):
+def parseString(string, namespaces=True):
"""Parse a document from a string, returning the resulting
Document node.
"""
return builder.parseString(string)
-def parseFragment(file, context, namespaces=1):
+def parseFragment(file, context, namespaces=True):
"""Parse a fragment of a document, given the context from which it
was originally extracted. context should be the parent of the
node(s) which are in the fragment.
return result
-def parseFragmentString(string, context, namespaces=1):
+def parseFragmentString(string, context, namespaces=True):
"""Parse a fragment of a document from a string, given the context
from which it was originally extracted. context should be the
parent of the node(s) which are in the fragment.
#
# The following names are defined:
#
-# isinstance -- version of the isinstance() function that accepts
-# tuples as the second parameter regardless of the
-# Python version
-#
# NodeList -- lightest possible NodeList implementation
#
# EmptyNodeList -- lightest possible NodeList that is guarateed to
#
# StringTypes -- tuple of defined string types
#
-# GetattrMagic -- base class used to make _get_<attr> be magically
-# invoked when available
# defproperty -- function used in conjunction with GetattrMagic;
# using these together is needed to make them work
# as efficiently as possible in both Python 2.2+
#
# defproperty() should be used for each version of
# the relevant _get_<property>() function.
-#
-# NewStyle -- base class to cause __slots__ to be honored in
-# the new world
-#
-# True, False -- only for Python 2.2 and earlier
-__all__ = ["NodeList", "EmptyNodeList", "NewStyle",
- "StringTypes", "defproperty", "GetattrMagic"]
+__all__ = ["NodeList", "EmptyNodeList", "StringTypes", "defproperty"]
import xmlcore.dom
StringTypes = type(''), type(unicode(''))
-# define True and False only if not defined as built-ins
-try:
- True
-except NameError:
- True = 1
- False = 0
- __all__.extend(["True", "False"])
+class NodeList(list):
+ __slots__ = ()
+ def item(self, index):
+ if 0 <= index < len(self):
+ return self[index]
-try:
- isinstance('', StringTypes)
-except TypeError:
- #
- # Wrap isinstance() to make it compatible with the version in
- # Python 2.2 and newer.
- #
- _isinstance = isinstance
- def isinstance(obj, type_or_seq):
- try:
- return _isinstance(obj, type_or_seq)
- except TypeError:
- for t in type_or_seq:
- if _isinstance(obj, t):
- return 1
- return 0
- __all__.append("isinstance")
-
-
-if list is type([]):
- class NodeList(list):
- __slots__ = ()
-
- def item(self, index):
- if 0 <= index < len(self):
- return self[index]
-
- def _get_length(self):
- return len(self)
-
- def _set_length(self, value):
- raise xmlcore.dom.NoModificationAllowedErr(
- "attempt to modify read-only attribute 'length'")
-
- length = property(_get_length, _set_length,
- doc="The number of nodes in the NodeList.")
-
- def __getstate__(self):
- return list(self)
-
- def __setstate__(self, state):
- self[:] = state
-
- class EmptyNodeList(tuple):
- __slots__ = ()
-
- def __add__(self, other):
- NL = NodeList()
- NL.extend(other)
- return NL
-
- def __radd__(self, other):
- NL = NodeList()
- NL.extend(other)
- return NL
-
- def item(self, index):
- return None
-
- def _get_length(self):
- return 0
-
- def _set_length(self, value):
- raise xmlcore.dom.NoModificationAllowedErr(
- "attempt to modify read-only attribute 'length'")
-
- length = property(_get_length, _set_length,
- doc="The number of nodes in the NodeList.")
+ def _get_length(self):
+ return len(self)
-else:
- def NodeList():
- return []
+ def _set_length(self, value):
+ raise xml.dom.NoModificationAllowedErr(
+ "attempt to modify read-only attribute 'length'")
- def EmptyNodeList():
- return []
+ length = property(_get_length, _set_length,
+ doc="The number of nodes in the NodeList.")
+ def __getstate__(self):
+ return list(self)
-try:
- property
-except NameError:
- def defproperty(klass, name, doc):
- # taken care of by the base __getattr__()
- pass
+ def __setstate__(self, state):
+ self[:] = state
- class GetattrMagic:
- def __getattr__(self, key):
- if key.startswith("_"):
- raise AttributeError, key
+class EmptyNodeList(tuple):
+ __slots__ = ()
- try:
- get = getattr(self, "_get_" + key)
- except AttributeError:
- raise AttributeError, key
- return get()
+ def __add__(self, other):
+ NL = NodeList()
+ NL.extend(other)
+ return NL
- class NewStyle:
- pass
+ def __radd__(self, other):
+ NL = NodeList()
+ NL.extend(other)
+ return NL
-else:
- def defproperty(klass, name, doc):
- get = getattr(klass, ("_get_" + name)).im_func
- def set(self, value, name=name):
- raise xmlcore.dom.NoModificationAllowedErr(
- "attempt to modify read-only attribute " + repr(name))
- assert not hasattr(klass, "_set_" + name), \
- "expected not to find _set_" + name
- prop = property(get, set, doc=doc)
- setattr(klass, name, prop)
-
- class GetattrMagic:
- pass
-
- NewStyle = object
+ def item(self, index):
+ return None
+
+ def _get_length(self):
+ return 0
+
+ def _set_length(self, value):
+ raise xml.dom.NoModificationAllowedErr(
+ "attempt to modify read-only attribute 'length'")
+
+ length = property(_get_length, _set_length,
+ doc="The number of nodes in the NodeList.")
+
+
+def defproperty(klass, name, doc):
+ get = getattr(klass, ("_get_" + name)).im_func
+ def set(self, value, name=name):
+ raise xml.dom.NoModificationAllowedErr(
+ "attempt to modify read-only attribute " + repr(name))
+ assert not hasattr(klass, "_set_" + name), \
+ "expected not to find _set_" + name
+ prop = property(get, set, doc=doc)
+ setattr(klass, name, prop)
xmlcore.dom.Node.ENTITY_REFERENCE_NODE)
-class Node(xmlcore.dom.Node, GetattrMagic):
+class Node(xmlcore.dom.Node):
namespaceURI = None # this is non-null only for elements and attributes
parentNode = None
ownerDocument = None
defproperty(Attr, "schemaType", doc="Schema type for this attribute.")
-class NamedNodeMap(NewStyle, GetattrMagic):
+class NamedNodeMap(object):
"""The attribute list is a transient interface to the underlying
dictionaries. Mutations here will change the underlying element's
dictionary.
AttributeList = NamedNodeMap
-class TypeInfo(NewStyle):
+class TypeInfo(object):
__slots__ = 'namespace', 'name'
def __init__(self, namespace, name):
writer.write("<![CDATA[%s]]>" % self.data)
-class ReadOnlySequentialNamedNodeMap(NewStyle, GetattrMagic):
+class ReadOnlySequentialNamedNodeMap(object):
__slots__ = '_seq',
def __init__(self, seq=()):
def _create_document(self):
return Document()
-class ElementInfo(NewStyle):
+class ElementInfo(object):
"""Object that represents content-model information for an element.
This implementation is not expected to be used in practice; DOM