ztfy/utils/security.py
changeset 0 712d20d2751e
child 2 20f3c0eb8fdf
equal deleted inserted replaced
-1:000000000000 0:712d20d2751e
       
     1 ##############################################################################
       
     2 #
       
     3 # Copyright (c) 2008 Thierry Florac <tflorac AT ulthar.net>
       
     4 # All Rights Reserved.
       
     5 #
       
     6 # This software is subject to the provisions of the Zope Public License,
       
     7 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    11 # FOR A PARTICULAR PURPOSE.
       
    12 #
       
    13 ##############################################################################
       
    14 """
       
    15 
       
    16 $Id: $
       
    17 """
       
    18 
       
    19 __version__   = "$Revision: $"
       
    20 __release__   = "$Id: $"
       
    21 __docformat__ = "restructuredtext"
       
    22  
       
    23 # import standard packages
       
    24 
       
    25 # import Zope3 interfaces
       
    26 
       
    27 # import local interfaces
       
    28 
       
    29 # import Zope3 packages
       
    30 from zope.security.proxy import removeSecurityProxy
       
    31 
       
    32 # import local packages
       
    33 
       
    34 
       
    35 def unproxied(value):
       
    36     """Remove security proxies from given value ; if value is a list or dict, all elements are unproxied"""
       
    37     if isinstance(value, list):
       
    38         result = []
       
    39         for v in value:
       
    40             result.append(removeSecurityProxy(v))
       
    41     elif isinstance(value, dict):
       
    42         result = value.copy()
       
    43         for v in value:
       
    44             result[v] = removeSecurityProxy(value[v])
       
    45     else:
       
    46         result = removeSecurityProxy(value)
       
    47     return result