1
1
from __future__ import annotations
2
2
3
- from typing import TYPE_CHECKING , Generator , Optional , cast
3
+ from typing import TYPE_CHECKING , Generator , cast
4
4
5
5
from pypdf ._utils import parse_iso8824_date
6
6
from pypdf .constants import FileSpecificationDictionaryEntries
@@ -29,7 +29,7 @@ def __init__(self, name: str, pdf_object: DictionaryObject) -> None:
29
29
self .pdf_object = pdf_object
30
30
31
31
@property
32
- def alternative_name (self ) -> Optional [ str ] :
32
+ def alternative_name (self ) -> str | None :
33
33
"""Retrieve the alternative name (file specification)."""
34
34
for key in [FileSpecificationDictionaryEntries .UF , FileSpecificationDictionaryEntries .F ]:
35
35
# PDF 2.0 reference, table 43:
@@ -39,7 +39,7 @@ def alternative_name(self) -> Optional[str]:
39
39
return None
40
40
41
41
@property
42
- def description (self ) -> Optional [ str ] :
42
+ def description (self ) -> str | None :
43
43
"""Retrieve the description."""
44
44
return self .pdf_object .get (FileSpecificationDictionaryEntries .DESC )
45
45
@@ -65,7 +65,7 @@ def _params(self) -> DictionaryObject:
65
65
return self ._embedded_file .get ("/Params" , DictionaryObject ()).get_object ()
66
66
67
67
@property
68
- def subtype (self ) -> Optional [ str ] :
68
+ def subtype (self ) -> str | None :
69
69
"""Retrieve the subtype. This is a MIME media type, prefixed by a slash."""
70
70
return self ._embedded_file .get ("/Subtype" )
71
71
@@ -75,30 +75,30 @@ def content(self) -> bytes:
75
75
return self ._embedded_file .get_data ()
76
76
77
77
@property
78
- def size (self ) -> Optional [ int ] :
78
+ def size (self ) -> int | None :
79
79
"""Retrieve the size of the uncompressed file in bytes."""
80
80
return self ._params .get ("/Size" )
81
81
82
82
@property
83
- def creation_date (self ) -> Optional [ datetime .datetime ] :
83
+ def creation_date (self ) -> datetime .datetime | None :
84
84
"""Retrieve the file creation datetime."""
85
85
return parse_iso8824_date (self ._params .get ("/CreationDate" ))
86
86
87
87
@property
88
- def modification_date (self ) -> Optional [ datetime .datetime ] :
88
+ def modification_date (self ) -> datetime .datetime | None :
89
89
"""Retrieve the datetime of the last file modification."""
90
90
return parse_iso8824_date (self ._params .get ("/ModDate" ))
91
91
92
92
@property
93
- def checksum (self ) -> Optional [ bytes ] :
93
+ def checksum (self ) -> bytes | None :
94
94
"""Retrieve the MD5 checksum of the (uncompressed) file."""
95
95
return self ._params .get ("/CheckSum" )
96
96
97
97
def __repr__ (self ) -> str :
98
98
return f"<{ self .__class__ .__name__ } name={ self .name !r} >"
99
99
100
100
@classmethod
101
- def _load_from_names (cls , names : ArrayObject ) -> Generator [EmbeddedFile , None , None ]:
101
+ def _load_from_names (cls , names : ArrayObject ) -> Generator [EmbeddedFile ]:
102
102
"""
103
103
Convert the given name tree into class instances.
104
104
@@ -117,7 +117,7 @@ def _load_from_names(cls, names: ArrayObject) -> Generator[EmbeddedFile, None, N
117
117
yield EmbeddedFile (name = direct_name , pdf_object = file_dictionary )
118
118
119
119
@classmethod
120
- def _load (cls , catalog : DictionaryObject ) -> Generator [EmbeddedFile , None , None ]:
120
+ def _load (cls , catalog : DictionaryObject ) -> Generator [EmbeddedFile ]:
121
121
"""
122
122
Load the embedded files for the given document catalog.
123
123
0 commit comments