diff -r cf70f030a744 Lib/plistlib.py --- a/Lib/plistlib.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/plistlib.py Mon Jun 23 21:44:22 2014 +0300 @@ -71,7 +71,7 @@ usually is a dictionary). """ didOpen = 0 - if isinstance(pathOrFile, (str, unicode)): + if isinstance(pathOrFile, basestring): pathOrFile = open(pathOrFile) didOpen = 1 p = PlistParser() @@ -86,7 +86,7 @@ file name or a (writable) file object. """ didOpen = 0 - if isinstance(pathOrFile, (str, unicode)): + if isinstance(pathOrFile, basestring): pathOrFile = open(pathOrFile, "w") didOpen = 1 writer = PlistWriter(pathOrFile) @@ -219,7 +219,11 @@ text = text.replace("&", "&") # escape '&' text = text.replace("<", "<") # escape '<' text = text.replace(">", ">") # escape '>' - return text.encode("utf-8") # encode as UTF-8 + try: + text = text.encode("utf-8") # encode as UTF-8 + except AttributeError: # no unicode support + pass + return text PLISTHEADER = """\ @@ -235,7 +239,7 @@ DumbXMLWriter.__init__(self, file, indentLevel, indent) def writeValue(self, value): - if isinstance(value, (str, unicode)): + if isinstance(value, basestring): self.simpleElement("string", value) elif isinstance(value, bool): # must switch for bool before int, as bool is a @@ -275,7 +279,7 @@ items = d.items() items.sort() for key, value in items: - if not isinstance(key, (str, unicode)): + if not isinstance(key, basestring): raise TypeError("keys must be strings") self.simpleElement("key", key) self.writeValue(value) @@ -434,7 +438,7 @@ data = "".join(self.data) try: data = data.encode("ascii") - except UnicodeError: + except (UnicodeError, AttributeError): pass self.data = [] return data diff -r cf70f030a744 Lib/test/test_plistlib.py --- a/Lib/test/test_plistlib.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/test/test_plistlib.py Mon Jun 23 21:44:22 2014 +0300 @@ -103,7 +103,8 @@ anInt = 728, aDict=dict( anotherString="", - aUnicodeValue=u'M\xe4ssig, Ma\xdf', + aUnicodeValue=u'M\xe4ssig, Ma\xdf' if test_support.have_unicode + else 'M\xc3\xa4ssig, Ma\xc3\x9f', aTrueValue=True, aFalseValue=False, deeperDict=dict(a=17, b=32.5, c=[1, 2, "text"]), @@ -113,7 +114,8 @@ nestedData = [plistlib.Data("\0\1\2\3" * 10)], aDate = datetime.datetime(2004, 10, 26, 10, 33, 33), ) - pl[u'\xc5benraa'] = "That was a unicode key." + pl[u'\xc5benraa' if test_support.have_unicode else '\xc3\x85benraa'] = \ + "That was a unicode key." return pl def test_create(self):