'Simple helper function to create an str from possibly unicode strings.
Args:
value: input string (should pass as an instance of str or unicode).'

def __EncodeIfNeeded(self, value):

    if isinstance(value, unicode):
        return value.encode('utf8')
    else:
        return value
