"""Registration facilities for DOM. This module should not be useddirectly. Instead, the functions getDOMImplementation andregisterDOMImplementation should be imported from xml.dom."""# This is a list of well-known implementations. Well-known names# should be published by posting to xml-sig@python.org, and are# subsequently recorded in this file.import syswell_known_implementations = {'minidom':'xml.dom.minidom','4DOM': 'xml.dom.DOMImplementation',}# DOM implementations not officially registered should register# themselves with theirregistered = {}def registerDOMImplementation(name, factory):"""registerDOMImplementation(name, factory)Register the factory function with the name. The factory functionshould return an object which implements the DOMImplementationinterface. The factory function can either return the same object,or a new one (e.g. if that implementation supports somecustomization)."""registered[name] = factorydef _good_enough(dom, features):"_good_enough(dom, features) -> Return 1 if the dom offers the features"for f,v in features:if not dom.hasFeature(f,v):return 0return 1def getDOMImplementation(name=None, features=()):"""getDOMImplementation(name = None, features = ()) -> DOM implementation.Return a suitable DOM implementation. The name is eitherwell-known, the module name of a DOM implementation, or None. Ifit is not None, imports the corresponding module and returnsDOMImplementation object if the import succeeds.If name is not given, consider the available implementations tofind one with the required feature set. If no implementation canbe found, raise an ImportError. The features list must be a sequenceof (feature, version) pairs which are passed to hasFeature."""import oscreator = Nonemod = well_known_implementations.get(name)if mod:mod = __import__(mod, {}, {}, ['getDOMImplementation'])return mod.getDOMImplementation()elif name:return registered[name]()elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ:return getDOMImplementation(name = os.environ["PYTHON_DOM"])# User did not specify a name, try implementations in arbitrary# order, returning the one that has the required featuresif isinstance(features, str):features = _parse_feature_string(features)for creator in registered.values():dom = creator()if _good_enough(dom, features):return domfor creator in well_known_implementations.keys():try:dom = getDOMImplementation(name = creator)except Exception: # typically ImportError, or AttributeErrorcontinueif _good_enough(dom, features):return domraise ImportError("no suitable DOM implementation found")def _parse_feature_string(s):features = []parts = s.split()i = 0length = len(parts)while i < length:feature = parts[i]if feature[0] in "0123456789":raise ValueError("bad feature name: %r" % (feature,))i = i + 1version = Noneif i < length:v = parts[i]if v[0] in "0123456789":i = i + 1version = vfeatures.append((feature, version))return tuple(features)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。