]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Allow extraction method specification to use a dot instead of the colon for separatin...
authorChristopher Lenz <cmlenz@gmail.com>
Fri, 6 Jun 2008 21:22:29 +0000 (21:22 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Fri, 6 Jun 2008 21:22:29 +0000 (21:22 +0000)
babel/messages/extract.py

index 5f334709be0ba7879f2d0c41c3d1bdeb9444a797..7383a097e42b2e57e0a50437c00888b4e3f4f1f6 100644 (file)
@@ -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)