projects
/
matthijs
/
upstream
/
mobilegtd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ab8105e
)
Add getfilesystemencoding() for python < 2.3.
author
Matthijs Kooijman
<matthijs@stdin.nl>
Wed, 12 Aug 2009 20:19:58 +0000
(22:19 +0200)
committer
Matthijs Kooijman
<matthijs@stdin.nl>
Thu, 13 Aug 2009 09:58:43 +0000
(11:58 +0200)
src/inout/io.py
patch
|
blob
|
history
diff --git
a/src/inout/io.py
b/src/inout/io.py
index 68b69130999fdfa2771326449965d07ae8d4734d..f873b67d7b0f9aa4d6b196e23f66dee210d37c62 100644
(file)
--- a/
src/inout/io.py
+++ b/
src/inout/io.py
@@
-24,15
+24,30
@@
def create_file(file_path):
f = file(file_name,'w')
return f
f = file(file_name,'w')
return f
+def getfilesystemencoding():
+ try:
+ # sys.getfilesystemencoding() was introduced in Python v2.3
+ return sys.getfilesystemencoding()
+ except AttributeError:
+ return 'ascii'
def os_encode(s):
def os_encode(s):
- return s.encode(sys.getfilesystemencoding())
+ # Encoding can be None, meaning the default system encoding should
+ # be used.
+ enc = getfilesystemencoding()
+ if enc:
+ return s.encode(enc)
+ else:
+ return s
def os_decode(s):
def os_decode(s):
- if type(s) == unicode:
+ # Encoding can be None, meaning the default system encoding should
+ # be used.
+ enc = getfilesystemencoding()
+ if type(s) == unicode or not enc:
return s
else:
return s
else:
- return unicode(s,
sys.getfilesystemencoding()
)
+ return unicode(s,
enc
)
def write(file_path,content):
f = create_file(file_path)
def write(file_path,content):
f = create_file(file_path)