Skip to content

Commit 591ada7

Browse files
committed
type, import and documentation fixes
1 parent ca63795 commit 591ada7

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/pyff/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import threading
33
from datetime import datetime, timedelta
44
from json import dumps
5-
from typing import Any, List, Mapping, Iterator
5+
from typing import Any, Iterable, List, Mapping
66

77
import pkg_resources
88
import pyramid.httpexceptions as exc
@@ -389,7 +389,7 @@ def resources_handler(request):
389389
:return: a JSON representation of the set of resources currently loaded by the server
390390
"""
391391

392-
def _infos(resources: Iterator[Resource]) -> List[Mapping[str, Any]]:
392+
def _infos(resources: Iterable[Resource]) -> List[Mapping[str, Any]]:
393393
return list(filter(lambda i: 'State' in i and i['State'] is not None, [_info(r) for r in resources]))
394394

395395
def _info(r: Resource) -> Mapping[str, Any]:

src/pyff/resource.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from .exceptions import ResourceException
2222
from .fetch import make_fetcher
2323
from .logs import get_log
24-
from .parse import parse_resource
2524
from .utils import Watchable, hex_digest, img_to_data, non_blocking_lock, resource_string, safe_write, url_get, utc_now
2625

2726
requests.packages.urllib3.disable_warnings()
@@ -363,6 +362,9 @@ def load_resource(self, getter: Callable[[str], Response]) -> Tuple[Optional[str
363362
def parse(self, getter):
364363
data, status, info = self.load_resource(getter)
365364
info['State'] = 'Parsing'
365+
# local import to avoid circular import
366+
from .parse import parse_resource
367+
366368
parse_info = parse_resource(self, data)
367369
if parse_info is not None and isinstance(parse_info, dict):
368370
info.update(parse_info)

src/pyff/samlmd.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime
44
from distutils.util import strtobool
55
from itertools import chain
6-
from typing import Any, Dict, Mapping, Optional
6+
from typing import Any, Dict, Mapping
77

88
from lxml import etree
99
from lxml.builder import ElementMaker
@@ -224,9 +224,11 @@ def parse(self, resource: Resource, content: str) -> Mapping[str, Any]:
224224
info['NextUpdate'] = next_update
225225
resource.expire_time = iso2datetime(next_update)
226226
elif config.respect_cache_duration:
227-
now = utc_now()
228-
now = now.replace(microsecond=0)
229-
next_update = now + duration2timedelta(config.default_cache_duration)
227+
_duration = duration2timedelta(config.default_cache_duration)
228+
if not _duration:
229+
raise ValueError('Invalid default_cache_duration')
230+
now = utc_now().replace(microsecond=0)
231+
next_update = now + _duration
230232
info['NextUpdate'] = next_update
231233
resource.expire_time = next_update
232234

@@ -377,9 +379,9 @@ def entitiesdescriptor(
377379
:param cache_duration: an XML timedelta expression, eg PT1H for 1hr
378380
:param valid_until: a relative time eg 2w 4d 1h for 2 weeks, 4 days and 1hour from now.
379381
:param copy: set to False to avoid making a copy of all the entities in list. This may be dangerous.
380-
:param validate: set to False to skip schema validation of the resulting EntitiesDesciptor element. This is dangerous!
381-
:param filter_invalid: remove invalid entitiesdescriptor elements from aggregate
382-
:param nsmap: additional namespace definitions to include in top level entitiesdescriptor element
382+
:param validate: set to False to skip schema validation of the resulting EntitiesDescriptor element. This is dangerous!
383+
:param filter_invalid: remove invalid EntitiesDescriptor elements from aggregate
384+
:param nsmap: additional namespace definitions to include in top level EntitiesDescriptor element
383385
384386
Produce an EntityDescriptors set from a list of entities. Optional Name, cacheDuration and validUntil are affixed.
385387
"""

0 commit comments

Comments
 (0)