diff --git a/api/config/__init__.py b/api/config/__init__.py index d3cd60b0d..e69de29bb 100644 --- a/api/config/__init__.py +++ b/api/config/__init__.py @@ -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 diff --git a/api/funkwhale_api/common/utils.py b/api/funkwhale_api/common/utils.py index f0d4b1970..19d43ad82 100644 --- a/api/funkwhale_api/common/utils.py +++ b/api/funkwhale_api/common/utils.py @@ -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()}" diff --git a/api/funkwhale_api/music/factories.py b/api/funkwhale_api/music/factories.py index eba9525b4..cf9b11a0a 100644 --- a/api/funkwhale_api/music/factories.py +++ b/api/funkwhale_api/music/factories.py @@ -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): diff --git a/api/funkwhale_api/music/licenses.py b/api/funkwhale_api/music/licenses.py index 2332f0908..1c8c6f4f8 100644 --- a/api/funkwhale_api/music/licenses.py +++ b/api/funkwhale_api/music/licenses.py @@ -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):