Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertEqual(getPaddingNum('##@@'), 10)
self.assertEqual(getPaddingNum('%01d'), 1)
self.assertEqual(getPaddingNum('%1d'), 1)
self.assertEqual(getPaddingNum('%04d'), 4)
self.assertEqual(getPaddingNum('%10d'), 10)
self.assertEqual(getPaddingNum('%00d'), 1)
self.assertEqual(getPaddingNum('%0d'), 1)
self.assertEqual(getPaddingNum('%d'), 1)
self.assertEqual(getPaddingNum('$F'), 1)
self.assertEqual(getPaddingNum('$F1'), 1)
self.assertEqual(getPaddingNum('$F2'), 2)
self.assertEqual(getPaddingNum('$F3'), 3)
allPossibleChars = [s for s in string.printable if s not in PAD_MAP]
for char in allPossibleChars:
self.assertRaises(ValueError, getPaddingNum, char)
self.assertRaises(ValueError, getPaddingNum, '#{}'.format(char))
self.assertRaises(ValueError, getPaddingNum, '@{}'.format(char))
allPossibleChars = [s for s in string.printable if s not in PAD_MAP and s not in string.digits]
for char in allPossibleChars:
self.assertRaises(ValueError, getPaddingNum, '%{}d'.format(char))
allPossibleChars = [s for s in string.printable if s not in PAD_MAP and s not in string.digits]
for char in allPossibleChars:
self.assertRaises(ValueError, getPaddingNum, '$F{}'.format(char))
"""Init the class
"""
sequence = utils.asString(sequence)
if not hasattr(self, '_frameSet'):
self._frameSet = None
try:
# the main case, padding characters in the path.1-100#.exr
path, frames, self._pad, self._ext = SPLIT_RE.split(sequence, 1)
self._dir, self._base = os.path.split(path)
self._frameSet = FrameSet(frames)
except ValueError:
# edge case 1; we've got an invalid pad
for placeholder in PAD_MAP:
if placeholder in sequence:
msg = "Failed to parse FileSequence: {0}"
raise ParseException(msg.format(sequence))
# edge case 2; we've got a single frame of a sequence
a_frame = DISK_RE.match(sequence)
if a_frame:
self._dir, self._base, frames, self._ext = a_frame.groups()
# edge case 3: we've got a single versioned file, not a sequence
if frames and not self._base.endswith('.'):
self._base = self._base + frames
self._pad = ''
elif not frames:
self._pad = ''
self._frameSet = None
else:
self._frameSet = FrameSet(frames)
Return True if the given string is a frame range. Any padding
characters, such as '#' and '@' are ignored.
Args:
frange (str): a frame range to test
Returns:
bool:
"""
# we're willing to trim padding characters from consideration
# this translation is orders of magnitude faster than prior method
if future.utils.PY2:
frange = bytes(frange).translate(None, ''.join(PAD_MAP.keys()))
else:
frange = str(frange)
for key in PAD_MAP:
frange = frange.replace(key, '')
if not frange:
return True
for part in utils.asString(frange).split(','):
if not part:
continue
try:
FrameSet._parse_frange_part(part)
except ParseException:
return False
return True
# in all other cases, cast to a string
else:
try:
frange = utils.asString(frange)
except Exception as err:
msg = 'Could not parse "{0}": cast to string raised: {1}'
raise ParseException(msg.format(frange, err))
# we're willing to trim padding characters from consideration
# this translation is orders of magnitude faster than prior method
if future.utils.PY2:
frange = bytes(frange).translate(None, ''.join(PAD_MAP.keys()))
self._frange = utils.asString(frange)
else:
frange = str(frange)
for key in PAD_MAP:
frange = frange.replace(key, '')
self._frange = utils.asString(frange)
# because we're acting like a set, we need to support the empty set
if not self._frange:
self._items = frozenset()
self._order = tuple()
return
# build the mutable stores, then cast to immutable for storage
items = set()
order = []
maxSize = constants.MAX_FRAME_SIZE
for part in self._frange.split(","):
Returns:
int:
Raises:
ValueError: if unsupported padding character is detected
"""
match = PRINTF_SYNTAX_PADDING_RE.match(chars) or HOUDINI_SYNTAX_PADDING_RE.match(chars)
if match:
paddingNumStr = match.group(1)
paddingNum = int(paddingNumStr) if paddingNumStr else 1
return max(paddingNum, 1)
try:
rval = 0
for char in chars:
rval += PAD_MAP[char]
return rval
except KeyError:
msg = "Detected an unsupported padding character: \"{}\"."
msg += " Supported padding characters: {} or printf syntax padding"
msg += " %d"
raise ValueError(msg.format(char, utils.asString(list(PAD_MAP))))
match = PRINTF_SYNTAX_PADDING_RE.match(chars) or HOUDINI_SYNTAX_PADDING_RE.match(chars)
if match:
paddingNumStr = match.group(1)
paddingNum = int(paddingNumStr) if paddingNumStr else 1
return max(paddingNum, 1)
try:
rval = 0
for char in chars:
rval += PAD_MAP[char]
return rval
except KeyError:
msg = "Detected an unsupported padding character: \"{}\"."
msg += " Supported padding characters: {} or printf syntax padding"
msg += " %d"
raise ValueError(msg.format(char, utils.asString(list(PAD_MAP))))
self._items = frozenset(items)
self._frange = FrameSet.framesToFrameRange(
self._order, sort=False, compress=False)
return
# in all other cases, cast to a string
else:
try:
frange = utils.asString(frange)
except Exception as err:
msg = 'Could not parse "{0}": cast to string raised: {1}'
raise ParseException(msg.format(frange, err))
# we're willing to trim padding characters from consideration
# this translation is orders of magnitude faster than prior method
if future.utils.PY2:
frange = bytes(frange).translate(None, ''.join(PAD_MAP.keys()))
self._frange = utils.asString(frange)
else:
frange = str(frange)
for key in PAD_MAP:
frange = frange.replace(key, '')
self._frange = utils.asString(frange)
# because we're acting like a set, we need to support the empty set
if not self._frange:
self._items = frozenset()
self._order = tuple()
return
# build the mutable stores, then cast to immutable for storage
items = set()
order = []