Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testMaxFrameSize(self):
_maxSize = constants.MAX_FRAME_SIZE
try:
maxSize = constants.MAX_FRAME_SIZE = 500
# Within range
utils.xfrange(1, 100, 1, maxSize=-1)
utils.xfrange(1, 100, 1, maxSize=100)
FrameSet('1-%d' % maxSize)
# Should not be allowed
self.assertRaises(exceptions.MaxSizeException, utils.xfrange, 1, 100, 1, maxSize=50)
self.assertRaises(exceptions.MaxSizeException, FrameSet, '1-%d' % (maxSize + 1))
# Inverting would produce a huge new range
fs = FrameSet('1,%d' % (maxSize + 3))
self.assertRaises(exceptions.MaxSizeException, fs.invertedFrameRange)
finally:
constants.MAX_FRAME_SIZE = _maxSize
def testMaxFrameSize(self):
_maxSize = constants.MAX_FRAME_SIZE
try:
maxSize = constants.MAX_FRAME_SIZE = 500
# Within range
utils.xfrange(1, 100, 1, maxSize=-1)
utils.xfrange(1, 100, 1, maxSize=100)
FrameSet('1-%d' % maxSize)
# Should not be allowed
self.assertRaises(exceptions.MaxSizeException, utils.xfrange, 1, 100, 1, maxSize=50)
self.assertRaises(exceptions.MaxSizeException, FrameSet, '1-%d' % (maxSize + 1))
# Inverting would produce a huge new range
fs = FrameSet('1,%d' % (maxSize + 3))
self.assertRaises(exceptions.MaxSizeException, fs.invertedFrameRange)
finally:
constants.MAX_FRAME_SIZE = _maxSize
Returns:
generator:
Raises:
:class:`fileseq.exceptions.MaxSizeException`: if size is exceeded
"""
if start <= stop:
stop, step = stop + 1, abs(step)
else:
stop, step = stop - 1, -abs(step)
if maxSize >= 0:
size = lenRange(start, stop, step)
if size > maxSize:
raise exceptions.MaxSizeException(
"Size %d > %s (MAX_FRAME_SIZE)" % (size, maxSize))
# because an xrange is an odd object all its own, we wrap it in a
# generator expression to get a proper Generator
return (f for f in range(start, stop, step))
:class:`fileseq.exceptions.MaxSizeException`:
"""
fail = False
size = 0
if isinstance(obj, numbers.Number):
if obj > constants.MAX_FRAME_SIZE:
fail = True
size = obj
elif hasattr(obj, '__len__'):
size = len(obj)
fail = size > constants.MAX_FRAME_SIZE
if fail:
raise MaxSizeException('Frame size %s > %s (MAX_FRAME_SIZE)'
% (size, constants.MAX_FRAME_SIZE))