diff options
-rw-r--r-- | libbe/bug.py | 11 | ||||
-rw-r--r-- | libbe/bugdir.py | 14 | ||||
-rw-r--r-- | libbe/comment.py | 14 | ||||
-rw-r--r-- | libbe/utility.py | 21 |
4 files changed, 50 insertions, 10 deletions
diff --git a/libbe/bug.py b/libbe/bug.py index e3dc1e0..f3448e2 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -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) diff --git a/libbe/bugdir.py b/libbe/bugdir.py index 9802502..6e020ee 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -228,6 +228,20 @@ settings easy. Don't set this attribute. Set .rcs instead, and map[uuid] = None self._bug_map_value = map # ._bug_map_value used by @local_property + def _extra_strings_check_fn(value): + 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) + @_versioned_property(name="extra_strings", + doc="Space for an array of extra strings. Useful for storing state for functionality implemented purely in becommands/<some_function>.py.", + default=[], + check_fn=_extra_strings_check_fn, + change_hook=_extra_strings_change_hook, + mutable=True) + def extra_strings(): return {} + @Property @primed_property(primer=_bug_map_gen) @local_property("bug_map") diff --git a/libbe/comment.py b/libbe/comment.py index d19953b..3249e8b 100644 --- a/libbe/comment.py +++ b/libbe/comment.py @@ -218,6 +218,20 @@ class Comment(Tree, settings_object.SavedSettingsObject): @doc_property(doc="A revision control system instance.") def rcs(): return {} + def _extra_strings_check_fn(value): + 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) + @_versioned_property(name="extra_strings", + doc="Space for an array of extra strings. Useful for storing state for functionality implemented purely in becommands/<some_function>.py.", + default=[], + check_fn=_extra_strings_check_fn, + change_hook=_extra_strings_change_hook, + mutable=True) + def extra_strings(): return {} + def __init__(self, bug=None, uuid=None, from_disk=False, in_reply_to=None, body=None): """ 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() |