Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../xml/dom
File: domreg.py
"""Registration facilities for DOM. This module should not be used
[0] Fix | Delete
directly. Instead, the functions getDOMImplementation and
[1] Fix | Delete
registerDOMImplementation should be imported from xml.dom."""
[2] Fix | Delete
[3] Fix | Delete
from xml.dom.minicompat import * # isinstance, StringTypes
[4] Fix | Delete
[5] Fix | Delete
# This is a list of well-known implementations. Well-known names
[6] Fix | Delete
# should be published by posting to xml-sig@python.org, and are
[7] Fix | Delete
# subsequently recorded in this file.
[8] Fix | Delete
[9] Fix | Delete
import sys
[10] Fix | Delete
[11] Fix | Delete
well_known_implementations = {
[12] Fix | Delete
'minidom':'xml.dom.minidom',
[13] Fix | Delete
'4DOM': 'xml.dom.DOMImplementation',
[14] Fix | Delete
}
[15] Fix | Delete
[16] Fix | Delete
# DOM implementations not officially registered should register
[17] Fix | Delete
# themselves with their
[18] Fix | Delete
[19] Fix | Delete
registered = {}
[20] Fix | Delete
[21] Fix | Delete
def registerDOMImplementation(name, factory):
[22] Fix | Delete
"""registerDOMImplementation(name, factory)
[23] Fix | Delete
[24] Fix | Delete
Register the factory function with the name. The factory function
[25] Fix | Delete
should return an object which implements the DOMImplementation
[26] Fix | Delete
interface. The factory function can either return the same object,
[27] Fix | Delete
or a new one (e.g. if that implementation supports some
[28] Fix | Delete
customization)."""
[29] Fix | Delete
[30] Fix | Delete
registered[name] = factory
[31] Fix | Delete
[32] Fix | Delete
def _good_enough(dom, features):
[33] Fix | Delete
"_good_enough(dom, features) -> Return 1 if the dom offers the features"
[34] Fix | Delete
for f,v in features:
[35] Fix | Delete
if not dom.hasFeature(f,v):
[36] Fix | Delete
return 0
[37] Fix | Delete
return 1
[38] Fix | Delete
[39] Fix | Delete
def getDOMImplementation(name = None, features = ()):
[40] Fix | Delete
"""getDOMImplementation(name = None, features = ()) -> DOM implementation.
[41] Fix | Delete
[42] Fix | Delete
Return a suitable DOM implementation. The name is either
[43] Fix | Delete
well-known, the module name of a DOM implementation, or None. If
[44] Fix | Delete
it is not None, imports the corresponding module and returns
[45] Fix | Delete
DOMImplementation object if the import succeeds.
[46] Fix | Delete
[47] Fix | Delete
If name is not given, consider the available implementations to
[48] Fix | Delete
find one with the required feature set. If no implementation can
[49] Fix | Delete
be found, raise an ImportError. The features list must be a sequence
[50] Fix | Delete
of (feature, version) pairs which are passed to hasFeature."""
[51] Fix | Delete
[52] Fix | Delete
import os
[53] Fix | Delete
creator = None
[54] Fix | Delete
mod = well_known_implementations.get(name)
[55] Fix | Delete
if mod:
[56] Fix | Delete
mod = __import__(mod, {}, {}, ['getDOMImplementation'])
[57] Fix | Delete
return mod.getDOMImplementation()
[58] Fix | Delete
elif name:
[59] Fix | Delete
return registered[name]()
[60] Fix | Delete
elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ:
[61] Fix | Delete
return getDOMImplementation(name = os.environ["PYTHON_DOM"])
[62] Fix | Delete
[63] Fix | Delete
# User did not specify a name, try implementations in arbitrary
[64] Fix | Delete
# order, returning the one that has the required features
[65] Fix | Delete
if isinstance(features, StringTypes):
[66] Fix | Delete
features = _parse_feature_string(features)
[67] Fix | Delete
for creator in registered.values():
[68] Fix | Delete
dom = creator()
[69] Fix | Delete
if _good_enough(dom, features):
[70] Fix | Delete
return dom
[71] Fix | Delete
[72] Fix | Delete
for creator in well_known_implementations.keys():
[73] Fix | Delete
try:
[74] Fix | Delete
dom = getDOMImplementation(name = creator)
[75] Fix | Delete
except StandardError: # typically ImportError, or AttributeError
[76] Fix | Delete
continue
[77] Fix | Delete
if _good_enough(dom, features):
[78] Fix | Delete
return dom
[79] Fix | Delete
[80] Fix | Delete
raise ImportError,"no suitable DOM implementation found"
[81] Fix | Delete
[82] Fix | Delete
def _parse_feature_string(s):
[83] Fix | Delete
features = []
[84] Fix | Delete
parts = s.split()
[85] Fix | Delete
i = 0
[86] Fix | Delete
length = len(parts)
[87] Fix | Delete
while i < length:
[88] Fix | Delete
feature = parts[i]
[89] Fix | Delete
if feature[0] in "0123456789":
[90] Fix | Delete
raise ValueError, "bad feature name: %r" % (feature,)
[91] Fix | Delete
i = i + 1
[92] Fix | Delete
version = None
[93] Fix | Delete
if i < length:
[94] Fix | Delete
v = parts[i]
[95] Fix | Delete
if v[0] in "0123456789":
[96] Fix | Delete
i = i + 1
[97] Fix | Delete
version = v
[98] Fix | Delete
features.append((feature, version))
[99] Fix | Delete
return tuple(features)
[100] Fix | Delete
[101] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function