Skip to content

Commit cb5d3d3

Browse files
Move PyffException.
1 parent 44e2543 commit cb5d3d3

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/pyff/utils.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This module contains various utilities.
44
55
"""
6+
67
import base64
78
import cgi
89
import contextlib
@@ -45,7 +46,7 @@
4546

4647
from pyff import __version__
4748
from pyff.constants import NS, config
48-
from pyff.exceptions import *
49+
from pyff.exceptions import MetadataException, ResourceException
4950
from pyff.logs import get_log
5051

5152
etree.set_default_parser(etree.XMLParser(resolve_entities=False))
@@ -73,8 +74,8 @@ def debug_observer(e):
7374
log.error(repr(e))
7475

7576

76-
def trunc_str(x, l):
77-
return (x[:l] + '..') if len(x) > l else x
77+
def trunc_str(x, length):
78+
return (x[:length] + '..') if len(x) > length else x
7879

7980

8081
def resource_string(name: str, pfx: Optional[str] = None) -> Optional[Union[str, bytes]]:
@@ -143,7 +144,7 @@ def totimestamp(dt: datetime, epoch=datetime(1970, 1, 1)) -> int:
143144
epoch = epoch.replace(tzinfo=dt.tzinfo)
144145

145146
td = dt - epoch
146-
ts = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 1e6
147+
ts = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6
147148
return int(ts)
148149

149150

@@ -421,7 +422,7 @@ def filter_lang(elts: Any, langs: Optional[Sequence[str]] = None) -> list[Elemen
421422
raise RuntimeError('Configuration is missing langs')
422423

423424
dflt = langs[0]
424-
lst = [find_lang(elts, l, dflt) for l in langs]
425+
lst = [find_lang(elts, lang, dflt) for lang in langs]
425426
if len(lst) > 0:
426427
return lst
427428
else:
@@ -477,7 +478,7 @@ def total_seconds(dt: timedelta) -> float:
477478
if hasattr(dt, "total_seconds"):
478479
return dt.total_seconds()
479480
# TODO: Remove? I guess this is for Python < 3
480-
return (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10 ** 6) / 10 ** 6
481+
return (dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10**6) / 10**6
481482

482483

483484
def etag(s):
@@ -524,7 +525,7 @@ def has_tag(t, tag):
524525

525526

526527
def url2host(url):
527-
(host, sep, port) = urlparse(url).netloc.partition(':')
528+
(host, sep, _port) = urlparse(url).netloc.partition(':')
528529
return host
529530

530531

@@ -659,10 +660,10 @@ def is_text(x: Any) -> bool:
659660
return isinstance(x, str) or isinstance(x, str)
660661

661662

662-
def chunks(l, n):
663+
def chunks(input_list, n):
663664
"""Yield successive n-sized chunks from l."""
664-
for i in range(0, len(l), n):
665-
yield l[i : i + n]
665+
for i in range(0, len(input_list), n):
666+
yield input_list[i : i + n]
666667

667668

668669
class DirAdapter(BaseAdapter):
@@ -748,7 +749,7 @@ def safe_b64d(s: str) -> bytes:
748749

749750
def img_to_data(data: bytes, content_type: str) -> Optional[str]:
750751
"""Convert a file (specified by a path) into a data URI."""
751-
mime_type, options = cgi.parse_header(content_type)
752+
mime_type, _options = cgi.parse_header(content_type)
752753
data64 = None
753754
if len(data) > config.icon_maxsize:
754755
return None
@@ -952,7 +953,7 @@ def __init__(self):
952953
def add_watcher(self, cb, *args, **kwargs):
953954
self.watchers.append(Watchable.Watcher(cb, args, kwargs))
954955

955-
def remove_watcher(self, cb, *args, **kwargs):
956+
def remove_watcher(self, cb, *_args, **_kwargs):
956957
self.watchers.remove(Watchable.Watcher(cb))
957958

958959
def notify(self, *args, **kwargs):
@@ -966,5 +967,5 @@ def notify(self, *args, **kwargs):
966967

967968

968969
def utc_now() -> datetime:
969-
""" Return current time with tz=UTC """
970+
"""Return current time with tz=UTC"""
970971
return datetime.now(tz=timezone.utc)

0 commit comments

Comments
 (0)