Exemplo n.º 1
0
 def __repr__(self) :
     a = self.impl
     length = len(self)
     numeric_typecode = self.numeric_typecode
     out = "array(["
     for ii in xrange(0, length) :
         out += pretty.NumericString_(numeric_typecode, self[ii]) 
         if ii!=length-1 : out += ","
     out += "], "+repr(numeric_typecode)+")"
     return out
Exemplo n.º 2
0
 def _XMLContentFilter(self, content, was_array_typecode=None):
     result = ""  # RVO
     typecode = {float: 'd', complex: 'D'}
     type_content = type(content)
     if was_array_typecode != None:
         t = pretty.NumericString_(was_array_typecode, content)
     elif type_content in [float, complex]:
         t = pretty.NumericString_(typecode[type_content], content)
     elif type_content == long:
         t = repr(content)
     else:
         t = str(content)
     for ii in xrange(0, len(t)):
         c = t[ii]
         if not isprint(c):
             result += "&#" + hex(ord(c))[1:] + ";"
         else:
             if c in self.specialCharToEscapeSeq_:
                 esc_seq = self.specialCharToEscapeSeq_[t[ii]]
                 result = result + esc_seq
             else:
                 result = result + t[ii]
     return result
Exemplo n.º 3
0
    def _XMLDumpPODList(self, list_name, l, indent, inside_list_number,
                        add_type):
        # tag = str(list_name)
        tag = list_name
        oc_typecode = self._OC_typecode_(l)

        # Check to see if we want to dump this as a LIST or plain POD array
        if self.arrDisp_ == ARRAYDISPOSITION_AS_LIST:

            l = l.tolist()

            # float types: important for -> string to not lose precision
            was_array_typecode = None
            if oc_typecode in ['f', 'F', 'd', 'D']:
                was_array_typecode = oc_typecode
            else:
                l = [int(x) for x in l]

            self._XMLDumpList(list_name, l, indent, was_array_typecode)
            return

        # The attributes for an Array of POD will the Numeric type tag
        attrs = {}
        bytetag = oc_typecode
        if (self.options_ & XML_DUMP_POD_LIST_AS_XML_LIST):
            attrs["type__"] = bytetag
        else:
            attrs["arraytype__"] = bytetag

        # There are two ways to dump Array data: either as one tag
        # with a list of numbers, or a tag for for every number.
        # Dumping array data with a tag for every number works better with
        # other tools (spreasheet etc.), but if you annotate EVERY ELEMENT
        # of a long list, the XML becomes much bigger and slow.

        # Dump array with a tag for EVERY element
        primitive_type = True
        temp = None
        inner_tag = tag
        if (self.options_ & XML_DUMP_POD_LIST_AS_XML_LIST):
            # Rare case when POD array inside list
            if (inside_list_number != -1):
                inner_attrs = {}
                if inside_list_number == 0 and add_type:
                    inner_attrs["type__"] = "list"
                self._XMLDumpStartTag(tag, inner_attrs, indent, False)
                inner_tag = "list" + str(inside_list_number) + "__"
                indent += self.indentIncrement_

            if len(l) == 0:
                # Empty list
                self._XMLDumpStartTag(inner_tag, attrs, indent, primitive_type)
                self._XMLDumpEndTag(inner_tag, indent, primitive_type)
            else:
                # Non-empty list
                for ii in xrange(0, len(l)):
                    self._XMLDumpStartTag(inner_tag, attrs, indent,
                                          primitive_type)
                    temp = pretty.NumericString_(
                        bytetag, l[ii]
                    )  #repr(l[ii])  # so prints with full precision of Val for reals, etc.
                    self.os_.write(temp)
                    self._XMLDumpEndTag(inner_tag, indent, primitive_type)

            # Rare case when POD array inside list
            if (inside_list_number != -1):
                indent -= self.indentIncrement_
                self._XMLDumpEndTag(tag, indent, False)

        # Dump as a list of numbers with just one tag: the tag, the list of data,
        # then the end tag
        else:
            if (inside_list_number == 0 and add_type): attrs["type__"] = "list"
            self._XMLDumpStartTag(tag, attrs, indent, primitive_type)
            for ii in xrange(0, len(l)):
                temp = pretty.NumericString_(
                    bytetag, l[ii]
                )  #repr(l[ii])  # so prints with full precision of Val for reals, etc.
                self.os_.write(temp)
                if (ii < len(l) - 1): self.os_.write(",")
            # End
            self._XMLDumpEndTag(tag, indent, primitive_type)