Skip to content

Commit a7b4ed8

Browse files
Even more cleanup, fixing linting errors.
1 parent c64d591 commit a7b4ed8

File tree

6 files changed

+38
-33
lines changed

6 files changed

+38
-33
lines changed

scripts/csv2xrd.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99

1010
xrds = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}XRDS", nsmap=ns)
1111
with io.open(sys.argv[1]) as fd:
12-
for l in fd.readlines():
13-
l = l.strip()
14-
e = [x.strip('"') for x in l.split(",")]
15-
xrd = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}XRD", nsmap=ns)
16-
xrds.append(xrd)
17-
subject = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Subject", nsmap=ns)
18-
subject.text = e[3]
19-
link = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Link", nsmap=ns)
20-
link.set('rel',"urn:oasis:names:tc:SAML:2.0:metadata")
21-
link.set('href',e[3])
22-
xrd.append(subject)
23-
xrd.append(link)
24-
title = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Title", nsmap=ns)
25-
title.text = e[1]
26-
link.append(title)
12+
for line in fd.readlines():
13+
line = line.strip()
14+
e = [x.strip('"') for x in line.split(",")]
15+
xrd = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}XRD", nsmap=ns)
16+
xrds.append(xrd)
17+
subject = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Subject", nsmap=ns)
18+
subject.text = e[3]
19+
link = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Link", nsmap=ns)
20+
link.set('rel', "urn:oasis:names:tc:SAML:2.0:metadata")
21+
link.set('href', e[3])
22+
xrd.append(subject)
23+
xrd.append(link)
24+
title = etree.Element("{http://docs.oasis-open.org/ns/xri/xrd-1.0}Title", nsmap=ns)
25+
title.text = e[1]
26+
link.append(title)
2727

2828
print(etree.tostring(xrds, pretty_print=True))

src/pyff/builtins.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def fork(req: Plumbing.Request, *opts):
301301
def _any(lst, d):
302302
for x in lst:
303303
if x in d:
304-
if type(d) == dict:
304+
if d is dict:
305305
return d[x]
306306
else:
307307
return True
@@ -837,7 +837,7 @@ def select(req: Plumbing.Request, *opts):
837837
match = req.state['match']
838838

839839
if isinstance(match, str):
840-
query = [match.lower()]
840+
_query = [match.lower()]
841841

842842
def _strings(elt):
843843
lst = []
@@ -869,7 +869,7 @@ def _match(q, elt):
869869

870870
if q is not None and len(q) > 0:
871871
tokens = _strings(elt)
872-
p = re.compile(fr'\b{q}', re.IGNORECASE)
872+
p = re.compile(rf'\b{q}', re.IGNORECASE)
873873
for tstr in tokens:
874874
if p.search(tstr):
875875
return tstr

src/pyff/constants.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,9 @@ def parse_options(program, docs):
523523

524524
if config.loglevel is None:
525525
config.loglevel = 'INFO'
526-
527-
if config.aliases is None or len(config.aliases) == 0:
528-
config.aliases = dict(metadata=entities)
526+
# FIXME, don't know what this is, but it is wrong.
527+
# if config.aliases is None or len(config.aliases) == 0:
528+
# config.aliases = dict(metadata=entities)
529529

530530
if config.modules is None:
531531
config.modules = []

src/pyff/parse.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _format_key(k: str) -> str:
2727
# Turn expiration_time into 'Expiration Time'
2828
return k.replace('_', ' ').title()
2929

30-
res = {_format_key(k): v for k, v in self.dict().items()}
30+
res = {_format_key(k): v for k, v in self.model_dump().items()}
3131
return res
3232

3333

@@ -114,7 +114,7 @@ def parse(self, resource: Resource, content: str) -> ParserInfo:
114114
info = ParserInfo(description='XRD links', expiration_time='never expires')
115115
t = parse_xml(unicode_stream(content))
116116

117-
relt = root(t)
117+
_relt = root(t)
118118
for xrd in t.iter("{%s}XRD" % NS['xrd']):
119119
for link in xrd.findall(".//{{{}}}Link[@rel='{}']".format(NS['xrd'], NS['md'])):
120120
link_href = link.get("href")

