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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user