]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
* Removed pkg_resources/setuptools requirement from various places.
authorChristopher Lenz <cmlenz@gmail.com>
Thu, 31 May 2007 08:38:54 +0000 (08:38 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Thu, 31 May 2007 08:38:54 +0000 (08:38 +0000)
 * Fixed copyright year in a couple of file headers.
 * Some cleanup.

16 files changed:
babel/__init__.py
babel/catalog/extract.py
babel/catalog/frontend.py
babel/catalog/tests/__init__.py
babel/catalog/tests/extract.py
babel/catalog/tests/frontend.py [new file with mode: 0644]
babel/catalog/tests/pofile.py
babel/core.py
babel/dates.py
babel/tests/__init__.py
babel/tests/core.py
babel/tests/dates.py
babel/tests/numbers.py
babel/tests/util.py
doc/style/epydoc.css
setup.py

index f74dcbf4aa286c2a8ebedb97ee4f7224ca3f02f1..de8b59a3c3d08ed3fea7b459bcf83ae30e6ba27e 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
@@ -29,4 +29,7 @@ This package is basically composed of two major parts:
 from babel.core import *
 
 __docformat__ = 'restructuredtext en'
-__version__ = __import__('pkg_resources').get_distribution('Babel').version
+try:
+    __version__ = __import__('pkg_resources').get_distribution('Babel').version
+except ImportError:
+    pass
index ec26a88f5a21c407963e9260314040f5495d835e..7970c17f95e0dd3be8e9d38e68a306d7398fa08c 100644 (file)
@@ -22,7 +22,6 @@ The main entry points into the extraction functionality are the functions
 """
 
 import os
-from pkg_resources import working_set
 import sys
 from tokenize import generate_tokens, NAME, OP, STRING
 
@@ -33,7 +32,7 @@ __docformat__ = 'restructuredtext en'
 
 GROUP_NAME = 'babel.extractors'
 
-KEYWORDS = {
+DEFAULT_KEYWORDS = {
     '_': None,
     'gettext': None,
     'ngettext': (1, 2),
@@ -49,8 +48,8 @@ DEFAULT_MAPPING = {
 }
 
 
-def extract_from_dir(dirname, mapping=DEFAULT_MAPPING, keywords=KEYWORDS,
-                     options=None):
+def extract_from_dir(dirname, mapping=DEFAULT_MAPPING,
+                     keywords=DEFAULT_KEYWORDS, options=None):
     """Extract messages from any source files found in the given directory.
     
     This function generates tuples of the form:
@@ -80,8 +79,10 @@ def extract_from_dir(dirname, mapping=DEFAULT_MAPPING, keywords=KEYWORDS,
     :param dirname: the path to the directory to extract messages from
     :param mapping: a mapping of extraction method names to extended glob
                     patterns
-    :param keywords: a list of keywords (i.e. function names) that should be
-                     recognized as translation functions
+    :param keywords: a dictionary mapping keywords (i.e. names of functions
+                     that should be recognized as translation functions) to
+                     tuples that specify which of their arguments contain
+                     localizable strings
     :param options: a dictionary of additional options (optional)
     :return: an iterator over ``(filename, lineno, funcname, message)`` tuples
     :rtype: ``iterator``
@@ -99,7 +100,8 @@ def extract_from_dir(dirname, mapping=DEFAULT_MAPPING, keywords=KEYWORDS,
                     yield filename, line, func, key
                 extracted_files[filename] = True
 
-def extract_from_file(method, filename, keywords=KEYWORDS, options=None):
+def extract_from_file(method, filename, keywords=DEFAULT_KEYWORDS,
+                      options=None):
     """Extract messages from a specific file.
     
     This function returns a list of tuples of the form:
@@ -108,8 +110,10 @@ def extract_from_file(method, filename, keywords=KEYWORDS, options=None):
     
     :param filename: the path to the file to extract messages from
     :param method: a string specifying the extraction method (.e.g. "python")
-    :param keywords: a list of keywords (i.e. function names) that should be
-                     recognized as translation functions
+    :param keywords: a dictionary mapping keywords (i.e. names of functions
+                     that should be recognized as translation functions) to
+                     tuples that specify which of their arguments contain
+                     localizable strings
     :param options: a dictionary of additional options (optional)
     :return: the list of extracted messages
     :rtype: `list`
@@ -120,7 +124,7 @@ def extract_from_file(method, filename, keywords=KEYWORDS, options=None):
     finally:
         fileobj.close()
 
-def extract(method, fileobj, keywords=KEYWORDS, options=None):
+def extract(method, fileobj, keywords=DEFAULT_KEYWORDS, options=None):
     """Extract messages from the given file-like object using the specified
     extraction method.
     
@@ -143,28 +147,32 @@ def extract(method, fileobj, keywords=KEYWORDS, options=None):
     
     :param method: a string specifying the extraction method (.e.g. "python")
     :param fileobj: the file-like object the messages should be extracted from
-    :param keywords: a list of keywords (i.e. function names) that should be
-                     recognized as translation functions
+    :param keywords: a dictionary mapping keywords (i.e. names of functions
+                     that should be recognized as translation functions) to
+                     tuples that specify which of their arguments contain
+                     localizable strings
     :param options: a dictionary of additional options (optional)
     :return: the list of extracted messages
     :rtype: `list`
     :raise ValueError: if the extraction method is not registered
     """
+    from pkg_resources import working_set
+
     for entry_point in working_set.iter_entry_points(GROUP_NAME, method):
         func = entry_point.load(require=True)
         m = []
         for lineno, funcname, messages in func(fileobj, keywords.keys(),
                                                options=options or {}):
             if isinstance(messages, (list, tuple)):
-                indices = keywords[funcname]
                 msgs = []
-                for indice in indices:
-                    msgs.append(messages[indice-1])
+                for index in keywords[funcname]:
+                    msgs.append(messages[index - 1])
                 messages = tuple(msgs)
                 if len(messages) == 1:
                     messages = messages[0]
             yield lineno, funcname, messages
         return
+
     raise ValueError('Unknown extraction method %r' % method)
 
 def extract_genshi(fileobj, keywords, options):
index 00ca8ac51ec69fac11a9022828ec8d46e5e0b9d4..ab9ea1333158fc5b35daba484e19c60be7e42ef6 100644 (file)
@@ -20,7 +20,7 @@ import os
 import sys
 
 from babel import __version__ as VERSION
-from babel.catalog.extract import extract_from_dir, KEYWORDS
+from babel.catalog.extract import extract_from_dir, DEFAULT_KEYWORDS
 from babel.catalog.pofile import write_po
 
 __all__ = ['extract_messages', 'main']
@@ -53,7 +53,7 @@ class extract_messages(Command):
          'space-separated list of keywords to look for in addition to the '
          'defaults'),
         ('no-default-keywords', None,
-         'do not include the default keywords defined by Babel'),
+         'do not include the default keywords'),
         ('no-location', None,
          'do not include location comments with filename and line number'),
         ('omit-header', None,
@@ -61,28 +61,27 @@ class extract_messages(Command):
         ('output-file=', 'o',
          'name of the output file'),
     ]
-    boolean_options = ['no-location', 'omit-header', 'no-default-keywords']
+    boolean_options = ['no-default-keywords', 'no-location', 'omit-header']
 
     def initialize_options(self):
         self.charset = 'utf-8'
-        self.keywords = KEYWORDS
+        self.keywords = DEFAULT_KEYWORDS.copy()
+        self.no_default_keywords = False
         self.no_location = False
         self.omit_header = False
         self.output_file = None
         self.input_dirs = None
-        self.no_default_keywords = False
 
     def finalize_options(self):
         if not self.input_dirs:
             self.input_dirs = dict.fromkeys([k.split('.',1)[0]
                 for k in self.distribution.packages
             ]).keys()
+        if self.no_default_keywords:
+            self.keywords = {}
         if isinstance(self.keywords, basestring):
-            new_keywords = [k.strip() for k in self.keywords.split()]
-            self.keywords = build_gettext_functions(
-                                    new_keywords,
-                                    dont_include_default=self.no_default_keywords
-            )
+            new_keywords = parse_keywords(self.keywords.split())
+            self.keywords.update(new_keywords)
 
     def run(self):
         outfile = open(self.output_file, 'w')
@@ -102,25 +101,6 @@ class extract_messages(Command):
         finally:
             outfile.close()
 
-def build_gettext_functions(func_list=[], dont_include_default=False):
-    """Build the gettext function to parse."""
-    if dont_include_default:
-        func_dict = {}
-    else:
-        func_dict = KEYWORDS
-    for func in func_list:
-        if func.find(':') != -1:
-            func_name, func_args = func.split(':')
-        else:
-            func_name, func_args = func, None
-        if not func_dict.has_key(func_name):
-            if func_args:
-                str_indexes = [(int(x) -1 ) for x in func_args.split(',')]
-            else:
-                str_indexes = None
-            func_dict[func_name] = str_indexes
-    return func_dict
-                
 def main(argv=sys.argv):
     """Command-line interface.
     
@@ -159,14 +139,15 @@ def main(argv=sys.argv):
         outfile = open(options.output, 'w')
     else:
         outfile = sys.stdout
-        
-    if options.no_default_keywords and not options.keywords:
-        parser.error("you must pass keywords to disable the default ones")
-    elif options.no_default_keywords and options.keywords:
-        keywords = build_gettext_functions(options.keywords,
-                            dont_include_default=options.no_default_keywords)
-    else:
-        keywords = build_gettext_functions()
+
+    keywords = DEFAULT_KEYWORDS.copy()
+    if options.no_default_keywords:
+        if not options.keywords:
+            parser.error('you must specify new keywords if you disable the '
+                         'default ones')
+        keywords = {}
+    if options.keywords:
+        keywords.update(parse_keywords(options.keywords))
 
     try:
         messages = []
@@ -184,5 +165,27 @@ def main(argv=sys.argv):
         if options.output:
             outfile.close()
 
+def parse_keywords(strings=[]):
+    """Parse keywords specifications from the given list of strings.
+    
+    >>> kw = parse_keywords(['_', 'dgettext:2', 'dngettext:2,3'])
+    >>> for keyword, indices in sorted(kw.items()):
+    ...     print (keyword, indices)
+    ('_', None)
+    ('dgettext', (2,))
+    ('dngettext', (2, 3))
+    """
+    keywords = {}
+    for string in strings:
+        if ':' in string:
+            funcname, indices = string.split(':')
+        else:
+            funcname, indices = string, None
+        if funcname not in keywords:
+            if indices:
+                indices = tuple([(int(x)) for x in indices.split(',')])
+            keywords[funcname] = indices
+    return keywords
+
 if __name__ == '__main__':
     main()
index a371f64e46a454afbdef90d9971756d58211f66a..429bb35583145e71c9c88c8c08306cb3e618a3e2 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
 import unittest
 
 def suite():
-    from babel.catalog.tests import extract, pofile
+    from babel.catalog.tests import extract, frontend, pofile
     suite = unittest.TestSuite()
     suite.addTest(extract.suite())
+    suite.addTest(frontend.suite())
     suite.addTest(pofile.suite())
     return suite
 
index 8c9fcfbf9cd9c3b1da56fdc2c98cd27698101260..45144aa40cda7a7276dbe5df2ac44d654b202d30 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
diff --git a/babel/catalog/tests/frontend.py b/babel/catalog/tests/frontend.py
new file mode 100644 (file)
index 0000000..23bf692
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007 Edgewall Software
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://babel.edgewall.org/wiki/License.
+#
+# This software consists of voluntary contributions made by many
+# individuals. For the exact contribution history, see the revision
+# history and logs, available at http://babel.edgewall.org/log/.
+
+import doctest
+import unittest
+
+from babel.catalog import frontend
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(doctest.DocTestSuite(frontend))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')
index c8958e00b0cb0c27f769f11f98c45f72e9021bb7..7152df3aab93fafbdb2ddefce3a1180afb020a06 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
index c07b94578eeb53860f9bff6f0099ea2607e6c8ba..2a59fd6f66d977da8e5b41bc0df8ca96e9b5378b 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
@@ -13,8 +13,8 @@
 
 """Core locale representation and locale data access gateway."""
 
+import os
 import pickle
-from pkg_resources import resource_filename
 try:
     import threading
 except ImportError:
@@ -129,7 +129,8 @@ class Locale(object):
 
     def _data(self):
         if self.__data is None:
-            filename = resource_filename(__name__, 'localedata/%s.dat' % self)
+            filename = os.path.join(os.path.dirname(__file__),
+                                    'localedata/%s.dat' % self)
             fileobj = open(filename, 'rb')
             try:
                 self.__data = pickle.load(fileobj)
@@ -219,6 +220,17 @@ class Locale(object):
         :type: `dict`
         """)
 
+    def decimal_formats(self):
+        return self._data['decimal_formats']
+    decimal_formats = property(decimal_formats, doc="""\
+        Locale patterns for decimal number formatting.
+        
+        >>> Locale('en', 'US').decimal_formats[None]
+        <NumberPattern u'#,##0.###'>
+        
+        :type: `dict`
+        """)
+
     #{ Calendar Information and Date Formatting
 
     def periods(self):
@@ -331,9 +343,9 @@ class Locale(object):
         Locale patterns for date formatting.
         
         >>> Locale('en', 'US').date_formats['short']
-        <DateTimeFormatPattern u'M/d/yy'>
+        <DateTimePattern u'M/d/yy'>
         >>> Locale('fr', 'FR').date_formats['long']
-        <DateTimeFormatPattern u'd MMMM yyyy'>
+        <DateTimePattern u'd MMMM yyyy'>
         
         :type: `dict`
         """)
@@ -344,20 +356,9 @@ class Locale(object):
         Locale patterns for time formatting.
         
         >>> Locale('en', 'US').time_formats['short']
-        <DateTimeFormatPattern u'h:mm a'>
+        <DateTimePattern u'h:mm a'>
         >>> Locale('fr', 'FR').time_formats['long']
-        <DateTimeFormatPattern u'HH:mm:ss z'>
-        
-        :type: `dict`
-        """)
-
-    def decimal_formats(self):
-        return self._data['decimal_formats']
-    decimal_formats = property(decimal_formats, doc="""\
-        Locale patterns for decimal number formatting.
-        
-        > Locale('en', 'US').decimal_formats[None]
-        <NumberFormatPattern u'#,##0.###'>
+        <DateTimePattern u'HH:mm:ss z'>
         
         :type: `dict`
         """)
index 1c8b4fa6ddce6632da5defa0e52ed97969d44c85..538ba63072b568d3415ae07dfd0475b762fcec5b 100644 (file)
@@ -116,9 +116,9 @@ def get_date_format(format='medium', locale=LC_TIME):
     format.
     
     >>> get_date_format(locale='en_US')
-    <DateTimeFormatPattern u'MMM d, yyyy'>
+    <DateTimePattern u'MMM d, yyyy'>
     >>> get_date_format('full', locale='de_DE')
-    <DateTimeFormatPattern u'EEEE, d. MMMM yyyy'>
+    <DateTimePattern u'EEEE, d. MMMM yyyy'>
     
     :param format: the format to use, one of "full", "long", "medium", or
                    "short"
@@ -133,9 +133,9 @@ def get_time_format(format='medium', locale=LC_TIME):
     format.
     
     >>> get_time_format(locale='en_US')
-    <DateTimeFormatPattern u'h:mm:ss a'>
+    <DateTimePattern u'h:mm:ss a'>
     >>> get_time_format('full', locale='de_DE')
-    <DateTimeFormatPattern u"H:mm' Uhr 'z">
+    <DateTimePattern u"H:mm' Uhr 'z">
     
     :param format: the format to use, one of "full", "long", "medium", or
                    "short"
@@ -204,7 +204,7 @@ def parse_time(string, locale=LC_TIME):
     raise NotImplementedError
 
 
-class DateTimeFormatPattern(object):
+class DateTimePattern(object):
 
     def __init__(self, pattern, format):
         self.pattern = pattern
@@ -327,7 +327,7 @@ def parse_pattern(pattern):
     
     :param pattern: the formatting pattern to parse
     """
-    if type(pattern) is DateTimeFormatPattern:
+    if type(pattern) is DateTimePattern:
         return pattern
 
     result = []
@@ -384,4 +384,4 @@ def parse_pattern(pattern):
     elif charbuf:
         append_chars()
 
-    return DateTimeFormatPattern(pattern, u''.join(result))
+    return DateTimePattern(pattern, u''.join(result))
index fa6e2cce2f196f76b56d4910b529e210baa586d3..13a680bd162a2960a50e6b0bdc40540b50f8a2fa 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
index 1337cf655f0a9fd30f13679fce3e5a771ed479ca..a3f5f278aa06153795f4abda6d5cdde0c30c30d4 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
index e614d859ccc53c0161ce7e22d7fa40aa3a4398ea..d0d3c80ec2f97b5b7d6b5685d12e5a6df0e9b1c7 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
index 68a9dc484af15924aa32da1a72568c1ee637cf66..73ef5e39f67cadfbc8da7deb7c17414616c3fc2d 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
index 0c780d33b926c32d61254546765c84ff1f9cbe3c..f393b347f25b0dd118683b1e02f04e823303fabf 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2006 Edgewall Software
+# Copyright (C) 2007 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
index 75b8ed76dddd7f3baf53cea1610882e04fea6399..cbe04c4286a119cfa0272e11d06fd4caae86eeef 100644 (file)
@@ -47,6 +47,9 @@ pre.variable { margin: 0; }
 table.summary { margin: .5em 0; }
 table.summary tr.table-header { background: #f7f7f0; }
 table.summary td.table-header { color: #666; font-weight: bold; }
+table.summary th.group-header { background: #f7f7f0; color: #666;
+  font-size: 90%; font-weight: bold; text-align: left;
+}
 table.summary th, table.summary td { border: 1px solid #d7d7d7; }
 table.summary th th, table.summary td td { border: none; }
 table.summary td.summary table td { color: #666; font-size: 90%; }
index 8ad82affd4ea93010c53cacfd4fbe75aa6fc9d8b..2e685f93b52bb2c95c56fb945f577b3657dace22 100755 (executable)
--- a/setup.py
+++ b/setup.py
 # individuals. For the exact contribution history, see the revision
 # history and logs, available at http://babel.edgewall.org/log/.
 
+from distutils.cmd import Command
 import doctest
 from glob import glob
 import os
-from setuptools import find_packages, setup, Command
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
 import sys
 
 
@@ -97,7 +101,7 @@ setup(
         'Programming Language :: Python',
         'Topic :: Software Development :: Libraries :: Python Modules',
     ],
-    packages = find_packages(exclude=['tests']),
+    packages = ['babel', 'babel.catalog'],
     package_data = {'babel': ['localedata/*.dat']},
     test_suite = 'babel.tests.suite',