fix unicode error on windows / python2

This commit is contained in:
Ricter Z 2018-08-12 23:11:01 +08:00
parent 16e8ce6f45
commit ef36e012ce
3 changed files with 12 additions and 5 deletions

View File

@ -13,8 +13,12 @@ from nhentai.utils import urlparse, generate_html
from nhentai.logger import logger from nhentai.logger import logger
try: try:
reload(sys) if sys.version_info < (3, 0, 0):
sys.setdefaultencoding(sys.stdin.encoding) import codecs
import locale
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr)
except NameError: except NameError:
# python3 # python3
pass pass

View File

@ -104,7 +104,10 @@ class ColorizingStreamHandler(logging.StreamHandler):
text = parts.pop(0) text = parts.pop(0)
if text: if text:
write(text) if sys.version_info < (3, 0, 0):
write(text.encode('utf-8'))
else:
write(text)
if parts: if parts:
params = parts.pop(0) params = parts.pop(0)

View File

@ -157,8 +157,8 @@ def print_doujinshi(doujinshi_list):
return return
doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list] doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list]
headers = ['id', 'doujinshi'] headers = ['id', 'doujinshi']
logger.info('Search Result\n' + data = tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')) logger.info('Search Result\n{}'.format(data))
def tag_parser(tag_id): def tag_parser(tag_id):