Skip to content

Commit 47be71c

Browse files
Fix Pydantic deprecation copy > model_copy
1 parent 74b911d commit 47be71c

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

src/pyff/builtins.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def fork(req: Plumbing.Request, *opts):
256256
**parsecopy**
257257
258258
Due to a hard to find bug, fork which uses deepcopy can lose some namespaces. The parsecopy argument is a workaround.
259-
It uses a brute force serialisation and deserialisation to get around the bug.
259+
It uses a brute force serialisation and deserialisation to get around the bug.
260260
261261
.. code-block:: yaml
262262
@@ -676,7 +676,7 @@ def load(req: Plumbing.Request, *opts):
676676
url = r.pop(0)
677677

678678
# Copy parent node opts as a starting point
679-
child_opts = req.md.rm.opts.copy(update={"via": [], "cleanup": [], "verify": None, "alias": url})
679+
child_opts = req.md.rm.opts.model_copy(update={"via": [], "cleanup": [], "verify": None, "alias": url})
680680

681681
while len(r) > 0:
682682
elt = r.pop(0)
@@ -702,7 +702,7 @@ def load(req: Plumbing.Request, *opts):
702702
child_opts.verify = elt
703703

704704
# override anything in child_opts with what is in opts
705-
child_opts = child_opts.copy(update=_opts)
705+
child_opts = child_opts.model_copy(update=_opts)
706706

707707
req.md.rm.add_child(url, child_opts)
708708

@@ -814,7 +814,7 @@ def select(req: Plumbing.Request, *opts):
814814
else:
815815
_opts['as'] = opts[i]
816816
if i + 1 < len(opts):
817-
more_opts = opts[i + 1:]
817+
more_opts = opts[i + 1 :]
818818
_opts.update(dict(list(zip(more_opts[::2], more_opts[1::2]))))
819819
break
820820

@@ -835,7 +835,6 @@ def select(req: Plumbing.Request, *opts):
835835
entities = resolve_entities(args, lookup_fn=req.md.store.select, dedup=dedup)
836836

837837
if req.state.get('match', None): # TODO - allow this to be passed in via normal arguments
838-
839838
match = req.state['match']
840839

841840
if isinstance(match, six.string_types):
@@ -1304,14 +1303,15 @@ def xslt(req: Plumbing.Request, *opts):
13041303
if stylesheet is None:
13051304
raise PipeException("xslt requires stylesheet")
13061305

1307-
params = dict((k, "\'%s\'" % v) for (k, v) in list(req.args.items()))
1306+
params = dict((k, "'%s'" % v) for (k, v) in list(req.args.items()))
13081307
del params['stylesheet']
13091308
try:
13101309
return root(xslt_transform(req.t, stylesheet, params))
13111310
except Exception as ex:
13121311
log.debug(traceback.format_exc())
13131312
raise ex
13141313

1314+
13151315
@pipe
13161316
def indent(req: Plumbing.Request, *opts):
13171317
"""
@@ -1710,7 +1710,6 @@ def finalize(req: Plumbing.Request, *opts):
17101710
if name is None or 0 == len(name):
17111711
name = req.state.get('url', None)
17121712
if name and 'baseURL' in req.args:
1713-
17141713
try:
17151714
name_url = urlparse(name)
17161715
base_url = urlparse(req.args.get('baseURL'))

src/pyff/parse.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pyff.constants import NS
1111
from pyff.logs import get_log
12-
from pyff.resource import Resource,ResourceInfo
12+
from pyff.resource import Resource, ResourceInfo
1313
from pyff.utils import find_matching_files, parse_xml, root, unicode_stream, utc_now
1414

1515
__author__ = 'leifj'
@@ -30,8 +30,10 @@ def _format_key(k: str) -> str:
3030
res = {_format_key(k): v for k, v in self.dict().items()}
3131
return res
3232

33+
3334
ResourceInfo.model_rebuild()
3435

36+
3537
class ParserException(Exception):
3638
def __init__(self, msg, wrapped=None, data=None):
3739
self._wraped = wrapped
@@ -84,7 +86,7 @@ def parse(self, resource: Resource, content: str) -> ParserInfo:
8486
info = ParserInfo(description='Directory', expiration_time='never expires')
8587
n = 0
8688
for fn in find_matching_files(content, self.extensions):
87-
child_opts = resource.opts.copy(update={'alias': None})
89+
child_opts = resource.opts.model_copy(update={'alias': None})
8890
resource.add_child("file://" + urlescape(fn), child_opts)
8991
n += 1
9092

@@ -122,7 +124,7 @@ def parse(self, resource: Resource, content: str) -> ParserInfo:
122124
if len(fingerprints) > 0:
123125
fp = fingerprints[0]
124126
log.debug("XRD: {} verified by {}".format(link_href, fp))
125-
child_opts = resource.opts.copy(update={'alias': None})
127+
child_opts = resource.opts.model_copy(update={'alias': None})
126128
resource.add_child(link_href, child_opts)
127129
resource.last_seen = utc_now().replace(microsecond=0)
128130
resource.expire_time = None

src/pyff/samlmd.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ def find_merge_strategy(strategy_name):
8686

8787

8888
def parse_saml_metadata(
89-
source: BytesIO, opts: ResourceOpts, base_url=None, validation_errors: Optional[Dict[str, Any]] = None,
89+
source: BytesIO,
90+
opts: ResourceOpts,
91+
base_url=None,
92+
validation_errors: Optional[Dict[str, Any]] = None,
9093
):
9194
"""Parse a piece of XML and return an EntitiesDescriptor element after validation.
9295
@@ -192,7 +195,10 @@ def _extra_md(_t, info, **kwargs):
192195
location = kwargs.get('location')
193196
sp_entity = sp_entities.find("{%s}EntityDescriptor[@entityID='%s']" % (NS['md'], entityID))
194197
if sp_entity is not None:
195-
md_source = sp_entity.find("{%s}SPSSODescriptor/{%s}Extensions/{%s}TrustInfo/{%s}MetadataSource[@src='%s']" % (NS['md'], NS['md'], NS['ti'], NS['ti'], location))
198+
md_source = sp_entity.find(
199+
"{%s}SPSSODescriptor/{%s}Extensions/{%s}TrustInfo/{%s}MetadataSource[@src='%s']"
200+
% (NS['md'], NS['md'], NS['ti'], NS['ti'], location)
201+
)
196202
for e in iter_entities(_t):
197203
md_source.append(e)
198204
return etree.Element("{%s}EntitiesDescriptor" % NS['md'])
@@ -205,11 +211,14 @@ def _extra_md(_t, info, **kwargs):
205211
entityID = e.get('entityID')
206212
info.entities.append(entityID)
207213

