3434Generate Plist example:
3535
3636 pl = Plist(
37- Foo ="Doodah",
38- aList=["A", "B", 12, 32.1, [1, 2, 3]],
39- aFloat = 0.1,
40- anInt = 728,
41- aDict=Dict(
42- aString ="<hello & hi there!>",
43- SomeUnicodeValue =u'M\xe4 ssig, Ma\xdf ',
44- someTrueValue =True,
45- someFalseValue =False,
46- ),
47- someData = Data("hello there! "),
48- someMoreData = Data("hello there! " * 10),
49- aDate = Date(time.mktime(time.gmtime())),
37+ aString ="Doodah",
38+ aList=["A", "B", 12, 32.1, [1, 2, 3]],
39+ aFloat = 0.1,
40+ anInt = 728,
41+ aDict=Dict(
42+ anotherString ="<hello & hi there!>",
43+ aUnicodeValue =u'M\xe4 ssig, Ma\xdf ',
44+ aTrueValue =True,
45+ aFalseValue =False,
46+ ),
47+ someData = Data("<binary gunk> "),
48+ someMoreData = Data("<lots of binary gunk> " * 10),
49+ aDate = Date(time.mktime(time.gmtime())),
5050 )
5151 # unicode keys are possible, but a little awkward to use:
5252 pl[u'\xc5 benraa'] = "That was a unicode key."
@@ -78,7 +78,6 @@ def __init__(self, file):
7878
7979 def beginElement (self , element ):
8080 self .stack .append (element )
81- element = _encode (element )
8281 self .writeln ("<%s>" % element )
8382 self .indentLevel += 1
8483
@@ -90,7 +89,6 @@ def endElement(self, element):
9089
9190 def simpleElement (self , element , value = None ):
9291 if value :
93- element = _encode (element )
9492 value = _encode (value )
9593 self .writeln ("<%s>%s</%s>" % (element , value , element ))
9694 else :
@@ -172,7 +170,7 @@ def writeArray(self, array):
172170
173171class Dict :
174172
175- """Dict wrapper for convenient acces of values through attributes."""
173+ """Dict wrapper for convenient access of values through attributes."""
176174
177175 def __init__ (self , ** args ):
178176 self .__dict__ .update (args )
@@ -189,6 +187,9 @@ def __str__(self):
189187 return "%s(**%s)" % (self .__class__ .__name__ , self .__dict__ )
190188 __repr__ = __str__
191189
190+ def copy (self ):
191+ return self .__class__ (** self .__dict__ )
192+
192193 def __getattr__ (self , attr ):
193194 """Delegate everything else to the dict object."""
194195 return getattr (self .__dict__ , attr )
@@ -400,19 +401,19 @@ def __repr__(self):
400401 import time
401402 if len (sys .argv ) == 1 :
402403 pl = Plist (
403- Foo = "Doodah" ,
404- aList = ["A" , "B" , 12 , 32.1 , [1 , 2 , 3 ]],
405- aFloat = 0.1 ,
406- anInt = 728 ,
407- aDict = Dict (
408- aString = "<hello & hi there!>" ,
409- SomeUnicodeValue = u'M\xe4 ssig, Ma\xdf ' ,
410- someTrueValue = True ,
411- someFalseValue = False ,
412- ),
413- someData = Data ("hello there! " ),
414- someMoreData = Data ("hello there! " * 10 ),
415- aDate = Date (time .mktime (time .gmtime ())),
404+ aString = "Doodah" ,
405+ aList = ["A" , "B" , 12 , 32.1 , [1 , 2 , 3 ]],
406+ aFloat = 0.1 ,
407+ anInt = 728 ,
408+ aDict = Dict (
409+ anotherString = "<hello & hi there!>" ,
410+ aUnicodeValue = u'M\xe4 ssig, Ma\xdf ' ,
411+ aTrueValue = True ,
412+ aFalseValue = False ,
413+ ),
414+ someData = Data ("<binary gunk> " ),
415+ someMoreData = Data ("<lots of binary gunk> " * 10 ),
416+ aDate = Date (time .mktime (time .gmtime ())),
416417 )
417418 elif len (sys .argv ) == 2 :
418419 pl = Plist .fromFile (sys .argv [1 ])
0 commit comments