From: Christopher Lenz Date: Fri, 6 Jun 2008 21:22:29 +0000 (+0000) Subject: Allow extraction method specification to use a dot instead of the colon for separatin... X-Git-Tag: 1.0~346 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee66c9c40ab891815ea078d17f7c5ac2f44d2cdb;p=thirdparty%2Fbabel.git Allow extraction method specification to use a dot instead of the colon for separating module and function names. See #105. --- diff --git a/babel/messages/extract.py b/babel/messages/extract.py index 5f334709..7383a097 100644 --- a/babel/messages/extract.py +++ b/babel/messages/extract.py @@ -205,8 +205,9 @@ def extract(method, fileobj, keywords=DEFAULT_KEYWORDS, comment_tags=(), :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 @@ def extract(method, fileobj, keywords=DEFAULT_KEYWORDS, comment_tags=(), :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)