source: trunk/essentials/dev-lang/python/Lib/xml/dom/minicompat.py@ 3226

Last change on this file since 3226 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 3.3 KB
Line 
1"""Python version compatibility support for minidom."""
2
3# This module should only be imported using "import *".
4#
5# The following names are defined:
6#
7# NodeList -- lightest possible NodeList implementation
8#
9# EmptyNodeList -- lightest possible NodeList that is guarateed to
10# remain empty (immutable)
11#
12# StringTypes -- tuple of defined string types
13#
14# defproperty -- function used in conjunction with GetattrMagic;
15# using these together is needed to make them work
16# as efficiently as possible in both Python 2.2+
17# and older versions. For example:
18#
19# class MyClass(GetattrMagic):
20# def _get_myattr(self):
21# return something
22#
23# defproperty(MyClass, "myattr",
24# "return some value")
25#
26# For Python 2.2 and newer, this will construct a
27# property object on the class, which avoids
28# needing to override __getattr__(). It will only
29# work for read-only attributes.
30#
31# For older versions of Python, inheriting from
32# GetattrMagic will use the traditional
33# __getattr__() hackery to achieve the same effect,
34# but less efficiently.
35#
36# defproperty() should be used for each version of
37# the relevant _get_<property>() function.
38
39__all__ = ["NodeList", "EmptyNodeList", "StringTypes", "defproperty"]
40
41import xml.dom
42
43try:
44 unicode
45except NameError:
46 StringTypes = type(''),
47else:
48 StringTypes = type(''), type(unicode(''))
49
50
51class NodeList(list):
52 __slots__ = ()
53
54 def item(self, index):
55 if 0 <= index < len(self):
56 return self[index]
57
58 def _get_length(self):
59 return len(self)