Practice ยท 1 of 1
Exporter plugin framework
Build a small plugin framework. The host provides ExporterBase (below). Plugins subclass it and auto-register.
Requirements:
1. ExporterBase.__init_subclass__ registers subclasses by their name attribute (nonempty str, unique โ duplicates raise ValueError at definition time).
2. Every exporter must implement export(rows) returning a STRING. If a subclass lacks export, raise TypeError at definition time.
3. ExporterBase.create(name) returns an instance or raises KeyError.
4. ExporterBase.names() returns a sorted list of registered names.
5. Provide two built-in plugins: CsvExporter (name='csv', rows of dicts joined as 'k1=v1,k2=v2' with rows on newlines) and JsonLinesExporter (name='jsonl', one compact JSON object per line).
6. Hostile test: registering a plugin named 'csv' again must raise ValueError; a plugin missing export must raise TypeError.
Difficulty: advanced
Back to lesson: Practice: Project: Plugin Framework