Index: MoinMoin/converter/__init__.py |
=================================================================== |
--- a/MoinMoin/converter/__init__.py |
+++ b/MoinMoin/converter/__init__.py |
@@ -19,35 +19,23 @@ |
""" |
+from collections import namedtuple |
+ |
from ..util.registry import RegistryBase |
from ..util.pysupport import load_package_modules |
class RegistryConverter(RegistryBase): |
- class Entry(object): |
- def __init__(self, factory, type_input, type_output, priority): |
- self.factory = factory |
- self.type_input = type_input |
- self.type_output = type_output |
- self.priority = priority |
- |
- def __call__(self, type_input, type_output, kw): |
+ class Entry(namedtuple('Entry', 'factory type_input type_output priority')): |
+ def __call__(self, type_input, type_output, **kw): |
if (self.type_output.issupertype(type_output) and |
self.type_input.issupertype(type_input)): |
return self.factory(type_input, type_output, **kw) |
- def __eq__(self, other): |
- if isinstance(other, self.__class__): |
- return (self.factory == other.factory and |
- self.type_input == other.type_input and |
- self.type_output == other.type_output and |
- self.priority == other.priority) |
- return NotImplemented |
- |
def __lt__(self, other): |
if isinstance(other, self.__class__): |
- if self.priority < other.priority: |
- return True |
+ if self.priority != other.priority: |
+ return self.priority < other.priority |
if self.type_output != other.type_output: |
return other.type_output.issupertype(self.type_output) |
if self.type_input != other.type_input: |
@@ -55,19 +43,6 @@ |
return False |
return NotImplemented |
- def __repr__(self): |
- return '<{0}: input {1}, output {2}, prio {3} [{4!r}]>' % (self.__class__.__name__, |
- self.type_input, |
- self.type_output, |
- self.priority, |
- self.factory) |
- |
- def get(self, type_input, type_output, **kw): |
- for entry in self._entries: |
- conv = entry(type_input, type_output, kw) |
- if conv is not None: |
- return conv |
- |
def register(self, factory, type_input, type_output, priority=RegistryBase.PRIORITY_MIDDLE): |
""" |
Register a factory |