src/pyff/samlmd.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
from .resource import Resource, ResourceOpts
1717

1818
from pyff.constants import ATTRS, NF_URI, NS, config
19-
from pyff.exceptions import *
19+
from pyff.exceptions import MetadataException
2020
from pyff.logs import get_log
2121
from pyff.parse import ParserInfo, PyffParser, add_parser
22-
from pyff.resource import Resource, ResourceOpts
2322
from pyff.utils import (
2423
Lambda,
2524
b2u,
@@ -262,7 +261,7 @@ def _format_key(k: str) -> str:
262261
# Turn expiration_time into 'Expiration Time'
263262
return k.replace('_', ' ').title()
264263

265-
res = {_format_key(k): v for k, v in self.dict().items()}
264+
res = {_format_key(k): v for k, v in self.model_dump().items()}
266265
return res
267266

268267

@@ -371,7 +370,7 @@ def filter_invalids_from_document(t: ElementTree, base_url, validation_errors) -
371370
xsd = schema()
372371
for e in iter_entities(t):
373372
if not xsd.validate(e):
374-
error = xml_error(xsd.error_log, m=base_url)
373+
_error = xml_error(xsd.error_log, m=base_url)
375374
entity_id = e.get("entityID", "(Missing entityID)")
376375
log.warning('removing \'{}\': schema validation failed: {}'.format(entity_id, xsd.error_log))
377376
validation_errors[entity_id] = f"{xsd.error_log}"
@@ -703,7 +702,7 @@ def _u(an, values):
703702

704703

705704
def gen_icon(e):
706-
scopes = entity_scopes(e)
705+
_scopes = entity_scopes(e)
707706

708707

709708
def entity_icon_url(e, langs=None):
@@ -990,7 +989,9 @@ def discojson_sp(e, global_trust_info=None, global_md_sources=None):
990989
sp['entityID'] = e.get('entityID', None)
991990

992991
md_sources = e.findall(
993-
"{{{}}}SPSSODescriptor/{{{}}}Extensions/{{{}}}TrustInfo/{{{}}}MetadataSource".format(NS['md'], NS['md'], NS['ti'], NS['ti'])
992+
"{{{}}}SPSSODescriptor/{{{}}}Extensions/{{{}}}TrustInfo/{{{}}}MetadataSource".format(
993+
NS['md'], NS['md'], NS['ti'], NS['ti']
994+
)
994995
)
995996

996997
sp['extra_md'] = {}
@@ -1294,7 +1295,9 @@ def _entity_attributes(e):
12941295

12951296
def _eattribute(e, attr, nf):
12961297
ea = _entity_attributes(e)
1297-
a = ea.xpath(".//saml:Attribute[@NameFormat='{}' and @Name='{}']".format(nf, attr), namespaces=NS, smart_strings=False)
1298+
a = ea.xpath(
1299+
".//saml:Attribute[@NameFormat='{}' and @Name='{}']".format(nf, attr), namespaces=NS, smart_strings=False
1300+
)
12981301
if a is None or len(a) == 0:
12991302
a = etree.Element("{%s}Attribute" % NS['saml'])
13001303
a.set('NameFormat', nf)

src/pyff/tools.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[--version]
77
[uri1] [uri2]
88
"""
9+
910
import logging
1011
import sys
1112
import traceback
@@ -19,7 +20,8 @@
1920
from pyff.store import MemoryStore
2021

2122

22-
def difftool():
23+
# TODO: Is this even working? remove?
24+
def difftool(r1, r2):
2325
"""
2426
diff two saml metadata sources
2527
"""
@@ -31,12 +33,12 @@ def difftool():
3133

3234
try:
3335
rm = Resource()
36+
r1 = Resource(url=args[0], opts=ResourceOpts())
37+
r2 = Resource(url=args[1], opts=ResourceOpts())
3438
rm.add(r1)
3539
rm.add(r2)
3640
store = MemoryStore()
3741
rm.reload(store=store)
38-
r1 = Resource(url=args[0], opts=ResourceOpts())
39-
r2 = Resource(url=args[1], opts=ResourceOpts())
4042
status = 0
4143

4244
if r1.t.get('Name') != r2.t.get('Name'):

0 commit comments

Comments
 (0)