• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / RestrictedPython / 16550884845

20 Mar 2025 07:39AM UTC coverage: 98.772%. Remained the same
16550884845

push

github

icemac
Back to development: 8.1

213 of 231 branches covered (92.21%)

2493 of 2524 relevant lines covered (98.77%)

0.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/RestrictedPython/Limits.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE
11
#
12
##############################################################################
13

14
limited_builtins = {}
1✔
15

16

17
def limited_range(iFirst, *args):
1✔
18
    # limited range function from Martijn Pieters
19
    RANGELIMIT = 1000
1✔
20
    if not len(args):
1✔
21
        iStart, iEnd, iStep = 0, iFirst, 1
1✔
22
    elif len(args) == 1:
1✔
23
        iStart, iEnd, iStep = iFirst, args[0], 1
1✔
24
    elif len(args) == 2:
1✔
25
        iStart, iEnd, iStep = iFirst, args[0], args[1]
1✔
26
    else:
27
        raise AttributeError('range() requires 1-3 int arguments')
1✔
28
    if iStep == 0:
1✔
29
        raise ValueError('zero step for range()')
1✔
30
    iLen = int((iEnd - iStart) / iStep)
1✔
31
    if iLen < 0:
1✔
32
        iLen = 0
1✔
33
    if iLen >= RANGELIMIT:
1✔
34
        raise ValueError(
1✔
35
            'To be created range() object would be to large, '
36
            'in RestrictedPython we only allow {limit} '
37
            'elements in a range.'.format(limit=str(RANGELIMIT)),
38
        )
39
    return range(iStart, iEnd, iStep)
1✔
40

41

42
limited_builtins['range'] = limited_range
1✔
43

44

45
def limited_list(seq):
1✔
46
    if isinstance(seq, str):
1✔
47
        raise TypeError('cannot convert string to list')
1✔
48
    return list(seq)
1✔
49

50

51
limited_builtins['list'] = limited_list
1✔
52

53

54
def limited_tuple(seq):
1✔
55
    if isinstance(seq, str):
1✔
56
        raise TypeError('cannot convert string to tuple')
1✔
57
    return tuple(seq)
1✔
58

59

60
limited_builtins['tuple'] = limited_tuple
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc