(self, enumeration)
| 1831 | def __init__(self, *checks): |
| 1832 | self.checks = checks |
| 1833 | def __call__(self, enumeration): |
| 1834 | checks = self.checks |
| 1835 | cls_name = enumeration.__name__ |
| 1836 | if Flag is not None and issubclass(enumeration, Flag): |
| 1837 | enum_type = 'flag' |
| 1838 | elif issubclass(enumeration, Enum): |
| 1839 | enum_type = 'enum' |
| 1840 | else: |
| 1841 | raise TypeError("the 'verify' decorator only works with Enum and Flag") |
| 1842 | for check in checks: |
| 1843 | if check is UNIQUE: |
| 1844 | # check for duplicate names |
| 1845 | duplicates = [] |
| 1846 | for name, member in enumeration.__members__.items(): |
| 1847 | if name != member.name: |
| 1848 | duplicates.append((name, member.name)) |
| 1849 | if duplicates: |
| 1850 | alias_details = ', '.join( |
| 1851 | ["%s -> %s" % (alias, name) for (alias, name) in duplicates]) |
| 1852 | raise ValueError('aliases found in %r: %s' % |
| 1853 | (enumeration, alias_details)) |
| 1854 | elif check is CONTINUOUS: |
| 1855 | values = set(e.value for e in enumeration) |
| 1856 | if len(values) < 2: |
| 1857 | continue |
| 1858 | low, high = min(values), max(values) |
| 1859 | missing = [] |
| 1860 | if enum_type == 'flag': |
| 1861 | # check for powers of two |
| 1862 | for i in range(_high_bit(low)+1, _high_bit(high)): |
| 1863 | if 2**i not in values: |
| 1864 | missing.append(2**i) |
| 1865 | elif enum_type == 'enum': |
| 1866 | # check for powers of one |
| 1867 | for i in range(low+1, high): |
| 1868 | if i not in values: |
| 1869 | missing.append(i) |
| 1870 | else: |
| 1871 | raise Exception('verify: unknown type %r' % enum_type) |
| 1872 | if missing: |
| 1873 | raise ValueError(('invalid %s %r: missing values %s' % ( |
| 1874 | enum_type, cls_name, ', '.join((str(m) for m in missing))) |
| 1875 | )[:256]) |
| 1876 | # limit max length to protect against DOS attacks |
| 1877 | elif check is NAMED_FLAGS: |
| 1878 | # examine each alias and check for unnamed flags |
| 1879 | member_names = enumeration._member_names_ |
| 1880 | member_values = [m.value for m in enumeration] |
| 1881 | missing_names = [] |
| 1882 | missing_value = 0 |
| 1883 | for name, alias in enumeration._member_map_.items(): |
| 1884 | if name in member_names: |
| 1885 | # not an alias |
| 1886 | continue |
| 1887 | if alias.value < 0: |
| 1888 | # negative numbers are not checked |
| 1889 | continue |
| 1890 | values = list(_iter_bits_lsb(alias.value)) |
nothing calls this directly
no test coverage detected