fix py/io classes and tests to pass 3.1

introduce py.builtin._totext helper to make a 2k=unicode / 3k=str object, allow a string as data

--HG--
branch : trunk
This commit is contained in:
holger krekel
2009-08-29 15:51:49 +02:00
parent d75f7b2dd7
commit 1dafcc6b37
11 changed files with 222 additions and 196 deletions

View File

@@ -372,6 +372,11 @@ class LocalPath(FSBase):
""" write string content into path. """
s = str(content)
f = self.open(mode)
if not hasattr(s, 'decode'): # byte string
encoding = getattr(f, 'encoding', None)
if not encoding:
encoding = sys.getdefaultencoding()
s = s.encode(encoding)
try:
f.write(s)
finally: