fix(api): pylint crashes on redefined-builtin
See https://github.com/PyCQA/pylint/issues/8079 Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2203>
This commit is contained in:
parent
6806adb4f5
commit
6528039e95
|
@ -1,3 +0,0 @@
|
|||
# loads what is required to generate the swagger docs
|
||||
# https://matrix.to/#/!nNBDNverFlbfNpReEO:matrix.org/$16579878472182UmZUv:tchncs.de?via=tchncs.de&via=matrix.org&via=juniorjpdj.pl
|
||||
import config.schema # noqa: F401
|
|
@ -477,14 +477,13 @@ def monkey_patch_request_build_absolute_uri():
|
|||
def get_file_hash(file, algo=None, chunk_size=None, full_read=False):
|
||||
algo = algo or settings.HASHING_ALGORITHM
|
||||
chunk_size = chunk_size or settings.HASHING_CHUNK_SIZE
|
||||
handler = getattr(hashlib, algo)
|
||||
hash = handler()
|
||||
hasher = hashlib.new(algo)
|
||||
file.seek(0)
|
||||
if full_read:
|
||||
for byte_block in iter(lambda: file.read(chunk_size), b""):
|
||||
hash.update(byte_block)
|
||||
hasher.update(byte_block)
|
||||
else:
|
||||
# sometimes, it's useful to only hash the beginning of the file, e.g
|
||||
# to avoid a lot of I/O when crawling large libraries
|
||||
hash.update(file.read(chunk_size))
|
||||
return f"{algo}:{hash.hexdigest()}"
|
||||
hasher.update(file.read(chunk_size))
|
||||
return f"{algo}:{hasher.hexdigest()}"
|
||||
|
|
|
@ -151,8 +151,9 @@ class TrackFactory(
|
|||
if created:
|
||||
self.save()
|
||||
|
||||
@factory.post_generation
|
||||
def license(self, created, extracted, **kwargs):
|
||||
# The @factory.post_generation is not used because we must
|
||||
# not redefine the builtin `license` function.
|
||||
def _license_post_generation(self, created, extracted, **kwargs):
|
||||
if not created:
|
||||
return
|
||||
|
||||
|
@ -160,6 +161,8 @@ class TrackFactory(
|
|||
self.license = LicenseFactory(code=extracted)
|
||||
self.save()
|
||||
|
||||
license = factory.PostGeneration(_license_post_generation)
|
||||
|
||||
|
||||
@registry.register
|
||||
class UploadFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
||||
|
|
|
@ -28,7 +28,7 @@ def load(data):
|
|||
|
||||
for row in data:
|
||||
try:
|
||||
license = existing_by_code[row["code"]]
|
||||
license_ = existing_by_code[row["code"]]
|
||||
except KeyError:
|
||||
logger.debug("Loading new license: {}".format(row["code"]))
|
||||
to_create.append(
|
||||
|
@ -36,15 +36,15 @@ def load(data):
|
|||
)
|
||||
else:
|
||||
logger.debug("Updating license: {}".format(row["code"]))
|
||||
stored = [getattr(license, f) for f in MODEL_FIELDS]
|
||||
stored = [getattr(license_, f) for f in MODEL_FIELDS]
|
||||
wanted = [row[f] for f in MODEL_FIELDS]
|
||||
if wanted == stored:
|
||||
continue
|
||||
# the object in database needs an update
|
||||
for f in MODEL_FIELDS:
|
||||
setattr(license, f, row[f])
|
||||
setattr(license_, f, row[f])
|
||||
|
||||
license.save()
|
||||
license_.save()
|
||||
|
||||
models.License.objects.bulk_create(to_create)
|
||||
return sorted(models.License.objects.all(), key=lambda o: o.code)
|
||||
|
@ -78,12 +78,12 @@ def match(*values):
|
|||
else:
|
||||
existing = load(LICENSES)
|
||||
_cache = existing
|
||||
for license in existing:
|
||||
if license.conf is None:
|
||||
for license_ in existing:
|
||||
if license_.conf is None:
|
||||
continue
|
||||
for i in license.conf["identifiers"]:
|
||||
for i in license_.conf["identifiers"]:
|
||||
if match_urls(url, i):
|
||||
return license
|
||||
return license_
|
||||
|
||||
|
||||
def match_urls(*urls):
|
||||
|
|
Loading…
Reference in New Issue