/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/xmlwriter.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/xmlwriter.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1171 by jonathan, Thu Jun 12 12:52:37 2003 UTC revision 2642 by bh, Fri Jul 1 20:49:04 2005 UTC
# Line 1  Line 1 
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  #  #
# Line 11  Functions to save an XML file Line 11  Functions to save an XML file
11    
12  __version__ = "$Revision$"  __version__ = "$Revision$"
13    
14  import os, string  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  #  #
# Line 22  TAB = "    " Line 24  TAB = "    "
24  def escape(data):  def escape(data):
25      """Escape &, \", ', <, and > in a string of data.      """Escape &, \", ', <, and > in a string of data.
26      """      """
27      data = string.replace(data, "&", "&amp;")      data = data.replace("&", "&amp;")
28      data = string.replace(data, "<", "&lt;")      data = data.replace("<", "&lt;")
29      data = string.replace(data, ">", "&gt;")      data = data.replace(">", "&gt;")
30      data = string.replace(data, '"', "&quot;")      data = data.replace('"', "&quot;")
31      data = string.replace(data, "'", "&apos;")      data = data.replace("'", "&apos;")
32      return data      return data
33    
34  class XMLWriter:  class XMLWriter:
# Line 119  class XMLWriter: Line 121  class XMLWriter:
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")

Legend:
Removed from v.1171  
changed lines
  Added in v.2642

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26