martin f. krafft | f37f068 | 2013-06-14 16:36:20 +0200 | [diff] [blame] | 1 | # |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
| 4 | # This file is part of reclass (http://github.com/madduck/reclass) |
| 5 | # |
| 6 | # Copyright © 2007–13 martin f. krafft <madduck@madduck.net> |
| 7 | # Released under the terms of the Artistic Licence 2.0 |
| 8 | # |
| 9 | class OutputterBase(object): |
| 10 | |
| 11 | def __init__(self): |
| 12 | pass |
| 13 | |
| 14 | def dump(self, data, pretty_print=False): |
| 15 | raise NotImplementedError, "dump() method not yet implemented" |
| 16 | |
| 17 | |
| 18 | class OutputLoader(object): |
| 19 | |
| 20 | def __init__(self, outputter): |
| 21 | self._name = outputter + '_outputter' |
| 22 | try: |
| 23 | self._module = __import__(self._name, globals(), locals(), |
| 24 | self._name) |
| 25 | except ImportError: |
| 26 | raise NotImplementedError |
| 27 | |
| 28 | def load(self, attr='Outputter'): |
| 29 | klass = getattr(self._module, attr, None) |
| 30 | if klass is None: |
| 31 | raise AttributeError, \ |
| 32 | 'Outputter class {0} does not export "{1}"'.format(self._name, klass) |
| 33 | return klass |