Beispiel #1
0
    def write_tome(self, writer, tome):
        writer.write_string(Defs.TOME_TYPE_ATTR, util.tome_typename(tome.__class__))

        # TODO: template support

        # Write out non-Tome props
        for prop in (prop for prop in util.basic_props(tome) if prop.value is not None):
            marshaller = self.require_data_marshaller(prop.value_type.clazz)
            child_writer = writer if marshaller.is_simple else writer.add_child(prop.name)
            marshaller.write_value(self, child_writer, prop.value, prop.name, prop.value_type)

        # Write Tomes
        for tome in sorted(tome.values(), key=lambda tome: tome.name):
            self.write_tome(writer.add_child(tome.name), tome)
Beispiel #2
0
    def load_tome(self, reader, required_superclass=None):
        name = reader.name
        if not util.valid_library_item_name(name):
            raise LoadError(reader.data, "Invalid tome name [name=%s]" % name)

        typename = reader.get_string(Defs.TOME_TYPE_ATTR, util.tome_typename(Tome))
        tome_class = self.require_tome_class(typename, required_superclass)
        tome = tome_class(name)

        if reader.has_value(Defs.TEMPLATE_ATTR):
            # if this tome has a template, we defer its loading until the end
            self._load_task.pending_templated_tomes.append(TemplatedTome(tome, reader))
        else:
            self._load_tome_now(tome, reader)

        return tome
Beispiel #3
0
 def register_tome_classes(self, classes):
     for clazz in classes:
         if not issubclass(clazz, Tome):
             raise MicrotomeError("Class must extend %s [tome_class=%s]" % (str(Tome), str(clazz)))
         self._tome_classes[util.tome_typename(clazz)] = clazz
         LOG.debug("Registered tome class '%s'" % str(clazz))