208-
md_source = e.find("{%s}SPSSODescriptor/{%s}Extensions/{%s}TrustInfo/{%s}MetadataSource" % (NS['md'], NS['md'], NS['ti'], NS['ti']))
214+
md_source = e.find(
215+
"{%s}SPSSODescriptor/{%s}Extensions/{%s}TrustInfo/{%s}MetadataSource"
216+
% (NS['md'], NS['md'], NS['ti'], NS['ti'])
217+
)
209218
if md_source is not None:
210219
location = md_source.attrib.get('src')
211220
if location is not None:
212-
child_opts = resource.opts.copy(update={'alias': entityID})
221+
child_opts = resource.opts.model_copy(update={'alias': entityID})
213222
r = resource.add_child(location, child_opts)
214223
kwargs = {
215224
'entityID': entityID,
@@ -311,7 +320,7 @@ def parse(self, resource: Resource, content: str) -> EidasMDParserInfo:
311320
info.scheme_territory, location, fp, args.get('country_code')
312321
)
313322
)
314-
child_opts = resource.opts.copy(update={'alias': None})
323+
child_opts = resource.opts.model_copy(update={'alias': None})
315324
child_opts.verify = fp
316325
r = resource.add_child(location, child_opts)
317326

@@ -725,7 +734,6 @@ def entity_domains(entity):
725734

726735

727736
def entity_extended_display_i18n(entity, default_lang=None):
728-
729737
name_dict = lang_dict(entity.iter("{%s}OrganizationName" % NS['md']), lambda e: e.text, default_lang=default_lang)
730738
name_dict.update(
731739
lang_dict(entity.iter("{%s}OrganizationDisplayName" % NS['md']), lambda e: e.text, default_lang=default_lang)
@@ -981,7 +989,9 @@ def discojson_sp(e, global_trust_info=None, global_md_sources=None):
981989

982990
sp['entityID'] = e.get('entityID', None)
983991

984-
md_sources = e.findall("{%s}SPSSODescriptor/{%s}Extensions/{%s}TrustInfo/{%s}MetadataSource" % (NS['md'], NS['md'], NS['ti'], NS['ti']))
992+
md_sources = e.findall(
993+
"{%s}SPSSODescriptor/{%s}Extensions/{%s}TrustInfo/{%s}MetadataSource" % (NS['md'], NS['md'], NS['ti'], NS['ti'])
994+
)
985995

986996
sp['extra_md'] = {}
987997
for md_source in md_sources:
@@ -1041,7 +1051,6 @@ def discojson_sp(e, global_trust_info=None, global_md_sources=None):
10411051

10421052

10431053
def discojson_sp_attr(e):
1044-
10451054
attribute = "https://refeds.org/entity-selection-profile"
10461055
b64_trustinfos = entity_attribute(e, attribute)
10471056
if b64_trustinfos is None:
@@ -1395,7 +1404,7 @@ def get_key(e):
13951404
except AttributeError:
13961405
pass
13971406
except IndexError:
1398-
log.warning("Sort pipe: unable to sort entity by '%s'. " "Entity '%s' has no such value" % (sxp, eid))
1407+
log.warning("Sort pipe: unable to sort entity by '%s'. Entity '%s' has no such value" % (sxp, eid))
13991408
except TypeError:
14001409
pass
14011410

0 commit comments

Comments
 (0)