Enum where members are also (and must be) strings
| 1340 | |
| 1341 | |
| 1342 | class StrEnum(str, ReprEnum): |
| 1343 | """ |
| 1344 | Enum where members are also (and must be) strings |
| 1345 | """ |
| 1346 | |
| 1347 | def __new__(cls, *values): |
| 1348 | "values must already be of type `str`" |
| 1349 | if len(values) > 3: |
| 1350 | raise TypeError('too many arguments for str(): %r' % (values, )) |
| 1351 | if len(values) == 1: |
| 1352 | # it must be a string |
| 1353 | if not isinstance(values[0], str): |
| 1354 | raise TypeError('%r is not a string' % (values[0], )) |
| 1355 | if len(values) >= 2: |
| 1356 | # check that encoding argument is a string |
| 1357 | if not isinstance(values[1], str): |
| 1358 | raise TypeError('encoding must be a string, not %r' % (values[1], )) |
| 1359 | if len(values) == 3: |
| 1360 | # check that errors argument is a string |
| 1361 | if not isinstance(values[2], str): |
| 1362 | raise TypeError('errors must be a string, not %r' % (values[2])) |
| 1363 | value = str(*values) |
| 1364 | member = str.__new__(cls, value) |
| 1365 | member._value_ = value |
| 1366 | return member |
| 1367 | |
| 1368 | @staticmethod |
| 1369 | def _generate_next_value_(name, start, count, last_values): |
| 1370 | """ |
| 1371 | Return the lower-cased version of the member name. |
| 1372 | """ |
| 1373 | return name.lower() |
| 1374 | |
| 1375 | |
| 1376 | def pickle_by_global_name(self, proto): |
no outgoing calls