def name_get(value):
'''
Check that a string is a valid name, and return it. A name is a string
that is just one word, without whitespace. Raise a GetError if the
string is not a valid name.
'''
if not isinstance(value, str):
raise GetError("non-string value '%s' not a valid name" % value)
if not value:
raise GetError("empty string not a valid name")
name = value.strip()
if not re.fullmatch("[^\\s][^\\s]*", name):
raise GetError("given string not a valid name (contains whitespace): %s" % name)
return name
评论列表
文章目录