From 16b73da1cb8c6f06cbc3be5a1cc499c16163d5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Tue, 18 Dec 2018 13:15:38 +0200 Subject: [PATCH] [chore] DRY: move common _VALID_URL_RE caching to a method --- youtube_dl/extractor/common.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index c51a3a07d..ed62e26ff 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -400,21 +400,24 @@ class InfoExtractor(object): self.set_downloader(downloader) @classmethod - def suitable(cls, url): - """Receives a URL and returns True if suitable for this IE.""" - + def valid_url_match(cls, url): # This does not use has/getattr intentionally - we want to know whether # we have cached the regexp for *this* class, whereas getattr would also # match the superclass if '_VALID_URL_RE' not in cls.__dict__: cls._VALID_URL_RE = re.compile(cls._VALID_URL) - return cls._VALID_URL_RE.match(url) is not None + m = cls._VALID_URL_RE.match(url) + return m + + @classmethod + def suitable(cls, url): + """Receives a URL and returns True if suitable for this IE.""" + m = cls.valid_url_match(url) + return m is not None @classmethod def _match_id(cls, url): - if '_VALID_URL_RE' not in cls.__dict__: - cls._VALID_URL_RE = re.compile(cls._VALID_URL) - m = cls._VALID_URL_RE.match(url) + m = cls.valid_url_match(url) assert m return compat_str(m.group('id'))