def fix_text(text): if text is None: return '' if hasattr(text, 'text'): text = text.text return ' '.join(text.split())