[Python-checkins] python/dist/src/Lib/plat-mac plistlib.py,1.5,1.6

jvr at users.sourceforge.net jvr at users.sourceforge.net
Sat Oct 2 16:06:59 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4010
Modified Files:
	plistlib.py 
Log Message:
removed 2.2 support
Index: plistlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/plistlib.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- plistlib.py	2 Oct 2004 08:40:47 -0000	1.5
+++ plistlib.py	2 Oct 2004 14:06:56 -0000	1.6
@@ -11,8 +11,6 @@
 To parse a plist from a file, use the readPlist(pathOrFile)
 function, with a file name or a (readable) file object as the only
 argument. It returns the top level object (usually a dictionary).
-(Warning: you need pyexpat installed for this to work, ie. it doesn't
-work with a vanilla Python 2.2 as shipped with MacOS X.2.)
 
 Values can be strings, integers, floats, booleans, tuples, lists,
 dictionaries, Data or Date objects. String values (including dictionary
@@ -23,10 +21,6 @@
 values with attribute notation, where d.foo is equivalent to d["foo"].
 Regular dictionaries work, too.
 
-To support Boolean values in plists with Python < 2.3, "bool", "True"
-and "False" are exported. Use these symbols from this module if you
-want to be compatible with Python 2.2.x (strongly recommended).
-
 The <data> plist type is supported through the Data class. This is a
 thin wrapper around a Python string.
 
@@ -63,10 +57,8 @@
 """
 
 
-__all__ = ["readPlist", "writePlist", "Plist", "Data", "Date", "Dict",
- "False", "True", "bool"]
-# Note: the Plist class has been deprecated, Dict, False, True and bool
-# are here only for compatibility with Python 2.2.
+__all__ = ["readPlist", "writePlist", "Plist", "Data", "Date", "Dict"]
+# Note: the Plist class has been deprecated.
 
 
 def readPlist(pathOrFile):
@@ -215,7 +207,7 @@
 
 """Convenience dictionary subclass: it allows dict construction using
 keyword arguments (just like dict() in 2.3) as well as attribute notation
- to retrieve values, making d.foo more or less uquivalent to d["foo"].
+ to retrieve values, making d.foo equivalent to d["foo"].
 """
 
 def __new__(cls, **kwargs):
@@ -400,66 +392,3 @@
 self.addObject(Data.fromBase64(self.getData()))
 def end_date(self):
 self.addObject(Date(self.getData()))
-
-
-# cruft to support booleans in Python <= 2.3
-import sys
-if sys.version_info[:2] < (2, 3):
- # Python 2.2 and earlier: no booleans
- # Python 2.2.x: booleans are ints
- class bool(int):
- """Imitation of the Python 2.3 bool object."""
- def __new__(cls, value):
- return int.__new__(cls, not not value)
- def __repr__(self):
- if self:
- return "True"
- else:
- return "False"
- True = bool(1)
- False = bool(0)
-else:
- # Bind the boolean builtins to local names
- True = True
- False = False
- bool = bool
-
-
-if __name__ == "__main__":
- from StringIO import StringIO
- import time
- if len(sys.argv) == 1:
- pl = Dict(
- aString="Doodah",
- aList=["A", "B", 12, 32.1, [1, 2, 3]],
- aFloat = 0.1,
- anInt = 728,
- aDict=Dict(
- anotherString="<hello & hi there!>",
- aUnicodeValue=u'M\xe4ssig, Ma\xdf',
- aTrueValue=True,
- aFalseValue=False,
- ),
- someData = Data("<binary gunk>"),
- someMoreData = Data("<lots of binary gunk>" * 10),
-# aDate = Date(time.mktime(time.gmtime())),
- )
- elif len(sys.argv) == 2:
- pl = readPlist(sys.argv[1])
- else:
- print "Too many arguments: at most 1 plist file can be given."
- sys.exit(1)
-
- # unicode keys are possible, but a little awkward to use:
- pl[u'\xc5benraa'] = "That was a unicode key."
- f = StringIO()
- writePlist(pl, f)
- xml = f.getvalue()
- print xml
- f.seek(0)
- pl2 = readPlist(f)
- assert pl == pl2
- f = StringIO()
- writePlist(pl2, f)
- assert xml == f.getvalue()
- #print repr(pl2)


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /