xmlclass/xmlclass.py
changeset 1911 c1298e7ffe3a
parent 1571 486f94a8032c
child 1730 64d8f52bc8c8
equal deleted inserted replaced
1910:a375e31bf312 1911:c1298e7ffe3a
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
     4 # This file is part of Beremiz, a Integrated Development Environment for
     5 #based on the plcopen standard. 
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
     6 #
     6 #
     7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
     8 #
     8 #
     9 #See COPYING file for copyrights details.
     9 # See COPYING file for copyrights details.
    10 #
    10 #
    11 #This library is free software; you can redistribute it and/or
    11 # This program is free software; you can redistribute it and/or
    12 #modify it under the terms of the GNU General Public
    12 # modify it under the terms of the GNU General Public License
    13 #License as published by the Free Software Foundation; either
    13 # as published by the Free Software Foundation; either version 2
    14 #version 2.1 of the License, or (at your option) any later version.
    14 # of the License, or (at your option) any later version.
    15 #
    15 #
    16 #This library is distributed in the hope that it will be useful,
    16 # This program is distributed in the hope that it will be useful,
    17 #but WITHOUT ANY WARRANTY; without even the implied warranty of
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 #General Public License for more details.
    19 # GNU General Public License for more details.
    20 #
    20 #
    21 #You should have received a copy of the GNU General Public
    21 # You should have received a copy of the GNU General Public License
    22 #License along with this library; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 import os, sys
    25 import os, sys
    26 import re
    26 import re
    27 import datetime
    27 import datetime
    28 from types import *
    28 from types import *
  1688     
  1688     
  1689     def getLocalTag(self):
  1689     def getLocalTag(self):
  1690         return etree.QName(self.tag).localname
  1690         return etree.QName(self.tag).localname
  1691         
  1691         
  1692     def tostring(self):
  1692     def tostring(self):
  1693         return NAMESPACE_PATTERN.sub("", etree.tostring(self, pretty_print=True))
  1693         return NAMESPACE_PATTERN.sub("", etree.tostring(self, pretty_print=True, encoding='utf-8')).decode('utf-8')
  1694 
  1694 
  1695 class XMLElementClassLookUp(etree.PythonElementClassLookup):
  1695 class XMLElementClassLookUp(etree.PythonElementClassLookup):
  1696     
  1696     
  1697     def __init__(self, classes, *args, **kwargs):
  1697     def __init__(self, classes, *args, **kwargs):
  1698         etree.PythonElementClassLookup.__init__(self, *args, **kwargs)
  1698         etree.PythonElementClassLookup.__init__(self, *args, **kwargs)
  1752             error = self.XSDSchema.error_log.last_error
  1752             error = self.XSDSchema.error_log.last_error
  1753             return tree, (error.line, error.message)
  1753             return tree, (error.line, error.message)
  1754         return tree, None 
  1754         return tree, None 
  1755     
  1755     
  1756     def Dumps(self, xml_obj):
  1756     def Dumps(self, xml_obj):
  1757         return etree.tostring(xml_obj)
  1757         return etree.tostring(xml_obj, encoding='utf-8')
  1758     
  1758     
  1759     def Loads(self, xml_string):
  1759     def Loads(self, xml_string):
  1760         return etree.fromstring(xml_string, self)
  1760         return etree.fromstring(xml_string, self)
  1761     
  1761     
  1762     def CreateRoot(self):
  1762     def CreateRoot(self):