mirror of
				https://github.com/Mikaela/Limnoria.git
				synced 2025-10-30 23:27:24 +01:00 
			
		
		
		
	RSS: Add Python 3 support.
This commit is contained in:
		
							parent
							
								
									6266d0f16f
								
							
						
					
					
						commit
						ad25f17639
					
				| @ -262,7 +262,7 @@ class RSS(callbacks.Plugin): | ||||
|                 try: | ||||
|                     self.log.debug('Downloading new feed from %u', url) | ||||
|                     results = feedparser.parse(url) | ||||
|                     if 'bozo_exception' in results: | ||||
|                     if 'bozo_exception' in results and not results['entries']: | ||||
|                         raise results['bozo_exception'] | ||||
|                 except feedparser.sgmllib.SGMLParseError: | ||||
|                     self.log.exception('Uncaught exception from feedparser:') | ||||
|  | ||||
| @ -189,8 +189,15 @@ class HtmlToText(HTMLParser, object): | ||||
| def htmlToText(s, tagReplace=' '): | ||||
|     """Turns HTML into text.  tagReplace is a string to replace HTML tags with. | ||||
|     """ | ||||
|     if sys.version_info[0] >= 3 and isinstance(s, bytes): | ||||
|         s = s.decode() | ||||
|     try: | ||||
|         import chardet | ||||
|     except ImportError: | ||||
|         s = s.decode('utf8') | ||||
|     else: | ||||
|         u = chardet.universaldetector.UniversalDetector() | ||||
|         u.feed(s) | ||||
|         u.close() | ||||
|         s = s.decode(u.result['encoding']) | ||||
|     x = HtmlToText(tagReplace) | ||||
|     x.feed(s) | ||||
|     return x.getText() | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Valentin Lorentz
						Valentin Lorentz