Skip to content

Commit 1bf9577

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c671270 commit 1bf9577

File tree

14 files changed

+211
-233
lines changed

14 files changed

+211
-233
lines changed

doc/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
autodoc_docstring_signature = True
6464

6565

66-
rst_prolog = '''
66+
rst_prolog = """
6767
.. role:: xml(code)
6868
:language: xml
69-
'''
69+
"""
7070

7171
# LXML crossref'ing stuff:
7272
# LXML doesn't have an intersphinx docs,

doc/source/examples/decrypt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
key = xmlsec.Key.from_file('rsakey.pem', xmlsec.constants.KeyDataFormatPem)
77
manager.add_key(key)
88
enc_ctx = xmlsec.EncryptionContext(manager)
9-
root = etree.parse("enc1-res.xml").getroot()
10-
enc_data = xmlsec.tree.find_child(root, "EncryptedData", xmlsec.constants.EncNs)
9+
root = etree.parse('enc1-res.xml').getroot()
10+
enc_data = xmlsec.tree.find_child(root, 'EncryptedData', xmlsec.constants.EncNs)
1111
decrypted = enc_ctx.decrypt(enc_data)
1212
print(etree.tostring(decrypted))

doc/source/examples/encrypt.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
template,
1010
xmlsec.constants.TransformAes128Cbc,
1111
type=xmlsec.constants.TypeEncElement,
12-
ns="xenc",
12+
ns='xenc',
1313
)
1414

1515
xmlsec.template.encrypted_data_ensure_cipher_value(enc_data)
16-
key_info = xmlsec.template.encrypted_data_ensure_key_info(enc_data, ns="dsig")
16+
key_info = xmlsec.template.encrypted_data_ensure_key_info(enc_data, ns='dsig')
1717
enc_key = xmlsec.template.add_encrypted_key(key_info, xmlsec.constants.TransformRsaOaep)
1818
xmlsec.template.encrypted_data_ensure_cipher_value(enc_key)
1919
data = template.find('./Data')
@@ -24,20 +24,10 @@
2424
manager.add_key(key)
2525

2626
enc_ctx = xmlsec.EncryptionContext(manager)
27-
enc_ctx.key = xmlsec.Key.generate(
28-
xmlsec.constants.KeyDataAes, 128, xmlsec.constants.KeyDataTypeSession
29-
)
27+
enc_ctx.key = xmlsec.Key.generate(xmlsec.constants.KeyDataAes, 128, xmlsec.constants.KeyDataTypeSession)
3028
enc_data = enc_ctx.encrypt_xml(enc_data, data)
31-
enc_method = xmlsec.tree.find_child(
32-
enc_data, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs
33-
)
34-
key_info = xmlsec.tree.find_child(
35-
enc_data, xmlsec.constants.NodeKeyInfo, xmlsec.constants.DSigNs
36-
)
37-
enc_method = xmlsec.tree.find_node(
38-
key_info, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs
39-
)
40-
cipher_value = xmlsec.tree.find_node(
41-
key_info, xmlsec.constants.NodeCipherValue, xmlsec.constants.EncNs
42-
)
29+
enc_method = xmlsec.tree.find_child(enc_data, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs)
30+
key_info = xmlsec.tree.find_child(enc_data, xmlsec.constants.NodeKeyInfo, xmlsec.constants.DSigNs)
31+
enc_method = xmlsec.tree.find_node(key_info, xmlsec.constants.NodeEncryptionMethod, xmlsec.constants.EncNs)
32+
cipher_value = xmlsec.tree.find_node(key_info, xmlsec.constants.NodeCipherValue, xmlsec.constants.EncNs)
4333
print(etree.tostring(cipher_value))

doc/source/examples/verify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
with open('sign1-res.xml') as fp:
66
template = etree.parse(fp).getroot()
77

8-
xmlsec.tree.add_ids(template, ["ID"])
8+
xmlsec.tree.add_ids(template, ['ID'])
99
signature_node = xmlsec.tree.find_node(template, xmlsec.constants.NodeSignature)
1010
# Create a digital signature context (no key manager is needed).
1111
ctx = xmlsec.SignatureContext()

setup.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def handle_starttag(self, tag, attrs):
3535
def make_request(url, github_token=None, json_response=False):
3636
headers = {'User-Agent': 'https://github.com/xmlsec/python-xmlsec'}
3737
if github_token:
38-
headers['authorization'] = "Bearer " + github_token
38+
headers['authorization'] = 'Bearer ' + github_token
3939
request = Request(url, headers=headers)
4040
with contextlib.closing(urlopen(request)) as r:
4141
charset = r.headers.get_content_charset() or 'utf-8'
@@ -74,9 +74,9 @@ def latest_release_json_from_github_api(repo):
7474
api_url = f'https://api.github.com/repos/{repo}/releases/latest'
7575

7676
# if we are running in CI, pass along the GH_TOKEN, so we don't get rate limited
77-
token = os.environ.get("GH_TOKEN")
77+
token = os.environ.get('GH_TOKEN')
7878
if token:
79-
log.info("Using GitHub token to avoid rate limiting")
79+
log.info('Using GitHub token to avoid rate limiting')
8080
return make_request(api_url, token, json_response=True)
8181

8282

@@ -114,7 +114,7 @@ def __init__(self, host, arch, compiler):
114114

115115
@property
116116
def triplet(self):
117-
return f"{self.host}-{self.arch}-{self.compiler}"
117+
return f'{self.host}-{self.arch}-{self.compiler}'
118118

119119

120120
class build_ext(build_ext_orig):
@@ -309,9 +309,7 @@ def prepare_static_build(self, build_platform):
309309
self.info('{:10}: {}'.format('zlib', f'PYXMLSEC_ZLIB_VERSION unset, downloading latest from {url}'))
310310
else:
311311
url = f'https://zlib.net/fossils/zlib-{self.zlib_version}.tar.gz'
312-
self.info(
313-
'{:10}: {}'.format('zlib', f'PYXMLSEC_ZLIB_VERSION={self.zlib_version}, downloading from {url}')
314-
)
312+
self.info('{:10}: {}'.format('zlib', f'PYXMLSEC_ZLIB_VERSION={self.zlib_version}, downloading from {url}'))
315313
urlretrieve(url, str(zlib_tar))
316314

317315
# fetch libiconv
@@ -325,9 +323,7 @@ def prepare_static_build(self, build_platform):
325323
else:
326324
url = f'https://ftp.gnu.org/pub/gnu/libiconv/libiconv-{self.libiconv_version}.tar.gz'
327325
self.info(
328-
'{:10}: {}'.format(
329-
'zlib', f'PYXMLSEC_LIBICONV_VERSION={self.libiconv_version}, downloading from {url}'
330-
)
326+
'{:10}: {}'.format('zlib', f'PYXMLSEC_LIBICONV_VERSION={self.libiconv_version}, downloading from {url}')
331327
)
332328
urlretrieve(url, str(libiconv_tar))
333329

@@ -342,9 +338,7 @@ def prepare_static_build(self, build_platform):
342338
version_prefix, _ = self.libxml2_version.rsplit('.', 1)
343339
url = f'https://download.gnome.org/sources/libxml2/{version_prefix}/libxml2-{self.libxml2_version}.tar.xz'
344340
self.info(
345-
'{:10}: {}'.format(
346-
'libxml2', f'PYXMLSEC_LIBXML2_VERSION={self.libxml2_version}, downloading from {url}'
347-
)
341+
'{:10}: {}'.format('libxml2', f'PYXMLSEC_LIBXML2_VERSION={self.libxml2_version}, downloading from {url}')
348342
)
349343
libxml2_tar = self.libs_dir / 'libxml2.tar.xz'
350344
urlretrieve(url, str(libxml2_tar))
@@ -360,9 +354,7 @@ def prepare_static_build(self, build_platform):
360354
version_prefix, _ = self.libxslt_version.rsplit('.', 1)
361355
url = f'https://download.gnome.org/sources/libxslt/{version_prefix}/libxslt-{self.libxslt_version}.tar.xz'
362356
self.info(
363-
'{:10}: {}'.format(
364-
'libxslt', f'PYXMLSEC_LIBXSLT_VERSION={self.libxslt_version}, downloading from {url}'
365-
)
357+
'{:10}: {}'.format('libxslt', f'PYXMLSEC_LIBXSLT_VERSION={self.libxslt_version}, downloading from {url}')
366358
)
367359
libxslt_tar = self.libs_dir / 'libxslt.tar.gz'
368360
urlretrieve(url, str(libxslt_tar))
@@ -377,9 +369,7 @@ def prepare_static_build(self, build_platform):
377369
else:
378370
url = f'https://github.com/lsh123/xmlsec/releases/download/{self.xmlsec1_version}/xmlsec1-{self.xmlsec1_version}.tar.gz'
379371
self.info(
380-
'{:10}: {}'.format(
381-
'xmlsec1', f'PYXMLSEC_XMLSEC1_VERSION={self.xmlsec1_version}, downloading from {url}'
382-
)
372+
'{:10}: {}'.format('xmlsec1', f'PYXMLSEC_XMLSEC1_VERSION={self.xmlsec1_version}, downloading from {url}')
383373
)
384374
xmlsec1_tar = self.libs_dir / 'xmlsec1.tar.gz'
385375
urlretrieve(url, str(xmlsec1_tar))
@@ -415,7 +405,7 @@ def prepare_static_build(self, build_platform):
415405
cross_compiling = CrossCompileInfo('darwin64', arch, 'cc')
416406
major_version, _ = tuple(map(int, platform.mac_ver()[0].split('.')[:2]))
417407
if major_version >= 11 and 'MACOSX_DEPLOYMENT_TARGET' not in env:
418-
env['MACOSX_DEPLOYMENT_TARGET'] = "11.0"
408+
env['MACOSX_DEPLOYMENT_TARGET'] = '11.0'
419409

420410
env['CFLAGS'] = ' '.join(cflags)
421411
env['LDFLAGS'] = ' '.join(ldflags)
@@ -430,9 +420,7 @@ def prepare_static_build(self, build_platform):
430420
openssl_config_cmd.insert(0, './config')
431421
subprocess.check_call(openssl_config_cmd, cwd=str(openssl_dir), env=env)
432422
subprocess.check_call(['make', f'-j{multiprocessing.cpu_count() + 1}'], cwd=str(openssl_dir), env=env)
433-
subprocess.check_call(
434-
['make', f'-j{multiprocessing.cpu_count() + 1}', 'install_sw'], cwd=str(openssl_dir), env=env
435-
)
423+
subprocess.check_call(['make', f'-j{multiprocessing.cpu_count() + 1}', 'install_sw'], cwd=str(openssl_dir), env=env)
436424

437425
self.info('Building zlib')
438426
zlib_dir = next(self.build_libs_dir.glob('zlib-*'))
@@ -594,7 +582,7 @@ def prepare_static_build(self, build_platform):
594582
python_requires='>=3.9',
595583
setup_requires=setup_reqs,
596584
install_requires=['lxml>=3.8'],
597-
author="Bulat Gaifullin",
585+
author='Bulat Gaifullin',
598586
author_email='[email protected]',
599587
maintainer='Oleg Hoefling',
600588
maintainer_email='[email protected]',

tests/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class TestMemoryLeaks(unittest.TestCase):
2525

2626
iterations = test_iterations
2727

28-
data_dir = os.path.join(os.path.dirname(__file__), "data")
28+
data_dir = os.path.join(os.path.dirname(__file__), 'data')
2929

3030
def setUp(self):
3131
gc.disable()
32-
self.addTypeEqualityFunc(etype, "assertXmlEqual")
32+
self.addTypeEqualityFunc(etype, 'assertXmlEqual')
3333
xmlsec.enable_debug_trace(1)
3434

3535
def run(self, result=None):
@@ -58,13 +58,13 @@ def run(self, result=None):
5858
if m_hits > int(self.iterations * 0.8):
5959
result.buffer = False
6060
try:
61-
raise AssertionError("memory leak detected")
61+
raise AssertionError('memory leak detected')
6262
except AssertionError:
6363
result.addError(self, sys.exc_info())
6464
if o_hits > int(self.iterations * 0.8):
6565
result.buffer = False
6666
try:
67-
raise AssertionError("unreferenced objects detected")
67+
raise AssertionError('unreferenced objects detected')
6868
except AssertionError:
6969
result.addError(self, sys.exc_info())
7070

@@ -74,7 +74,7 @@ def path(self, name):
7474

7575
def load(self, name):
7676
"""Load resource by name."""
77-
with open(self.path(name), "rb") as stream:
77+
with open(self.path(name), 'rb') as stream:
7878
return stream.read()
7979

8080
def load_xml(self, name, xpath=None):

tests/softhsm_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def setup() -> None:
223223
'[pkcs11_section]',
224224
'engine_id = pkcs11',
225225
# dynamic_path,
226-
"MODULE_PATH = {}".format(component_path['P11_MODULE']),
226+
'MODULE_PATH = {}'.format(component_path['P11_MODULE']),
227227
'init = 0',
228228
]
229229
)

0 commit comments

Comments
 (0)