[Zope] Python Script limit in range()
Peter Bengtsson
peter@grenna.net
Wed, 14 Mar 2001 12:43:55 -0000
A simple Script (Python) of mine:
Id: randomtext_pys
Title: Returns a random text
<params>length=500</params>
[code]
import string
import random
text=''
pool = "qwertyuioplkjhgfdsazxcvbnm 1234567890 \n"
for i in range(int(length)):
text='%s%s'%(text,pool[random.randint(0,(len(pool)-1))])
return text
[/code]
When I test this script within the management interface of Python Scripts
everything looks good and I can enter values of "length" like 100 to 10 000.
However, when I call this script from a DTML Method like this:
<dtml-var "randomtext_pys(1000)"> it throws an error at me.
<dtml-var "randomgtext_pys(500)"> and <dtml-var "randomgtext_pys(999)">
works fine.
Error Type: ValueError
Error Value: range() too large
(traceback below)
So according to the traceback the error you find this:
----------- lib/python/DocumentTemplate/DT_Util.py ------------
def careful_range(md, iFirst, *args):
# limited range function from Martijn Pieters
RANGELIMIT = 1000
if not len(args):
iStart, iEnd, iStep = 0, iFirst, 1
elif len(args) == 1:
iStart, iEnd, iStep = iFirst, args[0], 1
elif len(args) == 2:
iStart, iEnd, iStep = iFirst, args[0], args[1]
else:
raise AttributeError, 'range() requires 1-3 int arguments'
if iStep == 0: raise ValueError, 'zero step for range()'
iLen = int((iEnd - iStart) / iStep)
if iLen < 0: iLen = 0
if iLen >= RANGELIMIT: raise ValueError, 'range() too large'
return range(iStart, iEnd, iStep)
-------------------------------------------------------------------
WHY is that LIMIT there?
I can mod my Python Script to accomodate for the value of 1000, but I am
just curious of it.
Best Regards, Peter
Traceback (innermost last):
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/ZPublisher/Publish.py, line
222, in publish_module
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/ZPublisher/Publish.py, line
187, in publish
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/Zope/__init__.py, line 221,
in zpublisher_exception_hook
(Object: Traversable)
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/ZPublisher/Publish.py, line
171, in publish
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/ZPublisher/mapply.py, line
160, in mapply
(Object: showlong)
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/ZPublisher/Publish.py, line
112, in call_object
(Object: showlong)
File /dsk/1/Zope-src/Zope-2.3.0-src/lib/python/OFS/DTMLMethod.py, line
189, in __call__
(Object: showlong)
File
/dsk/1/Zope-src/Zope-2.3.0-src/lib/python/DocumentTemplate/DT_String.py,
line 538, in __call__
(Object: showlong)
File
/dsk/1/Zope-src/Zope-2.3.0-src/lib/python/DocumentTemplate/DT_Util.py, line
334, in eval
(Object: randomtext_pys(l))
(Info: l)
File <string>, line 0, in ?
File
/dsk/1/Zope-src/Zope-2.3.0-src/lib/python/Shared/DC/Scripts/Bindings.py,
line 324, in __call__
(Object: randomtext_pys)
File
/dsk/1/Zope-src/Zope-2.3.0-src/lib/python/Shared/DC/Scripts/Bindings.py,
line 353, in _bindAndExec
(Object: randomtext_pys)
File
/dsk/1/Zope-src/Zope-2.3.0-src/lib/python/Products/PythonScripts/PythonScrip
t.py, line 330, in _exec
(Object: randomtext_pys)
(Info: ({'script': <PythonScript instance at 894fa08>, 'context':
<Folder instance at 87e20c8>, 'container': <Folder instance at 87e20c8>,
'traverse_subpath': []}, ('1001',), {}, (500,)))
File Script (Python), line 8, in randomtext
File
/dsk/1/Zope-src/Zope-2.3.0-src/lib/python/DocumentTemplate/DT_Util.py, line
201, in careful_range
ValueError: (see above)