コード例 #1
0
 def text2html(self, text):
     sl = []
     sl.append("    <PRE>")
     text = typesx.replace(text, "&", "&amp;")
     sl.append(typesx.replace(text, "<", "&lt;"))
     sl.append("    </PRE>")
     return typesx.join(sl, "\n")
コード例 #2
0
def list2packed(lst):
    str_list = []
    add_item = str_list.append
    for item in lst:
        type_str, str_value, end_type = to_string_and_type(item)
        add_item('%s%s%s' % (type_str, str_value, end_type))
    return typesx.join(str_list, "")
コード例 #3
0
 def obj2xml(self, obj, indent):
     """this encodes mappings"""
     str_list = []
     add_line = str_list.append
     for name, value in list(obj.items()):
         if value is not None:
             if name == "parent":
                 str_type = "string"
                 if type(value) == StringType:
                     str_value = self.to_string(value)
                 else:
                     str_value = self.to_string(value.id)
             else:
                 str_type = get_atlas_type(value)
                 add_nl = 0
                 if str_type == "map":
                     str_value = self.obj2xml(value, indent + "\t")
                     if str_value: add_nl = 1
                 elif str_type == "list":
                     str_value = self.list2xml(value, indent + "\t")
                     if typesx.find(str_value, "\t") >= 0: add_nl = 1
                 else:
                     #int/float/string
                     str_value = self.to_string(value)
                 if add_nl: str_value = "\n%s\n%s" % (str_value, indent)
             add_line(
                 self.encode_attribute(indent, name, str_type, str_value))
     return typesx.join(str_list, "\n")
コード例 #4
0
def classize(id, data=0):
    if id is None:
        return "BaseObject"
    if type(id) != typesx.StringType: id = id.id
    cid = typesx.join(list(map(capitalize_only, typesx.split(id, '_'))), "")
    if data: return cid + "Data"
    return cid
コード例 #5
0
def map2packed(obj):
    """this encodes mappings"""
    str_list = []
    add_item = str_list.append
    for name, value in list(obj.items()):
        type_str, str_value, end_type = to_string_and_type(value)
        add_item('%s%s=%s%s' % (type_str, name, str_value, end_type))
    return typesx.join(str_list, "")
コード例 #6
0
 def __str__(self):
     s = []
     points = self.get_points()
     for i in range(len(points) - 1):
         p1 = points[i]
         p2 = points[i + 1]
         s.append("L %i %f %f %f %f\n" %
                  (self.color, p1[0], p1[1], p2[0], p2[1]))
     return typesx.join(s, "")
コード例 #7
0
def dxf2atlas(infile, outfile, outfile_media=None):
    if outfile_media == None:
        outfile_media = typesx.join(typesx.split(outfile, ".", 2), "_media.")
        if outfile == outfile_media:
            raise_(ValueError, "outfile==outfile_media: %s" % outfile_media)
    print(infile, "->", outfile, outfile_media)
    dxf = ReadDxf(infile)
    dxf.read()
    dxf.write(outfile, outfile_media)
コード例 #8
0
 def list2xml(self, lst, indent):
     str_list = []
     add_item = str_list.append
     complex_in_list = 0
     for item in lst:
         str_type = get_atlas_type(item)
         if str_type == "map":
             complex_in_list = 1
             add_item("<map>\n%s\n%s</map>" % \
                      (self.obj2xml(item, indent+"\t"), indent))
         elif str_type == "list":
             complex_in_list = 1
             add_item("<list>%s</list>" % \
                      self.list2xml(item, indent+"\t"))
         else:
             #int/float/string
             add_item("<%s>%s</%s>" %
                      (str_type, self.to_string(item), str_type))
     if complex_in_list:
         str_list = list(map(lambda s, i=indent: i + s, str_list))
         return typesx.join(str_list, "\n")
     else:
         return typesx.join(str_list, "")
コード例 #9
0
 def output_obj(self, obj):
     lines = []
     add_line = lines.append
     add_line('    <a name="%s"><h2>%s</h2></a>' % (obj.id, obj.id))
     add_line('    Attribute list:')
     add_line('    <ul>')
     for (name, value) in obj.items(all=1):
         s = '      <li><b><a href="type.html#%s">%s</a> ' % (name, name)
         attribute_def_obj = obj.attribute_definition(name)
         if attribute_def_obj != obj:
             s = s + '(inherited from %s) ' % attribute_def_obj.id
         if has_parent(name, "html", self.objects):
             value = '<br>\n' + value + '<br>\n'
         elif name == "example":
             value_list = ["<br>"]
             for example_obj in value:
                 if get_atlas_type(example_obj) == "string":
                     value_list.append(example_obj)
                 else:
                     bach = str(example_obj)
                     value_list.append("<pre>")
                     value_list.append(self.text2html(bach))
                     value_list.append("</pre>")
             value_list.append("<br>")
             value = typesx.join(value_list, "\n")
         elif get_atlas_type(value) == "map":
             value = repr(value)
         s=s+'(encoding:<a href="type.html#%s">%s</a>):</b> Value: <font color="green">%s</font> ' % \
            (get_atlas_type(value), get_atlas_type(value), value)
         s = s + self.objects[name].description
         add_line(s)
     add_line('    </ul>')
     add_line('')
     self.out(typesx.join(lines, "\n"))
     self.out("    Bach version:<br>\n")
     bach = str(obj)
     self.out(self.text2html(bach))
コード例 #10
0
 def __call__(self, object):
     if self.stream_flag:
         if isinstance(object, atlas.Messages):
             slst = []
             for obj in object:
                 slst.append(self(obj))
             return typesx.join(slst, "")
         str = self.encode1stream(object)
         if self.stream_begin_sent:
             str = self.middle_string + str
         else:
             self.stream_begin_sent = 1
             str = self.begin_string + str
         return str
     else:
         return self.encode1(object)
コード例 #11
0
 def ns_close(self, ns_list):
     for i in range(0, len(ns_list)):
         self.write("} ")
     self.write("// namespace " + typesx.join(ns_list, "::"))
     self.write("\n")
コード例 #12
0
 def footer(self, list):
     guard = typesx.join(list(map(typesx.upper, list)), "_")
     self.write("\n#endif // " + guard + "\n")
コード例 #13
0
 def encode1stream(self, object):
     return typesx.join(to_string_and_type(object), "") + "\n"
コード例 #14
0
 def __str__(self):
     s = []
     for ent in self:
         ent.color = self.color
         s.append(str(ent))
     return typesx.join(s, "")
コード例 #15
0
 def iwill(self, codecs):
     return typesx.join(["IWILL %s\n" % c for c in codecs],
                        "") + '\n'  # Fixes negotiation /Demitar
コード例 #16
0
 def ican(self, codecs):
     return typesx.join(["ICAN %s\n" % c for c in codecs],
                        "") + '\n'  # Fixes negotiation /Demitar
コード例 #17
0
 def header(self, list, copyright=copyright):
     self.write(copyright)
     self.write("\n")
     guard = typesx.join(list(map(typesx.upper, list)), "_")
     self.write("#ifndef " + guard + "\n")
     self.write("#define " + guard + "\n\n")