From df9bd7316f4d34db1fd6e016332ff32dd2f9394d Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Tue, 9 Jan 2018 15:41:40 +0100 Subject: [PATCH] Replace past.builtins.basestring with a custom one to workaround bug in Ubuntu's Python3 --- ffmpeg/_ffmpeg.py | 2 +- ffmpeg/_run.py | 2 +- ffmpeg/_utils.py | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/ffmpeg/_ffmpeg.py b/ffmpeg/_ffmpeg.py index 231783a..cd455cc 100644 --- a/ffmpeg/_ffmpeg.py +++ b/ffmpeg/_ffmpeg.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from past.builtins import basestring +from ._utils import basestring from .nodes import ( filter_operator, diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index d7f8cd2..73b5428 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from .dag import get_outgoing_edges, topo_sort from functools import reduce -from past.builtins import basestring +from ._utils import basestring import copy import operator import subprocess as _subprocess diff --git a/ffmpeg/_utils.py b/ffmpeg/_utils.py index 9b575a0..20eb1af 100644 --- a/ffmpeg/_utils.py +++ b/ffmpeg/_utils.py @@ -1,8 +1,42 @@ from __future__ import unicode_literals - -from builtins import str -from past.builtins import basestring import hashlib +import sys + +if sys.version_info.major == 2: + # noinspection PyUnresolvedReferences,PyShadowingBuiltins + str = unicode + + +# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu). +# This code is copy-pasted from it to avoid crashes. +class BaseBaseString(type): + def __instancecheck__(cls, instance): + return isinstance(instance, (bytes, str)) + + def __subclasshook__(cls, thing): + # TODO: What should go here? + raise NotImplemented + + +def with_metaclass(meta, *bases): + class metaclass(meta): + __call__ = type.__call__ + __init__ = type.__init__ + + def __new__(cls, name, this_bases, d): + if this_bases is None: + return type.__new__(cls, name, (), d) + return meta(name, bases, d) + + return metaclass('temporary_class', None, {}) + + +if sys.version_info.major >= 3: + class basestring(with_metaclass(BaseBaseString)): + pass +else: + # noinspection PyUnresolvedReferences,PyCompatibility + from builtins import basestring def _recursive_repr(item): @@ -27,6 +61,7 @@ def get_hash(item): repr_ = _recursive_repr(item).encode('utf-8') return hashlib.md5(repr_).hexdigest() + def get_hash_int(item): return int(get_hash(item), base=16)