"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/searchable.py $
$Id: searchable.py 30312 2007-11-27 11:26:59Z dbinger $
"""
from qp.lib.spec import Mixin, unicode_string, byte_string

class Searchable (Mixin):

    search_text_is = (None, unicode_string, byte_string)

    def __init__(self):
        self.search_text = None

    def get_search_text(self):
        """() -> unicode_string | byte_string
        This method is called by searches.
        """
        if self.search_text is None:
            self.update_search_text()
        return self.search_text

    def update_search_text(self):
        """
        Compute the search text and reset the search_text attribute if there
        is any change from the current value.
        """
        new_value = str(self)
        if self.search_text != new_value:
            self.search_text = new_value


