... print message
(3, u'Hello, world!', [], None)
- :param method: a string specifying the extraction method (.e.g. "python");
+ :param method: an extraction method (a callable), or
+ a string specifying the extraction method (.e.g. "python");
if this is a simple name, the extraction function will be
looked up by entry point; if it is an explicit reference
to a function (of the form ``package.module:funcname`` or
:raise ValueError: if the extraction method is not registered
"""
func = None
- if ':' in method or '.' in method:
+ if callable(method):
+ func = method
+ elif ':' in method or '.' in method:
if ':' not in method:
lastdot = method.rfind('.')
module, attrname = method[:lastdot], method[lastdot + 1:]
'javascript': extract_javascript
}
func = builtin.get(method)
+
if func is None:
raise ValueError('Unknown extraction method %r' % method)
assert 'warning: Empty msgid.' in sys.stderr.getvalue()
finally:
sys.stderr = stderr
+
+ def test_extract_allows_callable(self):
+ def arbitrary_extractor(fileobj, keywords, comment_tags, options):
+ return [(1, None, (), ())]
+ for x in extract.extract(arbitrary_extractor, BytesIO(b"")):
+ assert x[0] == 1