From 148b4a1a0832507bbd715761f44733662fe1eafd Mon Sep 17 00:00:00 2001 From: Ricter Z Date: Mon, 17 Oct 2016 21:48:21 +0800 Subject: [PATCH] urlparse for python3 --- nhentai/cmdline.py | 4 ++-- nhentai/constant.py | 4 ++-- nhentai/utils.py | 10 +++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 19c3e9d..10f5ace 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -7,6 +7,7 @@ except ImportError: pass import nhentai.constant as constant +from nhentai.utils import urlparse from nhentai.logger import logger @@ -64,8 +65,7 @@ def cmd_parser(): exit(0) if args.proxy: - import urlparse - proxy_url = urlparse.urlparse(args.proxy) + proxy_url = urlparse(args.proxy) if proxy_url.scheme not in ('http', 'https'): logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme)) else: diff --git a/nhentai/constant.py b/nhentai/constant.py index 1c7eca4..2959cbf 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -1,12 +1,12 @@ import os -import urlparse +from nhentai.utils import urlparse BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net') DETAIL_URL = '%s/g' % BASE_URL SEARCH_URL = '%s/search/' % BASE_URL -u = urlparse.urlparse(BASE_URL) +u = urlparse(BASE_URL) IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname) PROXY = {} diff --git a/nhentai/utils.py b/nhentai/utils.py index ee3d060..794efad 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -11,4 +11,12 @@ class _Singleton(type): return cls._instances[cls] -class Singleton(_Singleton('SingletonMeta', (object,), {})): pass \ No newline at end of file +class Singleton(_Singleton('SingletonMeta', (object,), {})): + pass + + +def urlparse(url): + try: + import urlparse + except ImportError: + import urllib.parse as urlparse