diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 10f5ace..c20802c 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -1,5 +1,6 @@ # coding: utf-8 -from __future__ import print_function +from __future__ import print_function, unicode_literals +import sys from optparse import OptionParser try: from itertools import ifilter as filter @@ -25,7 +26,7 @@ def cmd_parser(): parser = OptionParser() parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not') parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information.') - parser.add_option('--id', type='str', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3') + parser.add_option('--id', type='string', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3') parser.add_option('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword') parser.add_option('--page', type='int', dest='page', action='store', default=1, help='page number of search result') @@ -38,7 +39,13 @@ def cmd_parser(): help='timeout of download doujinshi') parser.add_option('--proxy', type='string', dest='proxy', action='store', default='', help='use proxy, example: http://127.0.0.1:1080') - args, _ = parser.parse_args() + + try: + sys.argv = list(map(lambda x: unicode(x.decode('utf-8')), sys.argv)) + except (NameError, TypeError): + pass + + args, _ = parser.parse_args(sys.argv[1:]) if args.tags: logger.warning('`--tags` is under construction') diff --git a/nhentai/command.py b/nhentai/command.py index a0cac08..6fbf786 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 # coding: utf-8 +from __future__ import unicode_literals, print_function import signal from nhentai.cmdline import cmd_parser, banner diff --git a/nhentai/constant.py b/nhentai/constant.py index 2959cbf..d9d4878 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -1,3 +1,5 @@ +# coding: utf-8 +from __future__ import unicode_literals, print_function import os from nhentai.utils import urlparse diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py index e664052..8d0b9a8 100644 --- a/nhentai/doujinshi.py +++ b/nhentai/doujinshi.py @@ -1,7 +1,7 @@ # coding: utf-8 -from __future__ import print_function +from __future__ import print_function, unicode_literals from tabulate import tabulate -# from builtins import range +from future.builtins import range from nhentai.constant import DETAIL_URL, IMAGE_URL from nhentai.logger import logger diff --git a/nhentai/downloader.py b/nhentai/downloader.py index 5eeab90..c46c5e6 100644 --- a/nhentai/downloader.py +++ b/nhentai/downloader.py @@ -1,5 +1,6 @@ -# coding: utf-8 -from builtins import str as text +# coding: utf- +from __future__ import unicode_literals, print_function +from future.builtins import str as text import os import requests import threadpool diff --git a/nhentai/logger.py b/nhentai/logger.py index 88273ab..dbf8034 100644 --- a/nhentai/logger.py +++ b/nhentai/logger.py @@ -1,6 +1,7 @@ # # Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license. # +from __future__ import print_function, unicode_literals import logging import os import re diff --git a/nhentai/parser.py b/nhentai/parser.py index 02f9766..127d6fa 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -1,5 +1,5 @@ # coding: utf-8 -from __future__ import print_function +from __future__ import unicode_literals, print_function from bs4 import BeautifulSoup import re @@ -99,7 +99,7 @@ def search_parser(keyword, page): def print_doujinshi(doujinshi_list): if not doujinshi_list: return - doujinshi_list = [i.values() for i in doujinshi_list] + doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list] headers = ['id', 'doujinshi'] logger.info('Search Result\n' + tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst')) diff --git a/nhentai/utils.py b/nhentai/utils.py index 93bdf8c..6377b14 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -1,4 +1,6 @@ # coding: utf-8 +from __future__ import unicode_literals, print_function + class _Singleton(type): """ A metaclass that creates a Singleton base class when called. """ @@ -10,7 +12,7 @@ class _Singleton(type): return cls._instances[cls] -class Singleton(_Singleton('SingletonMeta', (object,), {})): +class Singleton(_Singleton(str('SingletonMeta'), (object,), {})): pass