Mercurial > babel > old > mirror
changeset 331:852cd3703113
Allow extraction method specification to use a dot instead of the colon for separating module and function names. See #105.
author | cmlenz |
---|---|
date | Fri, 06 Jun 2008 21:22:29 +0000 |
parents | 9809b94b7d88 |
children | a7dff175b14f |
files | babel/messages/extract.py |
diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -205,8 +205,9 @@ :param method: 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``), the - corresponding function will be imported and used + to a function (of the form ``package.module:funcname`` or + ``package.module.funcname``), the corresponding function + will be imported and used :param fileobj: the file-like object the messages should be extracted from :param keywords: a dictionary mapping keywords (i.e. names of functions that should be recognized as translation functions) to @@ -220,6 +221,16 @@ :raise ValueError: if the extraction method is not registered """ func = None + if ':' in method or '.' in method: + if ':' not in method: + lastdot = method.rfind('.') + module, attrname = method[:lastdot], method[lastdot + 1:] + else: + module, attrname = method.split(':', 1) + func = getattr(__import__(module, {}, {}, [attrname]), attrname) + elif '.' in method: + parts = method.split('.') + clsname if ':' in method: module, clsname = method.split(':', 1) func = getattr(__import__(module, {}, {}, [clsname]), clsname)