Beispiel #1
0
 def _get_xml_string(self, everything=True, space='', deleted=False):
     s = UnicodeStringWriter()
     for entry in self._entries:
         if not entry.is_changed() and not everything:
             continue
         s._write_output(entry._get_xml_string(everything, space, False))
     for entry in self.values_deleted():
         s._write_output(entry._get_xml_string(True, space, True))
     return s.getvalue()
Beispiel #2
0
    def _get_xml_string(self, everything=True, space='', deleted=False):
        s = UnicodeStringWriter()
        if not self._fname:
            # group object!!
            for i in self.Properties:
                if not self.__dict__[i].is_changed() and not everything:
                    continue
                attr_name = i
                if attr_name in self._ign_fields:
                    continue
                if '_' in attr_name:
                    attr_name = re.sub('_.*', '', attr_name)
                    attr_name = "{0}.{1}#{2}".format(self._alias, self._index,
                                                     attr_name)
                else:
                    attr_name = "{0}".format(attr_name)
                if isinstance(self.__dict__[i], FieldType):
                    if self.__dict__[i]._composite:
                        continue
                    if not self.__dict__[i]._modifyAllowed and deleted:
                        continue
                    value = TypeHelper.resolve(self.__dict__[i]._value)
                    if deleted: value = self.__dict__[i]._default_on_delete
                    s._write_output(
                        '  <Attribute Name="{0}">{1}</Attribute>\n'.format(
                            attr_name, value))
                else:
                    s._write_output(self.__dict__[i]._get_xml_string(
                        everything, space + '  ', deleted))
            return s.getvalue()

        s._write_output(space + '<{0}'.format(self._fname))
        for i in self._attribs:
            if i not in self._ign_attribs:
                s._write_output(' {0}="{1}"'.format(i, self._attribs[i]))
        s._write_output('>\n')

        orig_len = len(s.getvalue())
        for i in self.Properties:
            if not self.__dict__[i].is_changed() and not everything:
                continue
            attr_name = i
            if attr_name in self._ign_fields:
                continue
            if isinstance(self.__dict__[i], FieldType):
                if not self.__dict__[i]._composite:
                    if not self.__dict__[i]._modifyAllowed and deleted:
                        continue
                    value = TypeHelper.resolve(self.__dict__[i]._value)
                    if deleted: value = self.__dict__[i]._default_on_delete
                    values = [value]
                    if self.__dict__[i]._list:
                        values = value.split(',')
                    for val in values:
                        s._write_output(
                            space +
                            '  <Attribute Name="{0}">{1}</Attribute>\n'.format(
                                attr_name, val))
            else:
                s._write_output(self.__dict__[i]._get_xml_string(
                    everything, space + '  ', deleted))
        new_len = len(s.getvalue())
        if new_len == orig_len:
            return ""

        s._write_output(space + '</{0}>\n'.format(self._fname))
        return s.getvalue()
Beispiel #3
0
 def format_scp(self, desiredcfg):
     with UnicodeStringWriter() as output:
         self._spit_scp(desiredcfg, output)
         return output.getvalue()