bh: thuban/Thuban __init__.py,1.4,1.5
cvs@intevation.de
cvs at intevation.de
Fri Jul 1 22:49:06 CEST 2005
Author: bh
Update of /thubanrepository/thuban/Thuban
In directory doto:/tmp/cvs-serv11857/Thuban
Modified Files:
__init__.py
Log Message:
First step towards unicode. With this roughly we're at step 1
string_representation.txt
* Doc/technotes/string_representation.txt: New. Document how
strings are represented in Thuban and how to get to a Unicode
Thuban.
* Thuban/__init__.py (set_internal_encoding)
(unicode_from_internal, internal_from_unicode): New. The first few
functions for the internal string representation
* Thuban/UI/about.py (unicodeToLocale): Removed. Use
internal_from_unicode instead.
* Thuban/UI/__init__.py (install_wx_translation): Determine the
encoding to use for the internal string representation. Also,
change the translation function to return strings in internal
representation even on unicode builds of wxPython
* Thuban/Model/load.py (SessionLoader.check_attrs): Decode
filenames too.
(SessionLoader.start_clrange): Use check_attrs to decode and check
the attributes.
* Thuban/Model/xmlreader.py (XMLReader.encode): Use
internal_from_unicode to convert unicode strings.
* Thuban/Model/xmlwriter.py (XMLWriter.encode): Use
unicode_from_internal when applicable
* test/runtests.py (main): New command line option:
internal-encoding to specify the internal string encoding to use
in the tests.
* test/support.py (initthuban): Set the internal encoding to
latin-1
* test/test_load.py (TestSingleLayer.test, TestClassification.test)
(TestLabelLayer.test): Use the internal string representation when
dealing with non-ascii characters
* test/test_load_1_0.py (TestSingleLayer.test)
(TestClassification.test, TestLabelLayer.test): Use the internal
string representation when dealing with non-ascii characters
* test/test_load_0_9.py (TestSingleLayer.test)
(TestClassification.test): Use the internal string representation
when dealing with non-ascii characters
* test/test_load_0_8.py (TestUnicodeStrings.test): Use the
internal string representation when dealing with non-ascii
characters
* test/test_save.py (XMLWriterTest.testEncode)
(SaveSessionTest.testClassifiedLayer): Use the internal string
representation when dealing with non-ascii characters where
applicable
Index: __init__.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- __init__.py 27 Oct 2003 17:11:06 -0000 1.4
+++ __init__.py 1 Jul 2005 20:49:04 -0000 1.5
@@ -1,4 +1,4 @@
-# Copyright (c) 2001, 2003 by Intevation GmbH
+# Copyright (c) 2001, 2003, 2005 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh at intevation.de>
# Jan-Oliver Wagner <jan at intevation.de>
@@ -74,3 +74,49 @@
global _translation_function
if not translation_function_installed():
_translation_function = function
+
+
+
+# String representation in Thuban
+#
+# Thuban has an internal representation for textual data that all text
+# that comes into Thuban has to be converted into. Any text written by
+# Thuban has to be converted to whatever is needed by the output device.
+#
+# Currently, the internal representation is usually a byte-string in a
+# particuler encoding. For more details see the file
+# Doc/technotes/string_representation.txt.
+
+# The encoding to use for the internal string representation. Usually
+# it's a string with the encoding name to use when converting between
+# Python byte-strings and unicode objects. The special value "unicode"
+# means the use unicode objects as the internal representation.
+_internal_encoding = None
+
+def internal_from_unicode(unistr):
+ """Return Thuban's internal representation for the unicode object unistr"""
+ if _internal_encoding != "unicode":
+ # we use replace so that we don't get exceptions when the
+ # conversion can't be done properly.
+ return unistr.encode(_internal_encoding, "replace")
+ else:
+ return unistr
+
+def unicode_from_internal(s):
+ """Return the unicode object for the string s in internal representation"""
+ if _internal_encoding != "unicode":
+ return unicode(s, _internal_encoding)
+ else:
+ return s
+
+
+def set_internal_encoding(encoding):
+ """Set the encoding to use for the internal string representation
+
+ The parameter should be the name of an encoding known to Python so
+ that it can be used with e.g. the encode method of unicode objects.
+ As a special case it can be the string 'unicode' to indicate that
+ the internal representation are unicode objects.
+ """
+ global _internal_encoding
+ _internal_encoding = encoding
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)