aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/cache.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-04-11 20:40:28 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-04-12 05:32:51 +0530
commit86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c (patch)
tree12558e4c8f24c1a8d16ccb63e2455b26c301285a /yt_dlp/cache.py
parentf9934b96145af8ac5dfdcbf684827aeaea9912a7 (diff)
downloadhypervideo-pre-86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c.tar.lz
hypervideo-pre-86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c.tar.xz
hypervideo-pre-86e5f3ed2e6e71eb81ea4c9e26288f16119ffd0c.zip
[cleanup] Upgrade syntax
Using https://github.com/asottile/pyupgrade 1. `__future__` imports and `coding: utf-8` were removed 2. Files were rewritten with `pyupgrade --py36-plus --keep-percent-format` 3. f-strings were cherry-picked from `pyupgrade --py36-plus` Extractors are left untouched (except removing header) to avoid unnecessary merge conflicts
Diffstat (limited to 'yt_dlp/cache.py')
-rw-r--r--yt_dlp/cache.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/yt_dlp/cache.py b/yt_dlp/cache.py
index e5cb193bc..f93ef85e7 100644
--- a/yt_dlp/cache.py
+++ b/yt_dlp/cache.py
@@ -1,7 +1,4 @@
-from __future__ import unicode_literals
-
import errno
-import io
import json
import os
import re
@@ -15,7 +12,7 @@ from .utils import (
)
-class Cache(object):
+class Cache:
def __init__(self, ydl):
self._ydl = ydl
@@ -31,7 +28,7 @@ class Cache(object):
'invalid section %r' % section
assert re.match(r'^[a-zA-Z0-9_.-]+$', key), 'invalid key %r' % key
return os.path.join(
- self._get_root_dir(), section, '%s.%s' % (key, dtype))
+ self._get_root_dir(), section, f'{key}.{dtype}')
@property
def enabled(self):
@@ -54,8 +51,7 @@ class Cache(object):
write_json_file(data, fn)
except Exception:
tb = traceback.format_exc()
- self._ydl.report_warning(
- 'Writing cache to %r failed: %s' % (fn, tb))
+ self._ydl.report_warning(f'Writing cache to {fn!r} failed: {tb}')
def load(self, section, key, dtype='json', default=None):
assert dtype in ('json',)
@@ -66,17 +62,16 @@ class Cache(object):
cache_fn = self._get_cache_fn(section, key, dtype)
try:
try:
- with io.open(cache_fn, 'r', encoding='utf-8') as cachef:
+ with open(cache_fn, encoding='utf-8') as cachef:
self._ydl.write_debug(f'Loading {section}.{key} from cache')
return json.load(cachef)
except ValueError:
try:
file_size = os.path.getsize(cache_fn)
- except (OSError, IOError) as oe:
+ except OSError as oe:
file_size = str(oe)
- self._ydl.report_warning(
- 'Cache retrieval from %s failed (%s)' % (cache_fn, file_size))
- except IOError:
+ self._ydl.report_warning(f'Cache retrieval from {cache_fn} failed ({file_size})')
+ except OSError:
pass # No cache available
return default