Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../xml/dom
File: minicompat.py
"""Python version compatibility support for minidom."""
[0] Fix | Delete
[1] Fix | Delete
# This module should only be imported using "import *".
[2] Fix | Delete
#
[3] Fix | Delete
# The following names are defined:
[4] Fix | Delete
#
[5] Fix | Delete
# NodeList -- lightest possible NodeList implementation
[6] Fix | Delete
#
[7] Fix | Delete
# EmptyNodeList -- lightest possible NodeList that is guaranteed to
[8] Fix | Delete
# remain empty (immutable)
[9] Fix | Delete
#
[10] Fix | Delete
# StringTypes -- tuple of defined string types
[11] Fix | Delete
#
[12] Fix | Delete
# defproperty -- function used in conjunction with GetattrMagic;
[13] Fix | Delete
# using these together is needed to make them work
[14] Fix | Delete
# as efficiently as possible in both Python 2.2+
[15] Fix | Delete
# and older versions. For example:
[16] Fix | Delete
#
[17] Fix | Delete
# class MyClass(GetattrMagic):
[18] Fix | Delete
# def _get_myattr(self):
[19] Fix | Delete
# return something
[20] Fix | Delete
#
[21] Fix | Delete
# defproperty(MyClass, "myattr",
[22] Fix | Delete
# "return some value")
[23] Fix | Delete
#
[24] Fix | Delete
# For Python 2.2 and newer, this will construct a
[25] Fix | Delete
# property object on the class, which avoids
[26] Fix | Delete
# needing to override __getattr__(). It will only
[27] Fix | Delete
# work for read-only attributes.
[28] Fix | Delete
#
[29] Fix | Delete
# For older versions of Python, inheriting from
[30] Fix | Delete
# GetattrMagic will use the traditional
[31] Fix | Delete
# __getattr__() hackery to achieve the same effect,
[32] Fix | Delete
# but less efficiently.
[33] Fix | Delete
#
[34] Fix | Delete
# defproperty() should be used for each version of
[35] Fix | Delete
# the relevant _get_<property>() function.
[36] Fix | Delete
[37] Fix | Delete
__all__ = ["NodeList", "EmptyNodeList", "StringTypes", "defproperty"]
[38] Fix | Delete
[39] Fix | Delete
import xml.dom
[40] Fix | Delete
[41] Fix | Delete
try:
[42] Fix | Delete
unicode
[43] Fix | Delete
except NameError:
[44] Fix | Delete
StringTypes = type(''),
[45] Fix | Delete
else:
[46] Fix | Delete
StringTypes = type(''), type(unicode(''))
[47] Fix | Delete
[48] Fix | Delete
[49] Fix | Delete
class NodeList(list):
[50] Fix | Delete
__slots__ = ()
[51] Fix | Delete
[52] Fix | Delete
def item(self, index):
[53] Fix | Delete
if 0 <= index < len(self):
[54] Fix | Delete
return self[index]
[55] Fix | Delete
[56] Fix | Delete
def _get_length(self):
[57] Fix | Delete
return len(self)
[58] Fix | Delete
[59] Fix | Delete
def _set_length(self, value):
[60] Fix | Delete
raise xml.dom.NoModificationAllowedErr(
[61] Fix | Delete
"attempt to modify read-only attribute 'length'")
[62] Fix | Delete
[63] Fix | Delete
length = property(_get_length, _set_length,
[64] Fix | Delete
doc="The number of nodes in the NodeList.")
[65] Fix | Delete
[66] Fix | Delete
# For backward compatibility
[67] Fix | Delete
def __setstate__(self, state):
[68] Fix | Delete
if state is None:
[69] Fix | Delete
state = []
[70] Fix | Delete
self[:] = state
[71] Fix | Delete
[72] Fix | Delete
[73] Fix | Delete
class EmptyNodeList(tuple):
[74] Fix | Delete
__slots__ = ()
[75] Fix | Delete
[76] Fix | Delete
def __add__(self, other):
[77] Fix | Delete
NL = NodeList()
[78] Fix | Delete
NL.extend(other)
[79] Fix | Delete
return NL
[80] Fix | Delete
[81] Fix | Delete
def __radd__(self, other):
[82] Fix | Delete
NL = NodeList()
[83] Fix | Delete
NL.extend(other)
[84] Fix | Delete
return NL
[85] Fix | Delete
[86] Fix | Delete
def item(self, index):
[87] Fix | Delete
return None
[88] Fix | Delete
[89] Fix | Delete
def _get_length(self):
[90] Fix | Delete
return 0
[91] Fix | Delete
[92] Fix | Delete
def _set_length(self, value):
[93] Fix | Delete
raise xml.dom.NoModificationAllowedErr(
[94] Fix | Delete
"attempt to modify read-only attribute 'length'")
[95] Fix | Delete
[96] Fix | Delete
length = property(_get_length, _set_length,
[97] Fix | Delete
doc="The number of nodes in the NodeList.")
[98] Fix | Delete
[99] Fix | Delete
[100] Fix | Delete
def defproperty(klass, name, doc):
[101] Fix | Delete
get = getattr(klass, ("_get_" + name)).im_func
[102] Fix | Delete
def set(self, value, name=name):
[103] Fix | Delete
raise xml.dom.NoModificationAllowedErr(
[104] Fix | Delete
"attempt to modify read-only attribute " + repr(name))
[105] Fix | Delete
assert not hasattr(klass, "_set_" + name), \
[106] Fix | Delete
"expected not to find _set_" + name
[107] Fix | Delete
prop = property(get, set, doc=doc)
[108] Fix | Delete
setattr(klass, name, prop)
[109] Fix | Delete
[110] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function