Skip to content

Commit f19e8ce

Browse files
authored
Merge pull request #214 from IdentityPython/ft-minor_fixes
minor fixes
2 parents 648c5bc + 3757d7d commit f19e8ce

File tree

5 files changed

+31
-29
lines changed

5 files changed

+31
-29
lines changed

src/pyff/api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ def _fmt(data, accepter):
116116
raise exc.exception_response(406)
117117

118118

119-
def call(entry):
120-
requests.post('{}/api/call/{}'.format(config.base_url, entry))
119+
def call(entry: str) -> None:
120+
url = f'{config.base_url}/api/call/{entry}'
121+
log.debug(f'Calling API endpoint at {url}')
122+
resp = requests.post(url)
123+
if resp.status_code >= 300:
124+
log.error(f'POST request to API endpoint at {url} failed: {resp.status_code} {resp.reason}')
125+
return None
121126

122127

123128
def request_handler(request):

src/pyff/builtins.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def load(req, *opts):
596596
- max_workers <5> : Number of parallel threads to use for loading MD files
597597
- timeout <120> : Socket timeout when downloading files
598598
- validate <True*|False> : When true downloaded metadata files are validated (schema validation)
599-
- fail_on_error <True|False*> : Control whether an error during download, parsing or (optional)validatation of a MD file
599+
- fail_on_error <True|False*> : Control whether an error during download, parsing or (optional)validation of a MD file
600600
does not abort processing of the pipeline. When true a failure aborts and causes pyff
601601
to exit with a non zero exit code. Otherwise errors are logged but ignored.
602602
- filter_invalid <True*|False> : Controls validation behaviour. When true Entities that fail validation are filtered
@@ -713,7 +713,7 @@ def select(req, *opts):
713713
This would select all SPs
714714
715715
Select statements are not cumulative - a select followed by another select in the plumbing resets the
716-
working douments to the result of the second select.
716+
working documents to the result of the second select.
717717
718718
Most statements except local and remote depend on having a select somewhere in your plumbing and will
719719
stop the plumbing if the current working document is empty. For instance, running
@@ -799,7 +799,7 @@ def _match(q, elt):
799799
raise PipeException("empty select - stop")
800800

801801
if req.plumbing.id != name:
802-
log.debug("storing synthentic collection {}".format(name))
802+
log.debug("storing synthetic collection {}".format(name))
803803
req.store.update(ot, name)
804804

805805
return ot
@@ -886,7 +886,7 @@ def first(req, *opts):
886886
:return: returns the first entity descriptor if the working document only contains one
887887
888888
Sometimes (eg when running an MDX pipeline) it is usually expected that if a single EntityDescriptor is being returned
889-
then the outer EntitiesDescriptor is stripped. This method does exactly that:
889+
then the outer EntitiesDescriptor is stripped. This method does exactly that.
890890
891891
"""
892892
if req.t is None:
@@ -918,7 +918,7 @@ def _discojson(req, *opts):
918918
cache & converted to data: URIs
919919
920920
:param req: The request
921-
:param opts: Options (unusued)
921+
:param opts: Options (unused)
922922
:return: returns a JSON array
923923
924924
"""
@@ -1453,10 +1453,10 @@ def finalize(req, *opts):
14531453
:return: returns the working document with @Name, @cacheDuration and @validUntil set
14541454
14551455
Set Name, ID, cacheDuration and validUntil on the toplevel EntitiesDescriptor element of the working document.
1456-
Unlessexplicit provided the @Name is set from the request URI if the pipeline is executed in the pyFF server. The
1456+
Unless explicitly provided the @Name is set from the request URI if the pipeline is executed in the pyFF server. The
14571457
@ID is set to a string representing the current date/time and will be prefixed with the string provided, which
14581458
defaults to '_'. The @cacheDuration element must be a valid xsd duration (eg PT5H for 5 hrs) and @validUntil can
1459-
be either an absolute ISO 8601 time string or (more comonly) a relative time on the form
1459+
be either an absolute ISO 8601 time string or (more commonly) a relative time in the form
14601460
14611461
.. code-block:: none
14621462

src/pyff/locks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def acquireRead(self, blocking=True, timeout=None):
106106
finally:
107107
self.__condition.release()
108108

109-
@property
109+
@property # type: ignore
110110
@contextmanager
111111
def readlock(self):
112112
"""Yields a read lock"""
@@ -116,7 +116,7 @@ def readlock(self):
116116
finally:
117117
self.release()
118118

119-
@property
119+
@property # type: ignore
120120
@contextmanager
121121
def writelock(self):
122122
"""Yields a write lock"""

src/pyff/resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
3-
An abstraction layer for metadata fetchers. Supports both syncronous and asyncronous fetchers with cache.
3+
An abstraction layer for metadata fetchers. Supports both synchronous and asynchronous fetchers with cache.
44
55
"""
66

src/pyff/utils.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
from itertools import chain
2525
from threading import local
2626
from time import gmtime, strftime
27+
from typing import AnyStr, Optional, Union
2728

2829
import iso8601
2930
import pkg_resources
3031
import requests
31-
import six
3232
import xmlsec
33-
import yaml
3433
from _collections_abc import Mapping, MutableMapping
3534
from apscheduler.executors.pool import ThreadPoolExecutor
3635
from apscheduler.jobstores.memory import MemoryJobStore
@@ -43,22 +42,13 @@
4342
from requests.structures import CaseInsensitiveDict
4443
from requests_cache import CachedSession
4544
from requests_file import FileAdapter
46-
from six.moves.urllib_parse import quote_plus, urlparse
45+
from six.moves.urllib_parse import urlparse
4746

4847
from . import __version__
4948
from .constants import NS, config
5049
from .exceptions import *
5150
from .logs import get_log
5251

53-
try:
54-
from redis import StrictRedis
55-
except ImportError as ex:
56-
StrictRedis = None
57-
58-
try:
59-
from PIL import Image
60-
except ImportError as ex:
61-
Image = None
6252

6353
etree.set_default_parser(etree.XMLParser(resolve_entities=False))
6454

@@ -244,7 +234,9 @@ def redis():
244234
if not hasattr(thread_data, 'redis'):
245235
thread_data.redis = None
246236

247-
if StrictRedis is None:
237+
try:
238+
from redis import StrictRedis
239+
except ImportError:
248240
raise ValueError("redis_py missing from dependencies")
249241

250242
if thread_data.redis is None:
@@ -727,27 +719,32 @@ def url_get(url):
727719
return r
728720

729721

730-
def safe_b64e(data):
731-
if not isinstance(data, six.binary_type):
722+
def safe_b64e(data: Union[str, bytes]) -> str:
723+
if not isinstance(data, bytes):
732724
data = data.encode("utf-8")
733725
return base64.b64encode(data).decode('ascii')
734726

735727

736-
def safe_b64d(s):
728+
def safe_b64d(s: str) -> bytes:
737729
return base64.b64decode(s)
738730

739731

740732
# data:&lt;class 'type'&gt;;base64,
741733
# data:<class 'type'>;base64,
742734

743735

744-
def img_to_data(data, content_type):
736+
def img_to_data(data: bytes, content_type: str) -> Optional[str]:
745737
"""Convert a file (specified by a path) into a data URI."""
746738
mime_type, options = cgi.parse_header(content_type)
747739
data64 = None
748740
if len(data) > config.icon_maxsize:
749741
return None
750742

743+
try:
744+
from PIL import Image
745+
except ImportError:
746+
Image = None
747+
751748
if Image is not None:
752749
try:
753750
im = Image.open(io.BytesIO(data))

0 commit comments

Comments
 (0)