def __getattr__(self, name):
"""\
This is used to plug-in external serializers.
When a "to_<name>" method is invoked, this method tries to find
a ``segno.plugin.converter`` plugin with the provided ``<name>``.
If such a plugin exists, a callable function is returned. The result
of invoking the function depends on the plugin.
"""
if name.startswith('to_'):
from pkg_resources import iter_entry_points
from functools import partial
for ep in iter_entry_points(group='segno.plugin.converter',
name=name[3:]):
plugin = ep.load()
return partial(plugin, self)
raise AttributeError('{0} object has no attribute {1}'
.format(self.__class__, name))
评论列表
文章目录