8000 Replace past.builtins.basestring with a custom one to workaround bug … · suryatmodulus/ffmpeg-python@df9bd73 · GitHub
[go: up one dir, main page]

Skip to content

Commit df9bd73

Browse files
committed
Replace past.builtins.basestring with a custom one to workaround bug in Ubuntu's Python3
1 parent 497105f commit df9bd73

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

ffmpeg/_ffmpeg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
from past.builtins import basestring
3+
from ._utils import basestring
44

55
from .nodes import (
66
filter_operator,

ffmpeg/_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .dag import get_outgoing_edges, topo_sort
44
from functools import reduce
5-
from past.builtins import basestring
5+
from ._utils import basestring
66
import copy
77
import operator
88
import subprocess as _subprocess

ffmpeg/_utils.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
11
from __future__ import unicode_literals
2-
3-
from builtins import str
4-
from past.builtins import basestring
52
import hashlib
3+
import sys
4+
5+
if sys.version_info.major == 2:
6+
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
7+
str = unicode
8+
9+
10+
# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
11+
# This code is copy-pasted from it to avoid crashes.
12+
class BaseBaseString(type):
13+
def __instancecheck__(cls, instance):
14+
return isinstance(instance, (bytes, str))
15+
16+
def __subclasshook__(cls, thing):
17+
# TODO: What should go here?
18+
raise NotImplemented
19+
20+
21+
def with_metaclass(meta, *bases):
22+
class metaclass(meta):
23+
__call__ = type.__call__
24+
__init__ = type.__init__
25+
26+
def __new__(cls, name, this_bases, d):
27+
if this_bases is None:
28+
return type.__new__(cls, name, (), d)
29+
return meta(name, bases, d)
30+
31+
return metaclass('temporary_class', None, {})
32+
33+
34+
if sys.version_info.major >= 3:
35+
class basestring(with_metaclass(BaseBaseString)):
36+
pass
37+
else:
38+
# noinspection PyUnresolvedReferences,PyCompatibility
39+
from builtins import basestring
640

741

842
def _recursive_repr(item):
@@ -27,6 +61,7 @@ def get_hash(item):
2761
repr_ = _recursive_repr(item).encode('utf-8')
2862
return hashlib.md5(repr_).hexdigest()
2963

64+
3065
def get_hash_int(item):
3166
return int(get_hash(item), base=16)
3267

0 commit comments

Comments
 (0)
0