Browse Source

- Force UTF-8 printing to terminal

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
e8454596ea
  1. 7
      src/search_engine/nova2.py
  2. 20
      src/search_engine/novaprinter.py

7
src/search_engine/nova2.py

@ -100,16 +100,15 @@ if __name__ == '__main__': @@ -100,16 +100,15 @@ if __name__ == '__main__':
what = '+'.join(sys.argv[2:])
threads = []
for engine in engines_list:
if 1:
#try:
try:
if THREADED:
exec "l = EngineLauncher(%s(), what)" % engine
threads.append(l)
l.start()
else:
engine().search(what)
#except:
# pass
except:
pass
if THREADED:
for t in threads:
t.join()

20
src/search_engine/novaprinter.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#VERSION: 1.2
#VERSION: 1.3
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@ -24,13 +24,21 @@ @@ -24,13 +24,21 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
import sys
# Force UTF-8 printing
from ctypes import pythonapi, py_object, c_char_p
PyFile_SetEncoding = pythonapi.PyFile_SetEncoding
PyFile_SetEncoding.argtypes = (py_object, c_char_p)
PyFile_SetEncoding(sys.stdout, "UTF-8")
def prettyPrinter(dictionnary):
if isinstance(dictionnary['size'], str):
dictionnary['size'] = dictionnary['size'].decode('utf-8')
# Convert everything to unicode for safe printing
for key,value in dictionnary.items():
if isinstance(dictionnary[key], str):
dictionnary[key] = unicode(dictionnary[key], 'utf-8')
dictionnary['size'] = anySizeToBytes(dictionnary['size'])
if isinstance(dictionnary['name'], unicode):
dictionnary['name'] = dictionnary['name'].encode('utf-8')
print dictionnary['link'],'|',dictionnary['name'],'|',dictionnary['size'],'|',dictionnary['seeds'],'|',dictionnary['leech'],'|',dictionnary['engine_url']
print u"%s|%s|%s|%s|%s|%s"%(dictionnary['link'],dictionnary['name'],dictionnary['size'],dictionnary['seeds'],dictionnary['leech'],dictionnary['engine_url'])
def anySizeToBytes(size_string):
"""

Loading…
Cancel
Save