diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-14 07:37:51 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-14 07:37:51 -0500 |
commit | 19fe0817ba7c2cd04caea3adfa82d4490288a548 (patch) | |
tree | 6291cac9b9861f1009d63a419c3e79879f356bc8 /libbe/util/encoding.py | |
parent | 2f0ceedba5b6619faf476cd1aa67e826e91d5c7c (diff) | |
download | bugseverywhere-19fe0817ba7c2cd04caea3adfa82d4490288a548.tar.gz |
Transitioned comment to Command format
Diffstat (limited to 'libbe/util/encoding.py')
-rw-r--r-- | libbe/util/encoding.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py index af312c1..434bae7 100644 --- a/libbe/util/encoding.py +++ b/libbe/util/encoding.py @@ -22,6 +22,7 @@ Support input/output/filesystem encodings (e.g. UTF-8). import codecs import locale import sys +import types import libbe if libbe.TESTING == True: @@ -65,5 +66,26 @@ def known_encoding(encoding): except LookupError: return False +def get_file_contents(path, mode='r', encoding=None, decode=False): + if decode == True: + if encoding == None: + encoding = get_filesystem_encoding() + f = codecs.open(path, mode, encoding) + else: + f = open(path, mode) + contents = f.read() + f.close() + return contents + +def set_file_contents(path, contents, mode='w', encoding=None): + if type(value) == types.UnicodeType: + if encoding == None: + encoding = get_filesystem_encoding() + f = codecs.open(path, mode, encoding) + else: + f = open(path, mode) + f.write(contents) + f.close() + if libbe.TESTING == True: suite = doctest.DocTestSuite() |