Replace assertion with straight error-checking.

This commit is contained in:
Raymond Hettinger 2007-05-21 08:13:35 +00:00
parent 5faa75f3c1
commit 0d6a8ccfb7
1 changed files with 2 additions and 1 deletions

View File

@ -24,7 +24,8 @@ def NamedTuple(typename, s):
""" """
field_names = s.split() field_names = s.split()
assert ''.join(field_names).replace('_', '').isalpha() # protect against exec attacks if not ''.join([typename] + field_names).replace('_', '').isalpha():
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores')
argtxt = ', '.join(field_names) argtxt = ', '.join(field_names)
reprtxt = ', '.join('%s=%%r' % name for name in field_names) reprtxt = ', '.join('%s=%%r' % name for name in field_names)
template = '''class %(typename)s(tuple): template = '''class %(typename)s(tuple):