From 257df923b9657a03d7a394d7862a449c2cd342dc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 21 Jul 2009 16:19:02 -0400 Subject: Bug._extra_strings_check_fn() guts now utility.iterable_full_of_strings(). --- libbe/utility.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'libbe/utility.py') diff --git a/libbe/utility.py b/libbe/utility.py index f27d7eb..3df06b4 100644 --- a/libbe/utility.py +++ b/libbe/utility.py @@ -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() -- cgit