Revert "Generalize translation code in GoogleTranslate.py". Previous
three reverts to undo the recent stuff from kad's branch, which was having problems with recursion This reverts commit 1920a127599721dd927da984f6d2b157ef1dcbab. Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
		
							parent
							
								
									493521c3da
								
							
						
					
					
						commit
						9720dfe5bc
					
				| @ -16,8 +16,6 @@ | ||||
| 
 | ||||
| from urllib2 import urlopen | ||||
| from urllib import urlencode | ||||
| from htmlentitydefs import name2codepoint | ||||
| import re | ||||
| 
 | ||||
| from extlib import irclib | ||||
| 
 | ||||
| @ -51,31 +49,13 @@ class GoogleTranslate(Module): | ||||
|             translation = translation.decode('utf-8') | ||||
| 
 | ||||
|             # do some text conversion | ||||
|             for i in re.findall('\u(\w{4})', translation): | ||||
|                 replacement = unichr(int(i, 16)) | ||||
|                 translation = translation.replace('\u' + i, replacement) | ||||
| 
 | ||||
|             for i in re.findall('&(#)?(x)?(\w+?);', translation): | ||||
|                 replacement = i[2] | ||||
|                 if i[0] == "#": | ||||
|                     if i[1] == 'x': | ||||
|                         replacement = unichr(int(i[2], 16)) | ||||
|                     else: | ||||
|                         replacement = unichr(int(i[2])) | ||||
|                 else: | ||||
|                     cp = name2codepoint.get(i[2]) | ||||
|                     replacement = unichr(cp) | ||||
|                 translation = translation.replace('&' + i[0] + i[1] + i[2] + ';', replacement) | ||||
| 
 | ||||
|             translation = translation.replace('\\\\', '\\') | ||||
| 
 | ||||
|             #translation = translation.replace('\\u0026quot;', '"') | ||||
|             #translation = translation.replace('\\u0026amp;', '&') | ||||
|             #translation = translation.replace('\\u003c', '<') | ||||
|             #translation = translation.replace('\\u0026lt;', '<') | ||||
|             #translation = translation.replace('\\u003e', '>') | ||||
|             #translation = translation.replace('\\u0026gt;', '>') | ||||
|             #translation = translation.replace('\\u0026#39;', '\'') | ||||
|             translation = translation.replace('\\u0026quot;', '"') | ||||
|             translation = translation.replace('\\u0026amp;', '&') | ||||
|             translation = translation.replace('\\u003c', '<') | ||||
|             translation = translation.replace('\\u0026lt;', '<') | ||||
|             translation = translation.replace('\\u003e', '>') | ||||
|             translation = translation.replace('\\u0026gt;', '>') | ||||
|             translation = translation.replace('\\u0026#39;', '\'') | ||||
| 
 | ||||
|             return self.reply(connection, replypath, translation) | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user