[Python-checkins] python/dist/src/Lib/plat-mac plistlib.py, 1.17,
1.18
jvr at users.sourceforge.net
jvr at users.sourceforge.net
Fri Nov 12 10:36:15 CET 2004
Update of /cvsroot/python/python/dist/src/Lib/plat-mac
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7266/plat-mac
Modified Files:
plistlib.py
Log Message:
On second thought: "Errors should never pass silently", so barf when a
string contains control chars that are illegal for XML
Index: plistlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-mac/plistlib.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- plistlib.py 12 Nov 2004 08:14:49 -0000 1.17
+++ plistlib.py 12 Nov 2004 09:36:11 -0000 1.18
@@ -200,18 +200,21 @@
)
-# Regex to strip all control chars, but for \t \n and \r
-_controlStripper = re.compile(
+# Regex to find any control chars, except for \t \n and \r
+_controlCharPat = re.compile(
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
def _escapeAndEncode(text):
+ m = _controlCharPat.search(text)
+ if m is not None:
+ raise ValueError("strings can't contains control characters; "
+ "use plistlib.Data instead")
text = text.replace("\r\n", "\n") # convert DOS line endings
text = text.replace("\r", "\n") # convert Mac line endings
text = text.replace("&", "&") # escape '&'
text = text.replace("<", "<") # escape '<'
text = text.replace(">", ">") # escape '>'
- text = _controlStripper.sub("?", text) # replace control chars with '?'
return text.encode("utf-8") # encode as UTF-8
More information about the Python-checkins
mailing list