1 |
# Copyright (c) 2003 by Intevation GmbH |
# Copyright (c) 2003, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jonathan Coles <[email protected]> |
4 |
# |
# |
14 |
import os |
import os |
15 |
from types import UnicodeType |
from types import UnicodeType |
16 |
|
|
17 |
|
from Thuban import unicode_from_internal |
18 |
|
|
19 |
# |
# |
20 |
# one level of indention |
# one level of indention |
21 |
# |
# |
121 |
self.file.write(' %s="%s"' % (self.encode(name), |
self.file.write(' %s="%s"' % (self.encode(name), |
122 |
self.encode(value))) |
self.encode(value))) |
123 |
|
|
124 |
def encode(self, str): |
def encode(self, s): |
125 |
"""Return an XML-escaped and UTF-8 encoded copy of the string str.""" |
"""Return an XML-escaped and UTF-8 encoded copy of the string s. |
|
|
|
|
esc = escape(str) |
|
126 |
|
|
127 |
if isinstance(esc, UnicodeType): |
The parameter must be a string in Thuban's internal string |
128 |
return esc.encode("utf8") |
representation or a unicode object. |
129 |
else: |
""" |
130 |
return unicode(escape(str),'latin1').encode("utf8") |
if not isinstance(s, unicode): |
131 |
|
s = unicode_from_internal(s) |
132 |
|
return escape(s).encode("utf8") |