def __mix_content(self, contents, **kw): """ returns: (sources, content) tuple """ min_length = kw.pop("min_length", 2) max_length = kw.pop("max_length", 130) sources = {} for content in contents: source_name = content.source_name body = sanitize_encoding(content.body).strip() # skips empty bodies if not body: continue # logging bodies here makes things very hard to debug logging.debug("__mix_content source_name:'%s' guid:%s" % (content.source_name, content.guid)) #logging.debug("__mix_content body:%s" % body) if not sources.has_key(source_name): sources[source_name] = content.source self.__speaker.ingest(body) # sanitizing encoding here since I think it's closest to the source. return sources.values(), sanitize_encoding( self.__speaker.speak(min_length, max_length))
def __mix_content(self, contents, **kw): """ returns: (sources, content) tuple """ min_length = kw.pop("min_length", 2) max_length = kw.pop("max_length", 130) sources = {} for content in contents: source_name = content.source_name body = sanitize_encoding(content.body).strip() # skips empty bodies if not body: continue # logging bodies here makes things very hard to debug logging.debug("__mix_content source_name:'%s' guid:%s" % (content.source_name, content.guid)) #logging.debug("__mix_content body:%s" % body) if not sources.has_key(source_name): sources[source_name] = content.source self.__speaker.ingest(body) # sanitizing encoding here since I think it's closest to the source. return sources.values(), sanitize_encoding(self.__speaker.speak(min_length, max_length))
def test_sanitize_encoding_handles_string_with_unicode_exception(self): m = Mox() m.StubOutWithMock(strings, '_unicode') try: strings._unicode(self._string_with_unicode_char, "utf8", "replace").AndRaise(TypeError("testing")) m.ReplayAll() strings.sanitize_encoding(self._string_with_unicode_char) self.fail("exception expected") except TypeError, e: pass
def test_sanitize_encoding_handles_unicode_subclass(self): strings.sanitize_encoding(Text("hi"))
def test_sanitize_encoding_handles_unicode_with_unicode_char(self): strings.sanitize_encoding(u"\xc2")
def test_sanitize_encoding_handles_string_with_unicode_char(self): strings.sanitize_encoding(self._string_with_unicode_char)