Example #1
0
    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))
Example #2
0
    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))
Example #3
0
 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
Example #4
0
 def test_sanitize_encoding_handles_unicode_subclass(self):
     strings.sanitize_encoding(Text("hi"))
Example #5
0
 def test_sanitize_encoding_handles_unicode_with_unicode_char(self):
     strings.sanitize_encoding(u"\xc2")
Example #6
0
 def test_sanitize_encoding_handles_string_with_unicode_char(self):
     strings.sanitize_encoding(self._string_with_unicode_char)