Skip to content

Commit

Permalink
Add compat_map/filter and use the former
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkf committed Nov 23, 2021
1 parent d69983a commit 1b96fd2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 21 additions & 0 deletions youtube_dl/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,25 @@ def unpack(self, string):
compat_Struct = struct.Struct


# compat_map/filter() returning an iterator, supposedly the
# same versioning as for zip below
try:
from future_builtins import map as compat_map
except ImportError:
try:
from itertools import imap as compat_map
except ImportError:
compat_map = map

try:
from future_builtins import filter as compat_filter
except ImportError:
try:
from itertools import ifilter as compat_filter
except ImportError:
compat_filter = filter


try:
from future_builtins import zip as compat_zip
except ImportError: # not 2.6+ or is 3.x
Expand Down Expand Up @@ -3015,6 +3034,7 @@ def compat_ctypes_WINFUNCTYPE(*args, **kwargs):
'compat_etree_fromstring',
'compat_etree_register_namespace',
'compat_expanduser',
'compat_filter',
'compat_get_terminal_size',
'compat_getenv',
'compat_getpass',
Expand All @@ -3026,6 +3046,7 @@ def compat_ctypes_WINFUNCTYPE(*args, **kwargs):
'compat_integer_types',
'compat_itertools_count',
'compat_kwargs',
'compat_map',
'compat_numeric_types',
'compat_ord',
'compat_os_name',
Expand Down
7 changes: 1 addition & 6 deletions youtube_dl/extractor/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

from __future__ import unicode_literals

# should probably have been in compat.py
try:
from future_builtins import map
except ImportError:
pass

import itertools
import json
import os.path
Expand All @@ -19,6 +13,7 @@
from ..compat import (
compat_chr,
compat_HTTPError,
compat_map as map,
compat_parse_qs,
compat_str,
compat_urllib_parse_unquote_plus,
Expand Down

0 comments on commit 1b96fd2

Please sign in to comment.