Commit 7aa6dd2b authored by Jérome Perrin's avatar Jérome Perrin

Fix astroid KeyError _CONST_PROXY

See merge request nexedi/erp5!1683
parents 5bfb680a b1d6fae6
...@@ -81,16 +81,8 @@ def checkComponent(component_instance): ...@@ -81,16 +81,8 @@ def checkComponent(component_instance):
code = component_instance.getTextContent() code = component_instance.getTextContent()
if six.PY2: if six.PY2:
code = unicode(code, 'utf8') code = unicode(code, 'utf8')
data = {'code': code} for annotation in json.loads(portal.ERP5Site_checkPythonSourceCodeAsJSON(
try: {'code': code}))['annotations']:
check_result_json = portal.ERP5Site_checkPythonSourceCodeAsJSON(data)
except Exception:
# pylint sometimes raises on the first attempt at importing modules, but
# may succeed on the second try (probably because of incomplete cleanup
# of partially imported moduled). We are not interested in pylint issues,
# we are interested in our code's issues, so give it one more try.
check_result_json = portal.ERP5Site_checkPythonSourceCodeAsJSON(data)
for annotation in json.loads(check_result_json)['annotations']:
annotation['component_path'] = component_relative_url annotation['component_path'] = component_relative_url
line_list.append( line_list.append(
Message( Message(
......
...@@ -372,6 +372,25 @@ else: ...@@ -372,6 +372,25 @@ else:
return m return m
MANAGER.register_transform(Module, wendelin_transform, lambda node: node.name == 'wendelin') MANAGER.register_transform(Module, wendelin_transform, lambda node: node.name == 'wendelin')
# prevent a crash with cryptography:
# 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 'CompiledFFI'>
import cryptography.hazmat.bindings._openssl
_register_module_extender_from_live_module(
'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
......
...@@ -2285,12 +2285,39 @@ class FooBar(ValidationFailed): ...@@ -2285,12 +2285,39 @@ class FooBar(ValidationFailed):
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
super(FooBar, self).__init__(*args, **kw) super(FooBar, self).__init__(*args, **kw)
# Test for various pylint fixes
# Transforms for Zope which should ideally be upstream'ed # Transforms for Zope which should ideally be upstream'ed
from AccessControl.PermissionRole import rolesForPermissionOn, PermissionRole, imPermissionRole, _what_not_even_god_should_do # pylint: disable=unused-import from AccessControl.PermissionRole import rolesForPermissionOn, PermissionRole, imPermissionRole, _what_not_even_god_should_do # pylint: disable=unused-import
# Monkey patch of astroid 1.3.8: it raised 'no-name-in-module' because # Monkey patch of astroid 1.3.8: it raised 'no-name-in-module' because
# Shared.DC was not considered a namespace package # Shared.DC was not considered a namespace package
from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import from Shared.DC.ZRDB.Results import Results # pylint: disable=unused-import
import lxml.etree
lxml.etree.Element('test')
from BTrees.OOBTree import OOBTree
OOBTree()
from cryptography.hazmat.primitives.asymmetric import rsa
rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
).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