sdata 0.23.0__tar.gz → 0.23.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sdata-0.23.0/sdata.egg-info → sdata-0.23.1}/PKG-INFO +1 -1
- {sdata-0.23.0 → sdata-0.23.1}/sdata/__init__.py +1 -1
- {sdata-0.23.0 → sdata-0.23.1}/sdata/data.py +1 -1
- {sdata-0.23.0 → sdata-0.23.1}/sdata/image.py +80 -3
- {sdata-0.23.0 → sdata-0.23.1/sdata.egg-info}/PKG-INFO +1 -1
- {sdata-0.23.0 → sdata-0.23.1}/LICENSE-MIT +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/MANIFEST.in +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/README.md +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/blob.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/attrdict/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/attrdict/default.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/attrdict/dictionary.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/attrdict/mapping.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/attrdict/merge.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/attrdict/mixins.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_common.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_dump.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_exceptions.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_exif.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_insert.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_load.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_remove.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_transplant.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/_webp.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/piexif/helper.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/collections/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/collections/rangebucketmap.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/collections/rangemap.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/collections/rangeset.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/range/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/range/cut.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/ranger/range/range.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/semver.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/simple_graph_db/LICENSE +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/simple_graph_db/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/simple_graph_db/database.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/simple_graph_db/schema.sql +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sobol_seq.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sortedcontainers/LICENSE +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sortedcontainers/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sortedcontainers/sorteddict.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sortedcontainers/sortedlist.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sortedcontainers/sortedset.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/sqlitedict.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/timeflake/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/timeflake/flake.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/contrib/timeflake/utils.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/doe.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/experiments/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/experiments/ks2.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/experiments/lapshear.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/experiments/material.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/db.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/hdf.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/isomme.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/pgp.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/pud.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/simple_signature.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/iolib/vault.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/metadata.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/suuid.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/timestamp.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/tools.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata/workbook.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata.egg-info/SOURCES.txt +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata.egg-info/dependency_links.txt +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata.egg-info/requires.txt +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/sdata.egg-info/top_level.txt +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/setup.cfg +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/setup.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/iolib/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/iolib/pud/__init__.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/iolib/pud/test_pud.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/iolib/test_hdf.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_attribute.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_blob.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_data.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_image.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_io.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_ks2.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_metadata.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_sqlite.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_suuid.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_table.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_testprogram.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_timeflake.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_timestamp.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_tools.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_vault.py +0 -0
- {sdata-0.23.0 → sdata-0.23.1}/tests/test_workbook.py +0 -0
|
@@ -12,6 +12,8 @@ import sdata.contrib.piexif
|
|
|
12
12
|
import sdata.contrib.piexif.helper
|
|
13
13
|
import json
|
|
14
14
|
import os
|
|
15
|
+
from io import BytesIO
|
|
16
|
+
import base64
|
|
15
17
|
import hashlib
|
|
16
18
|
try:
|
|
17
19
|
import PIL
|
|
@@ -47,15 +49,68 @@ class Image(Data):
|
|
|
47
49
|
def _from_filepath(cls, filepath, **kwargs):
|
|
48
50
|
"""read image from file
|
|
49
51
|
|
|
52
|
+
:param fielpath: image file path
|
|
53
|
+
:return: sdata.Image
|
|
50
54
|
"""
|
|
51
55
|
project = kwargs.get("project")
|
|
52
56
|
suuid = SUUID.from_file(cls.__class__.__name__, filepath, ns_name=project)
|
|
53
57
|
kwargs["uuid"] = suuid.huuid
|
|
54
58
|
kwargs["url"] = filepath
|
|
55
|
-
|
|
56
59
|
data = cls(name=os.path.basename(filepath), **kwargs)
|
|
57
60
|
return data
|
|
58
61
|
|
|
62
|
+
@classmethod
|
|
63
|
+
def from_image(cls, name, img, **kwargs):
|
|
64
|
+
"""read image from PIL.Image
|
|
65
|
+
|
|
66
|
+
"""
|
|
67
|
+
project = kwargs.get("project", "")
|
|
68
|
+
parent = kwargs.get("parent", "")
|
|
69
|
+
class_name = "Image" #cls.__class__.__name__
|
|
70
|
+
|
|
71
|
+
sh = hashlib.sha3_256()
|
|
72
|
+
sh.update(img.tobytes())
|
|
73
|
+
suuid = SUUID.from_name(class_name=class_name, name=sh.hexdigest(), ns_name=project)
|
|
74
|
+
suuid.project = project
|
|
75
|
+
kwargs["parent"] = parent
|
|
76
|
+
kwargs["project"] = suuid.project
|
|
77
|
+
kwargs["sname"] = suuid.sname
|
|
78
|
+
kwargs["uuid"] = suuid.huuid
|
|
79
|
+
kwargs["suuid"] = suuid.idstr
|
|
80
|
+
kwargs["url"] = sdata.osname(name)
|
|
81
|
+
# name = os.path.basename(filepath)
|
|
82
|
+
data = cls(name=name, **kwargs)
|
|
83
|
+
data.img = img
|
|
84
|
+
return data
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@classmethod
|
|
88
|
+
def from_bytes(cls, name, image_data, **kwargs):
|
|
89
|
+
"""read image from file
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
project = kwargs.get("project")
|
|
93
|
+
class_name = "Image" #cls.__class__.__name__
|
|
94
|
+
suuid = SUUID.from_str(class_name, name, ns_name=project)
|
|
95
|
+
kwargs["sname"] = suuid.sname
|
|
96
|
+
kwargs["uuid"] = suuid.huuid
|
|
97
|
+
kwargs["suuid"] = suuid.idstr
|
|
98
|
+
kwargs["url"] = name
|
|
99
|
+
data = cls(name=name, **kwargs)
|
|
100
|
+
data.img = PIL.Image.open(BytesIO(image_data))
|
|
101
|
+
try:
|
|
102
|
+
d = None
|
|
103
|
+
if name.lower().endswith(".png"):
|
|
104
|
+
d = cls._get_png_metadata(image_data)
|
|
105
|
+
elif name.lower().endswith(("jpg", "jpeg")):
|
|
106
|
+
d = cls._get_jpg_metadata(image_data)
|
|
107
|
+
if d is not None:
|
|
108
|
+
data.metadata = data.metadata.from_json(d)
|
|
109
|
+
except:
|
|
110
|
+
pass
|
|
111
|
+
return data
|
|
112
|
+
|
|
113
|
+
|
|
59
114
|
@classmethod
|
|
60
115
|
def from_file(cls, filepath, **kwargs):
|
|
61
116
|
"""read image from file
|
|
@@ -73,7 +128,7 @@ class Image(Data):
|
|
|
73
128
|
|
|
74
129
|
if filepath.lower().endswith(".png"):
|
|
75
130
|
data = cls.from_png(filepath, **kwargs)
|
|
76
|
-
elif filepath.lower().endswith("
|
|
131
|
+
elif filepath.lower().endswith(("jpg", "jpeg")):
|
|
77
132
|
data = cls.from_jpg(filepath, **kwargs)
|
|
78
133
|
else:
|
|
79
134
|
data = cls(name=name, **kwargs)
|
|
@@ -228,4 +283,26 @@ class Image(Data):
|
|
|
228
283
|
json_string = json.dumps(self.metadata.to_json())
|
|
229
284
|
exif_dict = {"Exif": {sdata.contrib.piexif.ExifIFD.UserComment: sdata.contrib.piexif.helper.UserComment.dump(json_string)}}
|
|
230
285
|
exif_bytes = sdata.contrib.piexif.dump(exif_dict)
|
|
231
|
-
self.img.save(filepath, "jpeg", exif=exif_bytes)
|
|
286
|
+
self.img.save(filepath, "jpeg", exif=exif_bytes)
|
|
287
|
+
|
|
288
|
+
def get_image_download_link(self, img, filename, text):
|
|
289
|
+
|
|
290
|
+
json_string = json.dumps(self.metadata.to_json())
|
|
291
|
+
buffered = BytesIO()
|
|
292
|
+
|
|
293
|
+
if filename.endswith(".png"):
|
|
294
|
+
metadaten = PIL.PngImagePlugin.PngInfo()
|
|
295
|
+
metadaten.add_text("sdata", json_string)
|
|
296
|
+
img.save(buffered, "PNG", pnginfo=metadaten)
|
|
297
|
+
elif filename.lower().endswith(".jpg"):
|
|
298
|
+
exif_dict = {"Exif": {
|
|
299
|
+
sdata.contrib.piexif.ExifIFD.UserComment: sdata.contrib.piexif.helper.UserComment.dump(json_string)}}
|
|
300
|
+
exif_bytes = sdata.contrib.piexif.dump(exif_dict)
|
|
301
|
+
img.save(buffered, format="JPEG", exif=exif_bytes)
|
|
302
|
+
else:
|
|
303
|
+
logging.warning(f"metadata not supported for {filepath}")
|
|
304
|
+
img.save(buffered)
|
|
305
|
+
|
|
306
|
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
|
307
|
+
href = f'<a href="data:file/txt;base64,{img_str}" download="{filename}">{text}</a>'
|
|
308
|
+
return href
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|