Create a composite member containing all canonical members present in `value`. If non-member values are present, result depends on `_boundary_` setting.
(cls, value)
| 1473 | |
| 1474 | @classmethod |
| 1475 | def _missing_(cls, value): |
| 1476 | """ |
| 1477 | Create a composite member containing all canonical members present in `value`. |
| 1478 | |
| 1479 | If non-member values are present, result depends on `_boundary_` setting. |
| 1480 | """ |
| 1481 | if not isinstance(value, int): |
| 1482 | raise ValueError( |
| 1483 | "%r is not a valid %s" % (value, cls.__qualname__) |
| 1484 | ) |
| 1485 | # check boundaries |
| 1486 | # - value must be in range (e.g. -16 <-> +15, i.e. ~15 <-> 15) |
| 1487 | # - value must not include any skipped flags (e.g. if bit 2 is not |
| 1488 | # defined, then 0d10 is invalid) |
| 1489 | flag_mask = cls._flag_mask_ |
| 1490 | singles_mask = cls._singles_mask_ |
| 1491 | all_bits = cls._all_bits_ |
| 1492 | neg_value = None |
| 1493 | if ( |
| 1494 | not ~all_bits <= value <= all_bits |
| 1495 | or value & (all_bits ^ flag_mask) |
| 1496 | ): |
| 1497 | if cls._boundary_ is STRICT: |
| 1498 | max_bits = max(value.bit_length(), flag_mask.bit_length()) |
| 1499 | raise ValueError( |
| 1500 | "%r invalid value %r\n given %s\n allowed %s" % ( |
| 1501 | cls, value, bin(value, max_bits), bin(flag_mask, max_bits), |
| 1502 | )) |
| 1503 | elif cls._boundary_ is CONFORM: |
| 1504 | value = value & flag_mask |
| 1505 | elif cls._boundary_ is EJECT: |
| 1506 | return value |
| 1507 | elif cls._boundary_ is KEEP: |
| 1508 | if value < 0: |
| 1509 | value = ( |
| 1510 | max(all_bits+1, 2**(value.bit_length())) |
| 1511 | + value |
| 1512 | ) |
| 1513 | else: |
| 1514 | raise ValueError( |
| 1515 | '%r unknown flag boundary %r' % (cls, cls._boundary_, ) |
| 1516 | ) |
| 1517 | if value < 0: |
| 1518 | neg_value = value |
| 1519 | if cls._boundary_ in (EJECT, KEEP): |
| 1520 | value = all_bits + 1 + value |
| 1521 | else: |
| 1522 | value = singles_mask & value |
| 1523 | # get members and unknown |
| 1524 | unknown = value & ~flag_mask |
| 1525 | aliases = value & ~singles_mask |
| 1526 | member_value = value & singles_mask |
| 1527 | if unknown and cls._boundary_ is not KEEP: |
| 1528 | raise ValueError( |
| 1529 | '%s(%r) --> unknown values %r [%s]' |
| 1530 | % (cls.__name__, value, unknown, bin(unknown)) |
| 1531 | ) |
| 1532 | # normal Flag? |
nothing calls this directly
no test coverage detected