better handle utf-8

This commit is contained in:
Christophe Benz 2010-06-02 17:46:28 +02:00
commit 947d50da4e
2 changed files with 5 additions and 3 deletions

View file

@ -47,6 +47,6 @@ class Videoob(ConsoleApplication):
@ConsoleApplication.command('Search videos') @ConsoleApplication.command('Search videos')
def command_search(self, pattern=None): def command_search(self, pattern=None):
print u'Search pattern: %s' % pattern if pattern else u'Last videos' print (u'Search pattern: %s' % pattern if pattern else u'Last videos').encode('utf-8')
for backend, video in self.weboob.do('iter_search_results', pattern=pattern, nsfw=self.options.nsfw): for backend, video in self.weboob.do('iter_search_results', pattern=pattern, nsfw=self.options.nsfw):
self.format(video) self.format(video)

View file

@ -157,15 +157,17 @@ class ConsoleApplication(BaseApplication):
self.formatter.flush() self.formatter.flush()
# Process result if value is returned by command # Process result if value is returned by command
if isinstance(command_result, (str, unicode)): if isinstance(command_result, str):
print command_result print command_result
elif isinstance(command_result, unicode):
print command_result.encode('utf-8')
elif isinstance(command_result, int): elif isinstance(command_result, int):
return command_result return command_result
elif command_result is None: elif command_result is None:
return 0 return 0
else: else:
try: try:
print unicode(command_result) print unicode(command_result).encode('utf-8')
except ValueError: except ValueError:
raise Exception(u'Command result type not expected: %s' % type(command_result)) raise Exception(u'Command result type not expected: %s' % type(command_result))