changeset 336:fb7c7aae2905

Fix handling of default value of `locales` parameter of the `Translations.load()` method. Thanks to Armin Ronacher for reporting the problem.
author cmlenz
date Wed, 11 Jun 2008 20:00:21 +0000
parents 9c41fe73e2e6
children 568170eb7580
files babel/support.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/babel/support.py
+++ b/babel/support.py
@@ -276,7 +276,7 @@
                         from
         """
         gettext.GNUTranslations.__init__(self, fp=fileobj)
-        self.files = [getattr(fileobj, 'name')]
+        self.files = filter(None, [getattr(fileobj, 'name', None)])
 
     def load(cls, dirname=None, locales=None, domain=DEFAULT_DOMAIN):
         """Load translations from the given directory.
@@ -290,9 +290,10 @@
                  matching translations were found
         :rtype: `Translations`
         """
-        if not isinstance(locales, (list, tuple)):
-            locales = [locales]
-        locales = [str(locale) for locale in locales]
+        if locales is not None:
+            if not isinstance(locales, (list, tuple)):
+                locales = [locales]
+            locales = [str(locale) for locale in locales]
         filename = gettext.find(domain or cls.DEFAULT_DOMAIN, dirname, locales)
         if not filename:
             return gettext.NullTranslations()
Copyright (C) 2012-2017 Edgewall Software