|
10 | 10 | from collections import deque |
11 | 11 | from datetime import datetime |
12 | 12 | from threading import Condition, Lock |
13 | | -from typing import Any, Callable, Deque, Dict, List, Optional, TYPE_CHECKING, Tuple, Union |
| 13 | +from typing import Any, Callable, Deque, Dict, Iterable, List, Optional, TYPE_CHECKING, Tuple, Union |
14 | 14 | from urllib.parse import quote as urlescape |
15 | 15 |
|
16 | 16 | import requests |
|
22 | 22 | from .exceptions import ResourceException |
23 | 23 | from .fetch import make_fetcher |
24 | 24 | from .logs import get_log |
25 | | -from .utils import Watchable, hex_digest, img_to_data, non_blocking_lock, resource_string, safe_write, url_get, utc_now |
| 25 | + |
| 26 | +from .utils import ( |
| 27 | + Watchable, |
| 28 | + hex_digest, |
| 29 | + img_to_data, |
| 30 | + non_blocking_lock, |
| 31 | + resource_string, |
| 32 | + safe_write, |
| 33 | + url_get, |
| 34 | + utc_now, |
| 35 | +) |
26 | 36 |
|
27 | 37 | if TYPE_CHECKING: |
28 | 38 | from .parse import PyffParser |
29 | 39 | from .pipes import PipelineCallback |
| 40 | + from .utils import Lambda |
30 | 41 |
|
31 | 42 | requests.packages.urllib3.disable_warnings() |
32 | 43 |
|
@@ -140,15 +151,20 @@ class ResourceOpts(BaseModel): |
140 | 151 | alias: Optional[str] = Field(None, alias='as') # TODO: Rename to 'name'? |
141 | 152 | # a certificate (file) or a SHA1 fingerprint to use for signature verification |
142 | 153 | verify: Optional[str] = None |
143 | | - via: List[Any] = Field([]) # list of PipelineCallback |
144 | | - # A list of PipelineCallback that can be used to pre-process parsed metadata before validation. Use as a clue-bat. |
145 | | - cleanup: List[Any] = Field([]) # list of PipelineCallback |
| 154 | + # TODO: move classes to make the correct typing work: Iterable[Union[Lambda, PipelineCallback]] = Field([]) |
| 155 | + via: List[Callable] = Field([]) |
| 156 | + # A list of callbacks that can be used to pre-process parsed metadata before validation. Use as a clue-bat. |
| 157 | + # TODO: sort imports to make the correct typing work: Iterable[PipelineCallback] = Field([]) |
| 158 | + cleanup: List[Callable] = Field([]) |
146 | 159 | fail_on_error: bool = False |
147 | 160 | # remove invalid EntityDescriptor elements rather than raise an error |
148 | 161 | filter_invalid: bool = True |
149 | 162 | # set to False to turn off all XML schema validation |
150 | 163 | validate_schema: bool = Field(True, alias='validate') |
151 | 164 |
|
| 165 | + class Config: |
| 166 | + arbitrary_types_allowed = True |
| 167 | + |
152 | 168 | def to_dict(self) -> Dict[str, Any]: |
153 | 169 | res = self.dict() |
154 | 170 | # Compensate for the 'alias' field options |
@@ -198,14 +214,17 @@ def local_copy_fn(self): |
198 | 214 | return os.path.join(config.local_copy_dir, urlescape(self.url)) |
199 | 215 |
|
200 | 216 | @property |
201 | | - def post(self) -> List['PipelineCallback']: |
| 217 | + def post( |
| 218 | + self, |
| 219 | + ) -> Iterable[Callable]: # TODO: move classes to make this work -> List[Union['Lambda', 'PipelineCallback']]: |
202 | 220 | return self.opts.via |
203 | 221 |
|
204 | | - def add_via(self, callback: 'PipelineCallback') -> None: |
| 222 | + def add_via(self, callback: Callable) -> None: |
| 223 | + # TODO: move classes to be able to declare callback: Union['Lambda', 'PipelineCallback'] |
205 | 224 | self.opts.via.append(callback) |
206 | 225 |
|
207 | 226 | @property |
208 | | - def cleanup(self) -> List['PipelineCallback']: |
| 227 | + def cleanup(self) -> Iterable[Callable]: # TODO: move classes to make this work -> Iterable['PipelineCallback']: |
209 | 228 | return self.opts.cleanup |
210 | 229 |
|
211 | 230 | def __str__(self): |
|
0 commit comments