From d4dd3ca4ded4e7dbb55be8797e42a12beaa00879 Mon Sep 17 00:00:00 2001 From: Michiel van Baak Date: Sun, 9 Feb 2020 15:37:11 +0100 Subject: [PATCH] Use native os.scandir when available --- libs/subliminal_patch/core.py | 6 +++++- libs/subzero/lib/io.py | 5 ++++- libs/subzero/subtitle_storage.py | 6 +++++- {libs => libs2}/_scandir.c | 0 {libs => libs2}/scandir.py | 0 5 files changed, 14 insertions(+), 3 deletions(-) rename {libs => libs2}/_scandir.c (100%) rename {libs => libs2}/scandir.py (100%) diff --git a/libs/subliminal_patch/core.py b/libs/subliminal_patch/core.py index 38a603eed..81da38aae 100644 --- a/libs/subliminal_patch/core.py +++ b/libs/subliminal_patch/core.py @@ -32,7 +32,11 @@ from subliminal.core import guessit, ProviderPool, io, is_windows_special_path, from subliminal_patch.exceptions import TooManyRequests, APIThrottled from subzero.language import Language, ENDSWITH_LANGUAGECODE_RE, FULL_LANGUAGE_LIST -from scandir import scandir, scandir_generic as _scandir_generic +try: + from os import scandir + _scandir_generic = scandir +except ImportError: + from scandir import scandir, scandir_generic as _scandir_generic import six logger = logging.getLogger(__name__) diff --git a/libs/subzero/lib/io.py b/libs/subzero/lib/io.py index bc28a2ffe..ed46af2ee 100644 --- a/libs/subzero/lib/io.py +++ b/libs/subzero/lib/io.py @@ -4,7 +4,10 @@ from __future__ import absolute_import import os import sys -from scandir import scandir as _scandir +try: + from os import scandir as _scandir +except ImportError: + from scandir import scandir as _scandir # thanks @ plex trakt scrobbler: https://github.com/trakt/Plex-Trakt-Scrobbler/blob/master/Trakttv.bundle/Contents/Libraries/Shared/plugin/core/io.py diff --git a/libs/subzero/subtitle_storage.py b/libs/subzero/subtitle_storage.py index 53a31b8f2..3763362d5 100644 --- a/libs/subzero/subtitle_storage.py +++ b/libs/subzero/subtitle_storage.py @@ -13,7 +13,11 @@ import sys from json_tricks.nonp import loads from subzero.lib.json import dumps -from scandir import scandir, scandir_generic as _scandir_generic +try: + from os import scandir + _scandir_generic = scandir +except ImportError: + from scandir import scandir, scandir_generic as _scandir_generic from .constants import mode_map import six diff --git a/libs/_scandir.c b/libs2/_scandir.c similarity index 100% rename from libs/_scandir.c rename to libs2/_scandir.c diff --git a/libs/scandir.py b/libs2/scandir.py similarity index 100% rename from libs/scandir.py rename to libs2/scandir.py