Skip to content

Commit

Permalink
Merge pull request #18 from plone/python3
Browse files Browse the repository at this point in the history
More compatibility changes for Python 2 / 3
  • Loading branch information
davilima6 authored Feb 1, 2018
2 parents 3ce34f4 + 56dfe24 commit 3142950
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Breaking changes:

New features:

- *add item here*
- More Python 2 / 3 compatibility adjustments
[davilima6]

Bug fixes:

Expand All @@ -22,7 +23,8 @@ Bug fixes:

New features:

- Add Python 2 / 3 compatibility [davilima6]
- Prepare for Python 2 / 3 compatibility
[davilima6]


2.1.17 (2017-09-03)
Expand Down
4 changes: 2 additions & 2 deletions Products/contentmigration/catalogpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def applyCatalogPatch(portal):
LOG.info('Patching catalog_object and uncatalog_object of %s' %
catalog.absolute_url(1))
if hasattr(klass, '_atct_catalog_object'):
raise RuntimeError, "%s already has _atct_catalog_object" % catalog
raise RuntimeError("%s already has _atct_catalog_object" % catalog)
if hasattr(klass, '_atct_uncatalog_object'):
raise RuntimeError, "%s already has _atct_uncatalog_object" % catalog
raise RuntimeError("%s already has _atct_uncatalog_object" % catalog)

klass._atct_catalog_object = klass.catalog_object.im_func
klass.catalog_object = instancemethod(catalog_object, None, klass)
Expand Down
24 changes: 12 additions & 12 deletions Products/contentmigration/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _createObjectByType(type_name, container, id, *args, **kw):
typesTool = getToolByName(container, 'portal_types')
fti = typesTool.getTypeInfo(type_name)
if not fti:
raise ValueError, 'Invalid type %s' % type_name
raise ValueError('Invalid type %s' % type_name)

ob = fti._constructInstance(container, id, *args, **kw)

Expand Down Expand Up @@ -94,22 +94,22 @@ def unrestricted_rename(self, id, new_id):
even unallowed portal types inside a folder
"""
try: self._checkId(new_id)
except: raise CopyError, MessageDialog(
except: raise CopyError(MessageDialog(
title='Invalid Id',
message=sys.exc_info()[1],
action ='manage_main')
action ='manage_main'))
ob=self._getOb(id)
#!#if ob.wl_isLocked():
#!# raise ResourceLockedError, 'Object "%s" is locked via WebDAV' % ob.getId()
#!# raise(ResourceLockedError, 'Object "%s" is locked via WebDAV' % ob.getId())
if not ob.cb_isMoveable():
raise CopyError,'Not supported {}'.format(escape(id))
raise CopyError('Not supported {}'.format(escape(id)))
#!#self._verifyObjectPaste(ob)
#!#CopyContainer._verifyObjectPaste(self, ob)
try: ob._notifyOfCopyTo(self, op=1)
except: raise CopyError, MessageDialog(
except: raise(CopyError, MessageDialog(
title='Rename Error',
message=sys.exc_info()[1],
action ='manage_main')
action ='manage_main'))
self._delObject(id)
ob = aq_base(ob)
ob._setId(new_id)
Expand Down Expand Up @@ -180,18 +180,18 @@ def migratePortalType(portal, src_portal_type, dst_portal_type, out=None,
src = ttool.getTypeInfo(src_portal_type)
dst = ttool.getTypeInfo(dst_portal_type)
if src is None or dst is None:
raise ValueError, "Unknown src or dst portal type: %s -> %s" % (
src_portal_type, dst_portal_type,)
raise ValueError('Unknown src or dst portal type: %s -> %s' % (
src_portal_type, dst_portal_type,))

key = (src.Metatype(), dst.Metatype())
migratorFromRegistry = getMigrator(key)
if migratorFromRegistry is None:
raise ValueError, "No registered migrator for '%s' found" % str(key)
raise ValueError('No registered migrator for "%s" found' % str(key))

if migrator is not None:
# got a migrator, make sure it is the right one
if migrator is not migratorFromRegistry:
raise ValueError("ups")
raise ValueError('ups')
else:
migrator = migratorFromRegistry

Expand All @@ -206,7 +206,7 @@ def migratePortalType(portal, src_portal_type, dst_portal_type, out=None,
if kwargs.get('full_transaction', False):
msg+=', using full transactions'

print >> out, msg
print(msg, file=sys.stderr)
LOG.debug(msg)

walk = Walker(portal, migrator, src_portal_type=src_portal_type,
Expand Down
4 changes: 2 additions & 2 deletions Products/contentmigration/inplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def _checkLoadAttr(self, attr):
"""Check for an attribute on the migrator before loading and
raise an error if it's already there."""
if hasattr(self, attr):
raise ValueError, ('The migrator already has a value '
'for %s.' % attr)
raise(ValueError, ('The migrator already has a value '
'for %s.' % attr))

def beforeChange_properties(self):
"""Load up the migrator with property values."""
Expand Down

0 comments on commit 3142950

Please sign in to comment.