def require_valid_name(name, name_type, allow_empty=False):
 if (not isinstance(name, basestring)):
  raise ValidationError(('%s must be a string.' % name_type))
 if (allow_empty and (name == '')):
  return
 if ((len(name) > 50) or (len(name) < 1)):
  raise ValidationError(('The length of %s should be between 1 and 50 characters; received %s' % (name_type, name)))
 if ((name[0] in string.whitespace) or (name[(-1)] in string.whitespace)):
  raise ValidationError('Names should not start or end with whitespace.')
 if re.search('\\s\\s+', name):
  raise ValidationError(('Adjacent whitespace in %s should be collapsed.' % name_type))
 for character in feconf.INVALID_NAME_CHARS:
  if (character in name):
   raise ValidationError(('Invalid character %s in %s: %s' % (character, name_type, name)))

def require_valid_name ( name , name_type , allow_empty = False ) : if ( not isinstance ( name , basestring ) ) : raise ValidationError ( ( '%s must be a string.' % name_type ) ) if ( allow_empty and ( name == '' ) ) : return if ( ( len ( name ) > 50 ) or ( len ( name ) < 1 ) ) : raise ValidationError ( ( 'The length of %s should be between 1 and 50 characters; received %s' % ( name_type , name ) ) ) if ( ( name [ 0 ] in string . whitespace ) or ( name [ ( - 1 ) ] in string . whitespace ) ) : raise ValidationError ( 'Names should not start or end with whitespace.' ) if re . search ( '\\s\\s+' , name ) : raise ValidationError ( ( 'Adjacent whitespace in %s should be collapsed.' % name_type ) ) for character in feconf . INVALID_NAME_CHARS : if ( character in name ) : raise ValidationError ( ( 'Invalid character %s in %s: %s' % ( character , name_type , name ) ) )
generic name validation .