17
17
from typing import Dict , Optional
18
18
19
19
import ipaddress
20
- import six
21
20
import xmlsec
22
21
from lxml import etree
23
22
from lxml .etree import DocumentInvalid
24
- from six . moves . urllib_parse import quote_plus , urlparse
23
+ from urllib . parse import quote_plus , urlparse
25
24
26
25
from pyff .constants import NS
27
26
from pyff .decorators import deprecated
@@ -104,7 +103,7 @@ def _map(req: Plumbing.Request, *opts):
104
103
105
104
def _p (e ):
106
105
entity_id = e .get ('entityID' )
107
- ip = Plumbing (pipeline = req .args , pid = "{ }.each[{}]". format ( req . plumbing . pid , entity_id ) )
106
+ ip = Plumbing (pipeline = req .args , pid = f" { req . plumbing . pid } .each[{ entity_id } ]" )
108
107
ireq = Plumbing .Request (ip , req .md , t = e , scheduler = req .scheduler )
109
108
ireq .set_id (entity_id )
110
109
ireq .set_parent (req )
@@ -114,7 +113,7 @@ def _p(e):
114
113
115
114
pool = ThreadPool ()
116
115
result = pool .map (_p , iter_entities (req .t ), chunksize = 10 )
117
- log .info ("processed {} entities" . format ( len (result )) )
116
+ log .info (f "processed { len (result )} entities" )
118
117
119
118
120
119
@pipe (name = "then" )
@@ -461,7 +460,7 @@ def sort(req: Plumbing.Request, *opts):
461
460
if req .t is None :
462
461
raise PipeException ("Unable to sort empty document." )
463
462
464
- _opts : Dict [str , Optional [str ]] = dict (list (zip (opts [0 :1 ], [" " .join (opts [1 :])])))
463
+ _opts : dict [str , Optional [str ]] = dict (list (zip (opts [0 :1 ], [" " .join (opts [1 :])])))
465
464
if 'order_by' not in _opts :
466
465
_opts ['order_by' ] = None
467
466
sort_entities (req .t , _opts ['order_by' ])
@@ -837,7 +836,7 @@ def select(req: Plumbing.Request, *opts):
837
836
if req .state .get ('match' , None ): # TODO - allow this to be passed in via normal arguments
838
837
match = req .state ['match' ]
839
838
840
- if isinstance (match , six . string_types ):
839
+ if isinstance (match , str ):
841
840
query = [match .lower ()]
842
841
843
842
def _strings (elt ):
@@ -870,22 +869,22 @@ def _match(q, elt):
870
869
871
870
if q is not None and len (q ) > 0 :
872
871
tokens = _strings (elt )
873
- p = re .compile (r '\b{}' . format ( q ) , re .IGNORECASE )
872
+ p = re .compile (fr '\b{ q } ' , re .IGNORECASE )
874
873
for tstr in tokens :
875
874
if p .search (tstr ):
876
875
return tstr
877
876
return None
878
877
879
- log .debug ("matching {} in {} entities" . format ( match , len (entities )) )
878
+ log .debug (f "matching { match } in { len (entities )} entities" )
880
879
entities = list (filter (lambda e : _match (match , e ) is not None , entities ))
881
- log .debug ("returning {} entities after match" . format ( len ( entities )) )
880
+ log .debug (f "returning { len ( entities ) } entities after match" )
882
881
883
882
ot = entitiesdescriptor (entities , name )
884
883
if ot is None :
885
884
raise PipeException ("empty select - stop" )
886
885
887
886
if req .plumbing .id != name :
888
- log .debug ("storing synthetic collection {}" . format ( name ) )
887
+ log .debug (f "storing synthetic collection { name } " )
889
888
req .store .update (ot , name )
890
889
891
890
return ot
@@ -1202,7 +1201,7 @@ def stats(req: Plumbing.Request, *opts):
1202
1201
raise PipeException ("Your pipeline is missing a select statement." )
1203
1202
1204
1203
print ("---" )
1205
- print ("total size: {:d}" . format ( req .store .size ()) )
1204
+ print (f "total size: { req .store .size ():d } " )
1206
1205
if not hasattr (req .t , 'xpath' ):
1207
1206
raise PipeException ("Unable to call stats on non-XML" )
1208
1207
@@ -1303,7 +1302,7 @@ def xslt(req: Plumbing.Request, *opts):
1303
1302
if stylesheet is None :
1304
1303
raise PipeException ("xslt requires stylesheet" )
1305
1304
1306
- params = dict (( k , "'%s'" % v ) for (k , v ) in list (req .args .items ()))
1305
+ params = { k : "'%s'" % v for (k , v ) in list (req .args .items ())}
1307
1306
del params ['stylesheet' ]
1308
1307
try :
1309
1308
return root (xslt_transform (req .t , stylesheet , params ))
@@ -1429,13 +1428,13 @@ def check_xml_namespaces(req: Plumbing.Request, *opts):
1429
1428
raise PipeException ("Your pipeline is missing a select statement." )
1430
1429
1431
1430
def _verify (elt ):
1432
- if isinstance (elt .tag , six . string_types ):
1431
+ if isinstance (elt .tag , str ):
1433
1432
for prefix , uri in list (elt .nsmap .items ()):
1434
1433
if not uri .startswith ('urn:' ):
1435
1434
u = urlparse (uri )
1436
1435
if u .scheme not in ('http' , 'https' ):
1437
1436
raise MetadataException (
1438
- "Namespace URIs must be be http(s) URIs ('{}' declared on {})" . format ( uri , elt .tag )
1437
+ f "Namespace URIs must be be http(s) URIs ('{ uri } ' declared on { elt .tag } )"
1439
1438
)
1440
1439
1441
1440
with_tree (root (req .t ), _verify )
@@ -1508,7 +1507,7 @@ def certreport(req: Plumbing.Request, *opts):
1508
1507
error_bits = int (req .args .get ('error_bits' , "1024" ))
1509
1508
warning_bits = int (req .args .get ('warning_bits' , "2048" ))
1510
1509
1511
- seen : Dict [str , bool ] = {}
1510
+ seen : dict [str , bool ] = {}
1512
1511
for eid in req .t .xpath ("//md:EntityDescriptor/@entityID" , namespaces = NS , smart_strings = False ):
1513
1512
for cd in req .t .xpath (
1514
1513
"md:EntityDescriptor[@entityID='%s']//ds:X509Certificate" % eid , namespaces = NS , smart_strings = False
@@ -1530,17 +1529,17 @@ def certreport(req: Plumbing.Request, *opts):
1530
1529
entity_elt ,
1531
1530
"certificate-error" ,
1532
1531
"keysize too small" ,
1533
- "%s has keysize of %s bits (less than %s)" % (cert .getSubject (), keysize , error_bits ),
1532
+ "{} has keysize of {} bits (less than {})" . format (cert .getSubject (), keysize , error_bits ),
1534
1533
)
1535
- log .error ("%s has keysize of %s" % (eid , keysize ))
1534
+ log .error ("{} has keysize of {}" . format (eid , keysize ))
1536
1535
elif keysize < warning_bits :
1537
1536
annotate_entity (
1538
1537
entity_elt ,
1539
1538
"certificate-warning" ,
1540
1539
"keysize small" ,
1541
- "%s has keysize of %s bits (less than %s)" % (cert .getSubject (), keysize , warning_bits ),
1540
+ "{} has keysize of {} bits (less than {})" . format (cert .getSubject (), keysize , warning_bits ),
1542
1541
)
1543
- log .warning ("%s has keysize of %s" % (eid , keysize ))
1542
+ log .warning ("{} has keysize of {}" . format (eid , keysize ))
1544
1543
1545
1544
notafter = cert .getNotAfter ()
1546
1545
if notafter is None :
@@ -1560,23 +1559,23 @@ def certreport(req: Plumbing.Request, *opts):
1560
1559
entity_elt ,
1561
1560
"certificate-error" ,
1562
1561
"certificate has expired" ,
1563
- "%s expired %s ago" % (cert .getSubject (), - dt ),
1562
+ "{} expired {} ago" . format (cert .getSubject (), - dt ),
1564
1563
)
1565
- log .error ("%s expired %s ago" % (eid , - dt ))
1564
+ log .error ("{} expired {} ago" . format (eid , - dt ))
1566
1565
elif total_seconds (dt ) < warning_seconds :
1567
1566
annotate_entity (
1568
1567
entity_elt ,
1569
1568
"certificate-warning" ,
1570
1569
"certificate about to expire" ,
1571
- "%s expires in %s" % (cert .getSubject (), dt ),
1570
+ "{} expires in {}" . format (cert .getSubject (), dt ),
1572
1571
)
1573
- log .warning ("%s expires in %s" % (eid , dt ))
1572
+ log .warning ("{} expires in {}" . format (eid , dt ))
1574
1573
except ValueError as ex :
1575
1574
annotate_entity (
1576
1575
entity_elt ,
1577
1576
"certificate-error" ,
1578
1577
"certificate has unknown expiration time" ,
1579
- "%s unknown expiration time %s" % (cert .getSubject (), notafter ),
1578
+ "{} unknown expiration time {}" . format (cert .getSubject (), notafter ),
1580
1579
)
1581
1580
1582
1581
req .store .update (entity_elt )
@@ -1623,7 +1622,7 @@ def emit(req: Plumbing.Request, ctype="application/xml", *opts):
1623
1622
1624
1623
if d is not None :
1625
1624
m = hashlib .sha1 ()
1626
- if not isinstance (d , six . binary_type ):
1625
+ if not isinstance (d , bytes ):
1627
1626
d = d .encode ("utf-8" )
1628
1627
m .update (d )
1629
1628
req .state ['headers' ]['ETag' ] = m .hexdigest ()
@@ -1632,7 +1631,7 @@ def emit(req: Plumbing.Request, ctype="application/xml", *opts):
1632
1631
1633
1632
req .state ['headers' ]['Content-Type' ] = ctype
1634
1633
if six .PY2 :
1635
- d = six . u ( d )
1634
+ d = d
1636
1635
return d
1637
1636
1638
1637
@@ -1664,7 +1663,7 @@ def signcerts(req: Plumbing.Request, *opts):
1664
1663
1665
1664
@pipe
1666
1665
def finalize (req : Plumbing .Request , * opts ):
1667
- """
1666
+ r """
1668
1667
Prepares the working document for publication/rendering.
1669
1668
1670
1669
:param req: The request
@@ -1716,7 +1715,7 @@ def finalize(req: Plumbing.Request, *opts):
1716
1715
# TODO: Investigate this error, which is probably correct:
1717
1716
# error: On Python 3 '{}'.format(b'abc') produces "b'abc'", not 'abc';
1718
1717
# use '{!r}'.format(b'abc') if this is desired behavior
1719
- name = "{ }://{}{}" . format ( base_url .scheme , base_url . netloc , name_url .path ) # type: ignore
1718
+ name = f" { base_url . scheme } ://{ base_url .netloc } { name_url .path } " # type: ignore
1720
1719
log .debug ("-------- using Name: %s" % name )
1721
1720
except ValueError as ex :
1722
1721
log .debug (f'Got an exception while finalizing: { ex } ' )
@@ -1752,7 +1751,7 @@ def finalize(req: Plumbing.Request, *opts):
1752
1751
offset = dt - now
1753
1752
e .set ('validUntil' , datetime2iso (dt ))
1754
1753
except ValueError as ex :
1755
- log .error ("Unable to parse validUntil: %s (%s)" % (valid_until , ex ))
1754
+ log .error ("Unable to parse validUntil: {} ({})" . format (valid_until , ex ))
1756
1755
1757
1756
# set a reasonable default: 50% of the validity
1758
1757
# we replace this below if we have cacheDuration set
0 commit comments