From 1d8d5a93f7187438587c3a754b53fdf30322cef0 Mon Sep 17 00:00:00 2001 From: dirkf Date: Thu, 13 Jul 2023 20:14:50 +0100 Subject: [test] Fixes for old Pythons --- youtube_dl/jsinterp.py | 14 +++++++------- youtube_dl/utils.py | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'youtube_dl') diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py index 882432b80..86d902248 100644 --- a/youtube_dl/jsinterp.py +++ b/youtube_dl/jsinterp.py @@ -280,16 +280,16 @@ class JSInterpreter(object): # make Py 2.6 conform to its lying documentation if name == 'flags': self.flags = self.__flags + return self.flags elif name == 'pattern': self.pattern = self.__pattern_txt + return self.pattern + elif hasattr(self.__self, name): + v = getattr(self.__self, name) + setattr(self, name, v) + return v elif name in ('groupindex', 'groups'): - # in case these get set after a match? - if hasattr(self.__self, name): - setattr(self, name, getattr(self.__self, name)) - else: - return 0 if name == 'groupindex' else {} - if hasattr(self, name): - return getattr(self, name) + return 0 if name == 'groupindex' else {} raise AttributeError('{0} has no attribute named {1}'.format(self, name)) @classmethod diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index ac6c81465..494f8341b 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -6198,7 +6198,8 @@ def traverse_obj(obj, *paths, **kwargs): elif isinstance(obj, compat_re_Match): result = None if isinstance(key, int) or casesense: - result = lookup_or_none(obj, key, getter=compat_re_Match.group) + # Py 2.6 doesn't have methods in the Match class/type + result = lookup_or_none(obj, key, getter=lambda _, k: obj.group(k)) elif isinstance(key, str): result = next((v for k, v in obj.groupdict().items() @@ -6246,7 +6247,10 @@ def traverse_obj(obj, *paths, **kwargs): if __debug__ and callable(key): # Verify function signature - inspect.getcallargs(key, None, None) + args = inspect.getargspec(key) + if len(args.args) != 2: + # crash differently in 2.6 ! + inspect.getcallargs(key, None, None) new_objs = [] for obj in objs: -- cgit v1.2.3