aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/util/encoding.py
diff options
context:
space:
mode:
Diffstat (limited to 'libbe/util/encoding.py')
-rw-r--r--libbe/util/encoding.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py
index d09117f..21e40cf 100644
--- a/libbe/util/encoding.py
+++ b/libbe/util/encoding.py
@@ -1,4 +1,3 @@
-# Bugs Everywhere, a distributed bugtracker
# Copyright (C) 2008-2009 Gianluca Montecchi <gian@grys.it>
# W. Trevor King <wking@drexel.edu>
#
@@ -62,5 +61,27 @@ def set_IO_stream_encodings(encoding):
sys.stdout = codecs.getwriter(encoding)(sys.__stdout__)
sys.stderr = codecs.getwriter(encoding)(sys.__stderr__)
+
+ def _guess_encoding(self):
+ return encoding.get_encoding()
+ def _check_encoding(value):
+ if value != None:
+ return encoding.known_encoding(value)
+ def _setup_encoding(self, new_encoding):
+ # change hook called before generator.
+ if new_encoding not in [None, settings_object.EMPTY]:
+ if self._manipulate_encodings == True:
+ encoding.set_IO_stream_encodings(new_encoding)
+ def _set_encoding(self, old_encoding, new_encoding):
+ self._setup_encoding(new_encoding)
+ self._prop_save_settings(old_encoding, new_encoding)
+
+ @_versioned_property(name="encoding",
+ doc="""The default input/output encoding to use (e.g. "utf-8").""",
+ change_hook=_set_encoding,
+ generator=_guess_encoding,
+ check_fn=_check_encoding)
+ def encoding(): return {}
+
if libbe.TESTING == True:
suite = doctest.DocTestSuite()