oarepo-runtime 1.5.35__py3-none-any.whl → 1.5.37__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ import mimetypes
2
+ import os
3
+ from invenio_records_resources.services.files.components import FileServiceComponent
4
+ from marshmallow.exceptions import ValidationError
5
+
6
+ class AllowedFileTypesComponent(FileServiceComponent):
7
+
8
+ def guess_content_type(self, filename: str | None) -> str | None:
9
+ if filename:
10
+ return mimetypes.guess_type(filename)[0] or "application/octet-stream"
11
+ return None
12
+
13
+ @property
14
+ def allowed_mimetypes(self):
15
+ """Returns files attribute (field) key."""
16
+ return getattr(self.service.config, "allowed_mimetypes", [])
17
+
18
+ def guess_extension(self, file, mimetype):
19
+ """File extension."""
20
+ # The ``ext`` property is used to in search to aggregate file types, and we want e.g. both ``.jpeg`` and
21
+ # ``.jpg`` to be aggregated under ``.jpg``
22
+ ext_guessed = mimetypes.guess_extension(mimetype)
23
+
24
+ # Check if a valid extension is guessed and it's not the default mimetype
25
+ if (
26
+ ext_guessed is not None
27
+ and mimetype != "application/octet-stream"
28
+ ):
29
+ return ext_guessed[1:]
30
+
31
+ # Support non-standard file extensions that cannot be guessed
32
+ _, ext = os.path.splitext(file)
33
+ if ext and len(ext) <= 5:
34
+ return ext[1:].lower()
35
+
36
+ if ext_guessed:
37
+ return ext_guessed[1:]
38
+
39
+ @property
40
+ def allowed_extensions(self):
41
+ """Returns files attribute (field) key."""
42
+ return getattr(self.service.config, "allowed_extensions", [])
43
+
44
+ def init_files(self, identity, id_, data, uow=None):
45
+ """Initialize the file upload for the record."""
46
+ list_files = list(data.files.entries)
47
+
48
+ for file in list_files:
49
+ allowed_type = self.guess_content_type(file)
50
+ allowed_ext = self.guess_extension(file, allowed_type)
51
+ if len(self.allowed_mimetypes) > 0 and allowed_type not in self.allowed_mimetypes:
52
+ raise ValidationError(f"Mimetype not supported, supported mimetypes: {self.allowed_mimetypes}")
53
+ elif len(self.allowed_extensions) > 0 and allowed_ext not in self.allowed_extensions:
54
+ raise ValidationError(f"Extension not supported, supported extensions: {self.allowed_extensions}")
55
+
@@ -130,3 +130,4 @@ class InvenioUISchema(ma.Schema):
130
130
  updated = LocalizedDateTime(dump_only=True)
131
131
  links = ma.fields.Raw(dump_only=True)
132
132
  revision_id = ma.fields.Integer(dump_only=True)
133
+ expanded = ma.fields.Raw(dump_only=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.35
3
+ Version: 1.5.37
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -89,6 +89,7 @@ oarepo_runtime/services/facets/max_facet.py,sha256=TZ4KMKKVJHzyU1KgNne4V7IMQPu1A
89
89
  oarepo_runtime/services/facets/nested_facet.py,sha256=y0xgjx37HsSj2xW7URxNemYTksD8hpPs7kOEfIBw22k,971
90
90
  oarepo_runtime/services/facets/params.py,sha256=5z8I4wKdp-7RJK4x6cSKE92fDJI8OkUz5JR5UKWAeYg,3564
91
91
  oarepo_runtime/services/files/__init__.py,sha256=K8MStrEQf_BUhvzhwPTF93Hkhwrd1dtv35LDo7iZeTM,268
92
+ oarepo_runtime/services/files/components.py,sha256=yQpZ0rCaIUkECPZMZ4aH2m1NIRlEWPgiPPV_6yUoPbY,2272
92
93
  oarepo_runtime/services/files/service.py,sha256=8DH0Pefr9kilM2JnOb-UYsnqerE8Z1Mu4p6DOJ4j_ZU,608
93
94
  oarepo_runtime/services/relations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
94
95
  oarepo_runtime/services/relations/components.py,sha256=3g0VdnGUM-2yYt50fPi-OADReBGJb4h05vmYHfh-QFs,592
@@ -102,7 +103,7 @@ oarepo_runtime/services/schema/i18n_validation.py,sha256=fyMTi2Rw-KiHv7c7HN61zGx
102
103
  oarepo_runtime/services/schema/marshmallow.py,sha256=LmcSxvbZ9jIhkNHCqqxt1SA2UNijoDmIzqli1MkoTrE,1153
103
104
  oarepo_runtime/services/schema/oneofschema.py,sha256=X_pXzrkYcLGGAtGN1qltrz45OzD_atrJHkHkp3L01xg,6660
104
105
  oarepo_runtime/services/schema/polymorphic.py,sha256=f9yC7MGVynAFGM0fXIq0NbqGJxI65Xpi8GaM2ZM4c6Q,561
105
- oarepo_runtime/services/schema/ui.py,sha256=qDR-nukJmeLwDZCdqcBg3CbseQ_A_BdxXyt_R4Qc_2c,3732
106
+ oarepo_runtime/services/schema/ui.py,sha256=xQgW-zLyZoHldGw47uVtXQj-5LexVNKTholyq4MiBZo,3777
106
107
  oarepo_runtime/services/schema/validation.py,sha256=fahqKGDdIYWux5ZeoljrEe8VD2fDZR9VpfvYmTYAmpw,1050
107
108
  oarepo_runtime/translations/default_translations.py,sha256=060GBlA1ghWxfeumo6NqxCCZDb-6OezOuF6pr-_GEOQ,104
108
109
  oarepo_runtime/translations/jinjax_messages.jinja,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -115,9 +116,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
115
116
  oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
116
117
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
117
118
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
118
- oarepo_runtime-1.5.35.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
119
- oarepo_runtime-1.5.35.dist-info/METADATA,sha256=ov1D4zGmQwPC2LNFD5obBpcphrCt9GsW3dfByS_XNYc,4680
120
- oarepo_runtime-1.5.35.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
121
- oarepo_runtime-1.5.35.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
122
- oarepo_runtime-1.5.35.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
123
- oarepo_runtime-1.5.35.dist-info/RECORD,,
119
+ oarepo_runtime-1.5.37.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
120
+ oarepo_runtime-1.5.37.dist-info/METADATA,sha256=9DcMboRlkhaXmUfLa6t8nUSTjoCJS26u7e2OjxXb7jI,4680
121
+ oarepo_runtime-1.5.37.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
122
+ oarepo_runtime-1.5.37.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
123
+ oarepo_runtime-1.5.37.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
124
+ oarepo_runtime-1.5.37.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (70.1.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5