Commit ee593f80 authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP

parent 9b74110a
...@@ -33,8 +33,6 @@ from copy import copy ...@@ -33,8 +33,6 @@ from copy import copy
import warnings import warnings
import types import types
import thread, threading import thread, threading
import os
from lib2to3.pgen2.parse import ParseError
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
...@@ -45,7 +43,6 @@ from AccessControl.SecurityManagement import getSecurityManager ...@@ -45,7 +43,6 @@ from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.ZopeGuards import guarded_getattr from AccessControl.ZopeGuards import guarded_getattr
from Acquisition import aq_base, aq_inner, aq_acquire, aq_chain from Acquisition import aq_base, aq_inner, aq_acquire, aq_chain
from DateTime import DateTime from DateTime import DateTime
from my2to3.trace import apply_fixers
import OFS.History import OFS.History
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
...@@ -866,27 +863,6 @@ class Base( ...@@ -866,27 +863,6 @@ class Base(
self.uid = uid # Else it will be generated when we need it self.uid = uid # Else it will be generated when we need it
self.sid = sid self.sid = sid
def __setstate__(self, state):
if os.environ.get("MY2TO3_ACTION") == "trace" and \
self.getPortalType() in [
"Document Component", "Extension Component", "Interface Component",
"Mixin Component", "Module Component", "Test Component",
"Tool Component",
]:
# See Products.ERP5Type.patches.my2to3_patch
# Apply "trace" fixers on the fly
# Note: The modifications are not saved (unless it is done explicitly,
# e.g. the user saves manually).
text_content = state.get('text_content')
if text_content:
try:
state['text_content'] = apply_fixers(text_content, state['id'])
except ParseError:
# text_content is not valid code
pass
super(Base, self).__setstate__(state)
# XXX This is necessary to override getId which is also defined in SimpleItem. # XXX This is necessary to override getId which is also defined in SimpleItem.
security.declareProtected( Permissions.AccessContentsInformation, 'getId' ) security.declareProtected( Permissions.AccessContentsInformation, 'getId' )
getId = BaseAccessor.Getter('getId', 'id', 'string') getId = BaseAccessor.Getter('getId', 'id', 'string')
...@@ -3640,6 +3616,31 @@ class Base( ...@@ -3640,6 +3616,31 @@ class Base(
id_generator_state[group].value = new_next_id id_generator_state[group].value = new_next_id
return range(next_id, new_next_id) return range(next_id, new_next_id)
from Products.ERP5Type import MY2TO3_ACTION
if MY2TO3_ACTION == 'trace':
def __setstate__(self, state):
if self.getPortalType() in (
"Document Component",
"Extension Component",
"Interface Component",
"Mixin Component",
"Module Component",
"Test Component",
"Tool Component"):
# See Products.ERP5Type.patches.my2to3_patch
# Apply "trace" fixers on the fly
# Note: The modifications are not saved (unless it is done explicitly,
# e.g. the user saves manually).
text_content = state.get('text_content')
if text_content:
try:
state['text_content'] = apply_fixers(text_content, state['id'])
except ParseError:
# text_content is not valid code
pass
super(Base, self).__setstate__(state)
Base.__setstate__ = __setstate__
InitializeClass(Base) InitializeClass(Base)
from Products.CMFCore.interfaces import IContentish from Products.CMFCore.interfaces import IContentish
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
############################################################################## ##############################################################################
from Products.ERP5Type import WITH_LEGACY_WORKFLOW from Products.ERP5Type import WITH_LEGACY_WORKFLOW, MY2TO3_ACTION
# Load all monkey patches # Load all monkey patches
from Products.ERP5Type.patches import my2to3_patch if MY2TO3_ACTION is not None:
from Products.ERP5Type.patches import my2to3_patch
from Products.ERP5Type.patches import WSGIPublisher from Products.ERP5Type.patches import WSGIPublisher
from Products.ERP5Type.patches import HTTPRequest from Products.ERP5Type.patches import HTTPRequest
from Products.ERP5Type.patches import AccessControl_patch from Products.ERP5Type.patches import AccessControl_patch
......
...@@ -32,6 +32,17 @@ ...@@ -32,6 +32,17 @@
""" """
from __future__ import absolute_import from __future__ import absolute_import
from App.config import getConfiguration from App.config import getConfiguration
# Conditionally apply patches/my2to3.py
try:
from my2to3.trace import apply_fixers
from lib2to3.pgen2.parse import ParseError
except ImportError:
MY2TO3_ACTION = None
else:
import os
MY2TO3_ACTION = os.environ.get("MY2TO3_ACTION")
from .patches import python, pylint, globalrequest from .patches import python, pylint, globalrequest
from zLOG import LOG, INFO from zLOG import LOG, INFO
DISPLAY_BOOT_PROCESS = False DISPLAY_BOOT_PROCESS = False
......
...@@ -42,7 +42,6 @@ from ZODB.broken import BrokenModified ...@@ -42,7 +42,6 @@ from ZODB.broken import BrokenModified
from zExceptions import Forbidden, NotFound from zExceptions import Forbidden, NotFound
from AccessControl.SecurityManagement import \ from AccessControl.SecurityManagement import \
getSecurityManager, setSecurityManager, noSecurityManager getSecurityManager, setSecurityManager, noSecurityManager
from Products.ERP5Type.dynamic.persistent_migration import Base__setstate__
from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules from Products.ERP5Type.dynamic.portal_type_class import synchronizeDynamicModules
from Products.ERP5Type.dynamic.lazy_class import ERP5BaseBroken, InitGhostBase from Products.ERP5Type.dynamic.lazy_class import ERP5BaseBroken, InitGhostBase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -78,7 +77,14 @@ class TestPortalTypeClass(ERP5TypeTestCase): ...@@ -78,7 +77,14 @@ class TestPortalTypeClass(ERP5TypeTestCase):
self.assertEqual(klass.__module__, self.assertEqual(klass.__module__,
migrated and 'erp5.portal_type' or 'erp5.component.document.erp5_version.Person') migrated and 'erp5.portal_type' or 'erp5.component.document.erp5_version.Person')
self.assertEqual(klass.__name__, 'Person') self.assertEqual(klass.__name__, 'Person')
self.assertEqual(klass.__setstate__.im_func is Base__setstate__.im_func, migrated)
from Products.ERP5Type import MY2TO3_ACTION
if MY2TO3_ACTION == 'trace':
from Products.ERP5Type.dynamic.persistent_migration import Base__setstate__
self.assertEqual(klass.__setstate__.im_func is Base__setstate__.im_func, migrated)
else:
from persistent import Persistent
self.assertEqual(klass.__setstate__ is Persistent.__setstate__, migrated)
# Import a .xml containing a Person created with the full module name # Import a .xml containing a Person created with the full module name
self.importObjectFromFile(person_module, 'non_migrated_person.xml') self.importObjectFromFile(person_module, 'non_migrated_person.xml')
......
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