From 9fe43dc219622a0bc50b8eb0302e3592d7c1fd50 Mon Sep 17 00:00:00 2001
From: Dhruvan Ganesh <navrudh.code@gmail.com>
Date: Wed, 10 Aug 2016 15:43:03 +0530
Subject: [PATCH] project is now Py3 and Py2 compatible

---
 nhentai/cmdline.py    |  5 ++---
 nhentai/command.py    | 11 ++++++-----
 nhentai/doujinshi.py  |  8 +++++---
 nhentai/downloader.py | 12 ++++++++----
 nhentai/logger.py     |  1 -
 nhentai/parser.py     |  8 +++++---
 requirements.txt      |  1 +
 7 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py
index 826ea7d..64235a4 100644
--- a/nhentai/cmdline.py
+++ b/nhentai/cmdline.py
@@ -1,14 +1,13 @@
 # coding: utf-8
 from __future__ import print_function
 from optparse import OptionParser
-from logger import logger
 try:
     from itertools import ifilter as filter
 except ImportError:
     pass
 
-
-import constant
+import nhentai.constant as constant
+from nhentai.logger import logger
 
 
 def banner():
diff --git a/nhentai/command.py b/nhentai/command.py
index b7df177..b48fd65 100644
--- a/nhentai/command.py
+++ b/nhentai/command.py
@@ -1,11 +1,12 @@
 #!/usr/bin/env python2.7
 # coding: utf-8
 import signal
-from cmdline import cmd_parser, banner
-from parser import doujinshi_parser, search_parser, print_doujinshi
-from doujinshi import Doujinshi
-from downloader import Downloader
-from logger import logger
+
+from nhentai.cmdline import cmd_parser, banner
+from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi
+from nhentai.doujinshi import Doujinshi
+from nhentai.downloader import Downloader
+from nhentai.logger import logger
 
 
 def main():
diff --git a/nhentai/doujinshi.py b/nhentai/doujinshi.py
index 87157ad..4bcee71 100644
--- a/nhentai/doujinshi.py
+++ b/nhentai/doujinshi.py
@@ -1,8 +1,10 @@
 # coding: utf-8
 from __future__ import print_function
 from tabulate import tabulate
-from constant import DETAIL_URL, IMAGE_URL
-from logger import logger
+from builtins import range
+
+from nhentai.constant import DETAIL_URL, IMAGE_URL
+from nhentai.logger import logger
 
 
 class DoujinshiInfo(dict):
@@ -47,7 +49,7 @@ class Doujinshi(object):
         logger.info('Start download doujinshi: %s' % self.name)
         if self.downloader:
             download_queue = []
-            for i in xrange(1, self.pages + 1):
+            for i in range(1, self.pages + 1):
                 download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext))
             self.downloader.download(download_queue, self.id)
         else:
diff --git a/nhentai/downloader.py b/nhentai/downloader.py
index 8916fb2..5eeab90 100644
--- a/nhentai/downloader.py
+++ b/nhentai/downloader.py
@@ -1,11 +1,15 @@
 # coding: utf-8
+from builtins import str as text
 import os
 import requests
 import threadpool
-from urlparse import urlparse
-from logger import logger
-from parser import request
+try:
+    from urllib.parse import urlparse
+except ImportError:
+    from urlparse import urlparse
 
+from nhentai.logger import logger
+from nhentai.parser import request
 from nhentai.utils import Singleton
 
 
@@ -50,7 +54,7 @@ class Downloader(Singleton):
         logger.log(15, '{0} download successfully'.format(result))
 
     def download(self, queue, folder=''):
-        if not isinstance(folder, (str, unicode)):
+        if not isinstance(folder, (text)):
             folder = str(folder)
 
         if self.path:
diff --git a/nhentai/logger.py b/nhentai/logger.py
index 157bf1f..88273ab 100644
--- a/nhentai/logger.py
+++ b/nhentai/logger.py
@@ -1,4 +1,3 @@
-import logging
 #
 # Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
 #
diff --git a/nhentai/parser.py b/nhentai/parser.py
index 25bf785..f897754 100644
--- a/nhentai/parser.py
+++ b/nhentai/parser.py
@@ -1,12 +1,14 @@
 # coding: utf-8
 from __future__ import print_function
+
+from bs4 import BeautifulSoup
 import re
 import requests
-from bs4 import BeautifulSoup
-import constant
-from logger import logger
 from tabulate import tabulate
 
+import nhentai.constant as constant
+from nhentai.logger import logger
+
 
 def request(method, url, **kwargs):
     if not hasattr(requests, method):
diff --git a/requirements.txt b/requirements.txt
index b48abcf..df0a2ee 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,3 +2,4 @@ requests>=2.5.0
 BeautifulSoup4>=4.0.0
 threadpool>=1.2.7
 tabulate>=0.7.5
+future>=0.15.2
\ No newline at end of file