Exemplo n.º 1
0
 def test_kvi_iteration(self):
     from AccessControl.ZopeGuards import SafeIter
     d = dict(a=1, b=2)
     for attr in ("keys", "values", "items"):
         v = getattr(d, attr)()
         si = SafeIter(v)
         self.assertEqual(next(si), next(iter(v)))
Exemplo n.º 2
0
    def test_guarded_next__3(self):
        """It does not double check if using a `SafeIter`."""
        from AccessControl.ZopeGuards import SafeIter

        SCRIPT = "next(iter([2411, 123]))"

        code, its_globals = self._compile_str(SCRIPT, 'ignored')
        its_globals['iterator'] = SafeIter([2411, 123])

        sm = SecurityManager()
        old = self.setSecurityManager(sm)
        try:
            exec(code, its_globals)
        finally:
            self.setSecurityManager(old)
        self.assertEqual(
            [('validate', ([2411, 123], [2411, 123], None, 2411))], sm.calls)
Exemplo n.º 3
0
def guarded_reversed(seq):
    return SafeIter(reversed(seq))
Exemplo n.º 4
0
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################
"""
Restricted six module.

From restricted python, use "import six" (see patches/Restricted.py).
"""
import six as _six

PY2 = _six.PY2
PY3 = _six.PY3
moves = _six.moves
text_type = _six.text_type
binary_type = _six.binary_type
string_types = _six.string_types
integer_types = _six.integer_types

# ContainerAssertions cannot be used here (like for dict) because the following
# functions are defined on `six` module directly and ContainerAssertions has a
# type() as key
from Products.ERP5Type.patches.Restricted import SafeIterItems
iteritems = lambda d: SafeIterItems(_six.iteritems(d), d)
from AccessControl.ZopeGuards import SafeIter
iterkeys = lambda d: SafeIter(_six.iterkeys(d), d)
itervalues = lambda d: SafeIter(_six.itervalues(d), d)

from AccessControl.ZopeGuards import safe_builtins as _safe_builtins
_safe_builtins['xrange'] = _six.moves.xrange