Source code for truc.demo
#!/usr/bin/env python
__docformat__ = 'restructuredtext en'
from string import ascii_letters, digits
table = ascii_letters + digits + '-'
[docs]def is_valid_host(machine='&truc'):
"""Check machine.
A machine must start with an ascii_letter
>>> is_valid_host('azerty')
True
>>> is_valid_host('Qwerty')
True
>>> is_valid_host('&azerty')
False
A machine can only contain chararcters present in table
table == ascii_letters + digits + '-'
>>> table
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-'
>>> is_valid_host('azerty-0123456789-QWERTY')
True
>>> is_valid_host('azerty-0123456789-&-QWERTY')
False
"""
if machine[0] not in ascii_letters:
return False
else:
bad_characters = [character for character in machine[1:]
if character not in table]
return not bad_characters
if __name__ == "__main__":
import doctest
OPTIONS = doctest.REPORT_ONLY_FIRST_FAILURE | doctest.ELLIPSIS |\
doctest.NORMALIZE_WHITESPACE
doctest.testmod(verbose=True, optionflags=OPTIONS)
# vim:set et sts=4 ts=4 tw=80: