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.
This commit is contained in:
@@ -566,7 +566,7 @@ class PathFormat():
|
|||||||
|
|
||||||
def exists(self, archive=None):
|
def exists(self, archive=None):
|
||||||
"""Return True if the file exists on disk or in 'archive'"""
|
"""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()
|
return self.fix_extension()
|
||||||
if self.extension and os.path.exists(self.realpath):
|
if self.extension and os.path.exists(self.realpath):
|
||||||
return self.check_file()
|
return self.check_file()
|
||||||
@@ -719,8 +719,8 @@ class DownloadArchive():
|
|||||||
"archive-format", extractor.archive_fmt)
|
"archive-format", extractor.archive_fmt)
|
||||||
).format_map
|
).format_map
|
||||||
|
|
||||||
def check(self, kwdict):
|
def __contains__(self, kwdict):
|
||||||
"""Return True if item described by 'kwdict' exists in archive"""
|
"""Return True if the item described by 'kwdict' exists in archive"""
|
||||||
key = self.keygen(kwdict)
|
key = self.keygen(kwdict)
|
||||||
self.cursor.execute(
|
self.cursor.execute(
|
||||||
"SELECT 1 FROM archive WHERE entry=? LIMIT 1", (key,))
|
"SELECT 1 FROM archive WHERE entry=? LIMIT 1", (key,))
|
||||||
|
|||||||
Reference in New Issue
Block a user