Skip to content

Commit

Permalink
Fix pylint errors R0904 and R0915.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
  • Loading branch information
audetto committed Nov 17, 2023
1 parent cb5c836 commit ae848f0
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions diskcache/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __repr__(self):
'misses': 0,
}

# TODO: these cannot be verified for a read_only database
# these cannot be verified for a read_only database
UNVERIFIABLE_SETTINGS = ['sqlite_query_only']

EVICTION_POLICY = {
Expand Down Expand Up @@ -508,25 +508,7 @@ def __init__(self, directory=None, timeout=60, disk=Disk, **settings):
}
self._disk = disk(directory, **kwargs)

# Set cached attributes: updates settings and sets pragmas.

for key, value in sets.items():
if self.sqlite_query_only:
query = 'SELECT value FROM Settings WHERE key = ?'
db_value = sql(query, (key,)).fetchall()
assert len(db_value) == 1
if key not in UNVERIFIABLE_SETTINGS:
assert value == db_value[0][0]
else:
query = 'INSERT OR REPLACE INTO Settings VALUES (?, ?)'
sql(query, (key, value))
self.reset(key, value, update=not self.sqlite_query_only)

for key, value in METADATA.items():
if not self.sqlite_query_only:
query = 'INSERT OR IGNORE INTO Settings VALUES (?, ?)'
sql(query, (key, value))
self.reset(key, update=not self.sqlite_query_only)
self._synch_settings(sets, sql)

((self._page_size,),) = sql('PRAGMA page_size').fetchall()

Expand Down Expand Up @@ -614,6 +596,27 @@ def __init__(self, directory=None, timeout=60, disk=Disk, **settings):
self._timeout = timeout
self._sql # pylint: disable=pointless-statement

def _synch_settings(self, sets, sql):
# Set cached attributes: updates settings and sets pragmas.

for key, value in sets.items():
if self.sqlite_query_only:
query = 'SELECT value FROM Settings WHERE key = ?'
db_value = sql(query, (key,)).fetchall()
assert len(db_value) == 1
if key not in UNVERIFIABLE_SETTINGS:
assert value == db_value[0][0]
else:
query = 'INSERT OR REPLACE INTO Settings VALUES (?, ?)'
sql(query, (key, value))
self.reset(key, value, update=not self.sqlite_query_only)

for key, value in METADATA.items():
if not self.sqlite_query_only:
query = 'INSERT OR IGNORE INTO Settings VALUES (?, ?)'
sql(query, (key, value))
self.reset(key, update=not self.sqlite_query_only)

@property
def directory(self):
"""Cache directory."""
Expand Down

0 comments on commit ae848f0

Please sign in to comment.