|
Lines 1-3
Link Here
|
|
|
1 |
#!/usr/bin/python2.7 |
| 1 |
# -*- coding: utf-8 -*- |
2 |
# -*- coding: utf-8 -*- |
| 2 |
# |
3 |
# |
| 3 |
# Univention UCS@school |
4 |
# Univention UCS@school |
|
Lines 96-101
class UsernameHandler(object):
Link Here
|
| 96 |
|
97 |
|
| 97 |
:param name: str: username, possibly a template |
98 |
:param name: str: username, possibly a template |
| 98 |
:return: str: unique username |
99 |
:return: str: unique username |
|
|
100 |
|
| 101 |
>>> UsernameHandler(20).format_username('Max.Mustermann') |
| 102 |
'Max.Mustermann' |
| 103 |
>>> UsernameHandler(20).format_username('.') # doctest: +IGNORE_EXCEPTION_DETAIL |
| 104 |
Traceback (most recent call last): |
| 105 |
... |
| 106 |
FormatError: |
| 107 |
>>> UsernameHandler(20).format_username('.Max.Mustermann.') |
| 108 |
'Max.Mustermann' |
| 109 |
>>> UsernameHandler(4).format_username('Max.Mustermann') |
| 110 |
'M' |
| 111 |
>>> for c in '\x01\x00\x03\x02\x05\x04\x07\x06\t\x08\x0b\n\r\x0c\x0f\x0e\x11\x10\x13\x12\x15\x14\x17\x16\x19\x18\x1b\x1a\x1d\x1c\x1f\x1e! #"%$\'&)(+*-,/;:=<?>@[]\\_^`{}|\x7f~': |
| 112 |
... assert 'Max' == UsernameHandler(20).format_username('Ma%sx' % (c,)) |
| 113 |
... |
| 114 |
>>> UsernameHandler(20).format_username('Max.Mustermann12.4567890') |
| 115 |
'Max.Mustermann12' |
| 116 |
>>> for c in '.1032547698ACBEDGFIHKJMLONQPSRUTWVYXZacbedgfihkjmlonqpsrutwvyxz': |
| 117 |
... assert 'Ma%sx' % (c,) == UsernameHandler(20).format_username('Ma%sx' % (c,)) |
| 118 |
... |
| 119 |
>>> UsernameHandler(20).format_username('Max[Muster]Mann') |
| 120 |
'MaxMusterMann' |
| 121 |
>>> UsernameHandler(20).format_username('Max[ALWAYSCOUNTER].Mustermann') |
| 122 |
'Max1.Mustermann' |
| 123 |
>>> UsernameHandler(20).format_username('Max[ALWAYSCOUNTER].Mustermann') |
| 124 |
'Max2.Mustermann' |
| 125 |
>>> UsernameHandler(20).format_username('Max[ALWAYSCOUNTER].Mustermann') |
| 126 |
'Max3.Mustermann' |
| 127 |
>>> UsernameHandler(20).format_username('Max[COUNTER2].Mustermann') |
| 128 |
'Max4.Mustermann' |
| 129 |
>>> UsernameHandler(20).format_username('Maria[ALWAYSCOUNTER].Musterfrau') |
| 130 |
'Maria1.Musterfrau' |
| 131 |
>>> UsernameHandler(20).format_username('Moritz[COUNTER2]') |
| 132 |
'Moritz' |
| 133 |
>>> UsernameHandler(20).format_username('Moritz[COUNTER2]') |
| 134 |
'Moritz2' |
| 135 |
>>> for i, c in enumerate('\x01\x00\x03\x02\x05\x04\x07\x06\t\x08\x0b\n\r\x0c\x0f\x0e\x11\x10\x13\x12\x15\x14\x17\x16\x19\x18\x1b\x1a\x1d\x1c\x1f\x1e! #"%$\'&)(+*-,/;:=<?>@\\_^`{}|\x7f~', 1): |
| 136 |
... assert 'Foo%d' % (i) == UsernameHandler(20).format_username('Fo%so[ALWAYSCOUNTER]' % (c,)) |
| 99 |
""" |
137 |
""" |
| 100 |
assert isinstance(name, basestring) |
138 |
assert isinstance(name, basestring) |
| 101 |
ori_name = name |
139 |
ori_name = name |
|
Lines 205-207
class UsernameHandler(object):
Link Here
|
| 205 |
num = first_time |
243 |
num = first_time |
| 206 |
self.add_to_ldap(name_base, "2") |
244 |
self.add_to_ldap(name_base, "2") |
| 207 |
return num |
245 |
return num |
|
|
246 |
|
| 247 |
|
| 248 |
if __name__ == '__main__': |
| 249 |
import doctest |
| 250 |
doctest.testmod() |