From a6a35e18d4525ebb54dc8250819b63c34bc38ba7 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 23 Aug 2016 10:55:24 +0200 Subject: [PATCH] support py2 and 3 --- bin/pandora_client | 5 +++-- pandora_client/__init__.py | 22 ++++++++++++---------- pandora_client/client.py | 5 +++-- pandora_client/extract.py | 4 ++-- pandora_client/server.py | 6 +++--- setup.py | 1 + 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bin/pandora_client b/bin/pandora_client index d8c40b4..1a9535f 100755 --- a/bin/pandora_client +++ b/bin/pandora_client @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 # GPL 2012 +from __future__ import print_function import os import sys @@ -27,11 +28,11 @@ if __name__ == '__main__': (opts, args) = parser.parse_args() if opts.version: - print "%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__) + print("%s %s" % (os.path.basename(sys.argv[0]), pandora_client.__version__)) sys.exit(0) opts.config = os.path.expanduser(opts.config) if (args and args[0] not in ('config', 'client') and not os.path.exists(opts.config)): - print 'no configuration found, run "%s config" or specify one with -c' % sys.argv[0] + print('no configuration found, run "%s config" or specify one with -c' % sys.argv[0]) sys.exit(1) if None in (opts.config, ): diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index e1f6edd..c8c5ef0 100755 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 # GPL 2012-2016 -from __future__ import division, with_statement, print_function +from __future__ import division, with_statement, print_function, absolute_import import getpass from glob import glob @@ -16,12 +16,14 @@ import sys import tempfile import time import pkg_resources -from urlparse import urlparse + +from six.moves.urllib.parse import urlparse +from six import string_types import ox -import extract -import utils +from . import extract +from . import utils DEBUG = False @@ -142,7 +144,7 @@ class Client(object): _configfile = None def __init__(self, config, offline=False): - if isinstance(config, basestring): + if isinstance(config, string_types): self._configfile = os.path.expanduser(config) with open(config) as f: try: @@ -235,7 +237,7 @@ class Client(object): def _conn(self): db_conn = self._config['cache'] - if isinstance(db_conn, str): + if isinstance(db_conn, bytes): db_conn = db_conn.decode('utf-8') db_conn = os.path.expanduser(db_conn) if not os.path.exists(os.path.dirname(db_conn)): @@ -277,7 +279,7 @@ class Client(object): prefixes = [prefix] else: prefixes = self.active_volumes().values() - prefixes = [p.decode('utf-8') if isinstance(prefix, str) else p for p in prefixes] + prefixes = [p.decode('utf-8') if isinstance(prefix, bytes) else p for p in prefixes] _info = self.info(oshash) for path in self.path(oshash): for prefix in prefixes: @@ -385,7 +387,7 @@ class Client(object): modified = time.mktime(time.localtime()) created = modified - if isinstance(path, str): + if isinstance(path, bytes): path = path.decode('utf-8') sql = u'SELECT atime, ctime, mtime, size, created, info FROM file WHERE deleted < 0 AND path=?' @@ -507,7 +509,7 @@ class Client(object): path = os.path.normpath(path) if not path.endswith(os.sep): path += os.sep - if isinstance(path, str): + if isinstance(path, bytes): path = path.decode('utf-8') if os.path.exists(path): volumes[name] = path @@ -1029,7 +1031,7 @@ class API(ox.API): form.add_field('action', 'upload') form.add_field('id', str(oshash)) fname = os.path.basename(filename) - if isinstance(fname, unicode): + if not isinstance(fname, bytes): fname = fname.encode('utf-8') form.add_file('file', fname, open(filename, 'rb')) r = self._json_request(self.url, form) diff --git a/pandora_client/client.py b/pandora_client/client.py index ef52eed..9c71205 100644 --- a/pandora_client/client.py +++ b/pandora_client/client.py @@ -1,6 +1,7 @@ # encoding: utf-8 # vi:si:et:sw=4:sts=4:ts=4 -from __future__ import print_function +from __future__ import division, with_statement, print_function, absolute_import + import os import json import subprocess @@ -10,7 +11,7 @@ import sys import requests -import extract +from . import extract class DistributedClient: diff --git a/pandora_client/extract.py b/pandora_client/extract.py index 39ab4ff..a609d6b 100644 --- a/pandora_client/extract.py +++ b/pandora_client/extract.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 # GPL 2010 -from __future__ import division, with_statement, print_function +from __future__ import division, with_statement, print_function, absolute_import import os import subprocess @@ -11,7 +11,7 @@ import shutil import ox -from utils import AspectRatio, run_command, basedir +from .utils import AspectRatio, run_command, basedir def command(program): diff --git a/pandora_client/server.py b/pandora_client/server.py index 510b1ff..08c7276 100644 --- a/pandora_client/server.py +++ b/pandora_client/server.py @@ -1,6 +1,6 @@ # encoding: utf-8 # vi:si:et:sw=4:sts=4:ts=4 -from __future__ import print_function +from __future__ import division, with_statement, print_function, absolute_import import os import json @@ -16,8 +16,8 @@ from twisted.web.static import File from twisted.web.server import Site from twisted.internet import reactor -import extract -from utils import hash_prefix +from . import extract +from .utils import hash_prefix class UploadThread(Thread): def __init__(self, server): diff --git a/setup.py b/setup.py index 9e84510..1ecfda1 100644 --- a/setup.py +++ b/setup.py @@ -51,6 +51,7 @@ setup( ], install_requires=[ 'ox >= 2.1.541,<3', + 'six', 'requests >= 1.1.0' ], keywords = [