Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1003)

Unified Diff: MoinMoin/converter/__init__.py

Issue 6453060: Registry improvements (Closed)
Patch Set: remove decorators Created 12 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | MoinMoin/items/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | MoinMoin/items/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b