Skip to content

Commit

Permalink
Simplify pickling logic by using __reduce__ instead of copy_reg
Browse files Browse the repository at this point in the history
The pickles produced this way are identical to the old ones.
  • Loading branch information
mgedmin authored and tseaver committed May 5, 2017
1 parent 8c1b95c commit 8442dcd
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/zope/securitypolicy/settings.py
Expand Up @@ -49,23 +49,16 @@ def getDescription(self):
def getName(self):
return self.__name

def __reduce__(self):
# register PermissionSettings to be symbolic constants by identity,
# even when pickled and unpickled.
return self.__name

def __str__(self):
return "PermissionSetting: %s" % self.__name

__repr__ = __str__

# register PermissionSettings to be symbolic constants by identity,
# even when pickled and unpickled.
try:
import copy_reg as copyreg
except ImportError:
# Py3: Location change.
import copyreg
copyreg.constructor(PermissionSetting)
copyreg.pickle(PermissionSetting,
PermissionSetting.getName,
PermissionSetting)


Allow = PermissionSetting(
'Allow', 'Explicit allow setting for permissions')
Expand Down

0 comments on commit 8442dcd

Please sign in to comment.