Bug._extra_strings_check_fn() guts now utility.iterable_full_of_strings().
authorW. Trevor King <wking@drexel.edu>
Tue, 21 Jul 2009 20:19:02 +0000 (16:19 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 21 Jul 2009 20:19:02 +0000 (16:19 -0400)
libbe/bug.py
libbe/utility.py

index e3dc1e0f7e8e602d5c010b981bf3d67a0846bcf2..f3448e29baaac68bf6f6403bdfba9f6ad9ae5d16 100644 (file)
@@ -187,15 +187,8 @@ class Bug(settings_object.SavedSettingsObject):
                     doc="An integer version of .time_string")
 
     def _extra_strings_check_fn(value):
-        "Require an iterable full of strings"
-        if value == settings_object.EMPTY:
-            return True
-        elif not hasattr(value, "__iter__"):
-            return False
-        for x in value:
-            if type(x) not in types.StringTypes:
-                return False
-        return True
+        return utility.iterable_full_of_strings(value, \
+                         alternative=settings_object.EMPTY)
     def _extra_strings_change_hook(self, old, new):
         self.extra_strings.sort() # to make merging easier
         self._prop_save_settings(old, new)
index f27d7ebec71a1ead3a97effaf4da88dc7a5e9a95..3df06b40b7373c26e62bef2bce932f41c3631723 100644 (file)
@@ -23,7 +23,6 @@ import time
 import types
 import doctest
 
-
 def search_parent_directories(path, filename):
     """
     Find the file (or directory) named filename in path or in any
@@ -106,5 +105,25 @@ def time_to_gmtime(str_time):
     time_val = str_to_time(str_time)
     return time_to_str(time_val)
 
+def iterable_full_of_strings(value, alternative=None):
+    """
+    Require an iterable full of strings.
+    >>> iterable_full_of_strings([])
+    True
+    >>> iterable_full_of_strings(["abc", "def", u"hij"])
+    True
+    >>> iterable_full_of_strings(["abc", None, u"hij"])
+    False
+    >>> iterable_full_of_strings(None, alternative=None)
+    True
+    """
+    if value == alternative:
+        return True
+    elif not hasattr(value, "__iter__"):
+        return False
+    for x in value:
+        if type(x) not in types.StringTypes:
+            return False
+    return True
 
 suite = doctest.DocTestSuite()