def adapt_schema(db, target_schema): """ Returns a database using the specified 'target_schema', and that maps the content of 'db', thanks to one or more L{Adapter}s. If no suitable adapter can be found, will raise an AdaptError()""" # for the moment, we only resolve direct hits. More clever # resolutions will hopefully be implemented. if db.schema.id == target_schema: return db # search for target_schema in the adapters for the current schema: adapters = Registry.get(db.schema.id, 'adapters') for adapter in adapters: if adapter.target == target_schema: return adapter()(db) raise AdaptError(_("no adaptor for converting a %s into a %s") % ( db.schema.id, target_schema))
def testAdapters(self): c = Registry.get("with-adapter", "adapters") self.failUnlessEqual(len(c), 1) c = c[0] self.failUnlessEqual(c.target, "another/format")
def testCategories(self): c = Registry.get("with-path", "importers") assert len(c) == 2