replace DownloadArchive.check() with __contains__()

Interestingly enough, 'a in obj' is slightly faster than
'obj.check(a)' and is also nicer to look at, I think.
deviantart-rewrite
Mike Fährmann 5 years ago
parent 5a210991b6
commit f5039b897f
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -566,7 +566,7 @@ class PathFormat():
def exists(self, archive=None):
"""Return True if the file exists on disk or in 'archive'"""
if archive and archive.check(self.kwdict):
if archive and self.kwdict in archive:
return self.fix_extension()
if self.extension and os.path.exists(self.realpath):
return self.check_file()
@ -719,8 +719,8 @@ class DownloadArchive():
"archive-format", extractor.archive_fmt)
).format_map
def check(self, kwdict):
"""Return True if item described by 'kwdict' exists in archive"""
def __contains__(self, kwdict):
"""Return True if the item described by 'kwdict' exists in archive"""
key = self.keygen(kwdict)
self.cursor.execute(
"SELECT 1 FROM archive WHERE entry=? LIMIT 1", (key,))

Loading…
Cancel
Save