Commit b1d6fae6 authored by Jérome Perrin's avatar Jérome Perrin

patches/pylint: teach astroid about xmlsec modules

python xmlsec's xmlsec.so contains multiple level module in the same
.so (xmlsec, xmlsec.template etc) and this seem to cause problems to
astroid, trying to lint a module containing:

  import xmlsec
  xmlsec.template.encrypted_data_create('...')

cause an error:

   File "develop-eggs/astroid-1.3.8+slapospatched001-py2.7.egg/astroid/raw_building.py", line 360, in _set_proxied
      return _CONST_PROXY[const.value.__class__]
  KeyError: <type 'module'>

and unlike similar error happening with ffi's module from cryptography,
retrying does not help.
parent eff0c49e
Pipeline #24475 failed with stage
in 0 seconds
...@@ -381,6 +381,16 @@ _register_module_extender_from_live_module( ...@@ -381,6 +381,16 @@ _register_module_extender_from_live_module(
'cryptography.hazmat.bindings._openssl', 'cryptography.hazmat.bindings._openssl',
cryptography.hazmat.bindings._openssl) cryptography.hazmat.bindings._openssl)
try:
import xmlsec
except ImportError:
pass
else:
_register_module_extender_from_live_module('xmlsec', xmlsec)
_register_module_extender_from_live_module('xmlsec.tree', xmlsec.tree)
_register_module_extender_from_live_module('xmlsec.template', xmlsec.template)
# Properly search for namespace packages: original astroid (as of 1.3.8) only # Properly search for namespace packages: original astroid (as of 1.3.8) only
# checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in # checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in
# Products.ZSQLMethods; Shared and Shared.DC being a namespace package defined # Products.ZSQLMethods; Shared and Shared.DC being a namespace package defined
......
...@@ -2306,6 +2306,18 @@ rsa.generate_private_key( ...@@ -2306,6 +2306,18 @@ rsa.generate_private_key(
key_size=2048, key_size=2048,
).public_key() ).public_key()
def xmlsec_decrypt():
# from https://xmlsec.readthedocs.io/en/stable/examples.html#decrypt
import xmlsec
manager = xmlsec.KeysManager()
key = xmlsec.Key.from_file('rsakey.pem', xmlsec.constants.KeyDataFormatPem)
manager.add_key(key)
enc_ctx = xmlsec.EncryptionContext(manager)
root = lxml.etree.parse("enc1-res.xml").getroot()
enc_data = xmlsec.tree.find_child(root, "EncryptedData", xmlsec.constants.EncNs)
decrypted = enc_ctx.decrypt(enc_data)
print(lxml.etree.tostring(decrypted))
""" % (dict(namespace=namespace, """ % (dict(namespace=namespace,
reference1=imported_reference1, reference1=imported_reference1,
module2=imported_module2, module2=imported_module2,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment