25
25
26
26
27
27
class _InternalKeyHandler (dict ):
28
+ """Handler to load all internal keys of a single image.
29
+
30
+ Attributes:
31
+ _path: Apsolute path of the image to load the metadata of.
32
+ _reader: QImageReader or None of _path. Accessed via reder property.
33
+ """
34
+
28
35
def __init__ (self , path : str ):
29
36
super ().__init__ (
30
37
{
@@ -39,27 +46,38 @@ def __init__(self, path: str):
39
46
40
47
@property
41
48
def reader (self ) -> QImageReader :
49
+ """Return QImageReader instance of _path."""
42
50
if self ._reader is None :
43
51
self ._reader = QImageReader (self ._path )
44
52
return self ._reader
45
53
46
54
def _get_filesize (self ):
55
+ """Get the file size."""
47
56
return files .get_size_file (self ._path )
48
57
49
58
def _get_filetype (self ):
59
+ """Get the file type."""
50
60
return files .imghdr .what (self ._path )
51
61
52
62
def _get_xdimension (self ):
63
+ """Get the x dimension in pixels."""
53
64
return self .reader .size ().width ()
54
65
55
66
def _get_ydimension (self ):
67
+ """Get the y dimension in pixels."""
56
68
return self .reader .size ().height ()
57
69
58
70
def __getitem__ (self , key : str ) -> Tuple [str , str , str ]:
71
+ """Intrypoint to extract the key of the image at _path.
72
+
73
+ Args:
74
+ key: internal key to fetch.
75
+ """
59
76
key , func = super ().get (key .lower ())
60
77
return (key , key , func ())
61
78
62
79
def get_keys (self ) -> Iterable [str ]:
80
+ """Returns a sequence of all available metadata keys."""
63
81
return (key for key , _ in super ().values ())
64
82
65
83
@@ -94,6 +112,11 @@ def get_date_time(self) -> str:
94
112
self .raise_exception ("Retrieving exif date-time" )
95
113
96
114
def fetch_key (self , _base_key : str ) -> Tuple [str , str , str ]:
115
+ """Fetch a single metadata key.
116
+
117
+ Args:
118
+ _base_key: metadata key to fetch.
119
+ """
97
120
self .raise_exception ("Getting formatted keys" )
98
121
99
122
def get_keys (self ) -> Iterable [str ]:
@@ -269,6 +292,7 @@ def fetch_key(self, base_key: str) -> Tuple[str, str, str]:
269
292
return None
270
293
271
294
def get_keys (self ) -> Iterable [str ]:
295
+ """Return a iteable of all available metadata keys."""
272
296
return (key for key in self ._metadata if not is_hex (key .rpartition ("." )[2 ]))
273
297
274
298
def copy_metadata (self , dest : str , reset_orientation : bool = True ) -> None :
@@ -330,7 +354,13 @@ def _external_handler(self) -> ExternalKeyHandler:
330
354
return self ._ext_handler
331
355
332
356
def fetch_keys (self , desired_keys : Sequence [str ]) -> Dict [Any , Tuple [str , str ]]:
333
- """Throws: UnsupportedMetadataOperation"""
357
+ """Extracts a list of metadata keys.
358
+
359
+ Throws: UnsupportedMetadataOperation.
360
+
361
+ Args:
362
+ desired_keys: list of metadata keys to extract.
363
+ """
334
364
metadata = dict ()
335
365
336
366
for base_key in desired_keys :
@@ -344,6 +374,18 @@ def fetch_keys(self, desired_keys: Sequence[str]) -> Dict[Any, Tuple[str, str]]:
344
374
345
375
return metadata
346
376
377
+ def fetch_key (self , key : str ) -> Tuple [str , str , str ]:
378
+ """Extracts a single metadata key.
379
+
380
+ Throws: UnsupportedMetadataOperation.
381
+
382
+ Args:
383
+ key: single metadata key to extract.
384
+ """
385
+ if key .lower ().startswith ("vimiv" ):
386
+ return self ._internal_handler [key ]
387
+ return self ._external_handler .fetch_key (key )
388
+
347
389
def get_keys (self ) -> Iterable [str ]:
348
390
"""Retrieve the name of all metadata keys available.
349
391
@@ -353,12 +395,6 @@ def get_keys(self) -> Iterable[str]:
353
395
self ._internal_handler .get_keys (), self ._external_handler .get_keys ()
354
396
)
355
397
356
- def fetch_key (self , key : str ) -> Tuple [str , str , str ]:
357
- """Throws: UnsupportedMetadataOperation"""
358
- if key .lower ().startswith ("vimiv" ):
359
- return self ._internal_handler [key ]
360
- return self ._external_handler .fetch_key (key )
361
-
362
398
363
399
class ExifOrientation :
364
400
"""Namespace for exif orientation tags.
0 commit comments