| 78 | _MIN_READ_BUF_SIZE = 1 << 20 |
| 79 | |
| 80 | class UID: |
| 81 | def __init__(self, data): |
| 82 | if not isinstance(data, int): |
| 83 | raise TypeError("data must be an int") |
| 84 | if data >= 1 << 64: |
| 85 | raise ValueError("UIDs cannot be >= 2**64") |
| 86 | if data < 0: |
| 87 | raise ValueError("UIDs must be positive") |
| 88 | self.data = data |
| 89 | |
| 90 | def __index__(self): |
| 91 | return self.data |
| 92 | |
| 93 | def __repr__(self): |
| 94 | return "%s(%s)" % (self.__class__.__name__, repr(self.data)) |
| 95 | |
| 96 | def __reduce__(self): |
| 97 | return self.__class__, (self.data,) |
| 98 | |
| 99 | def __eq__(self, other): |
| 100 | if not isinstance(other, UID): |
| 101 | return NotImplemented |
| 102 | return self.data == other.data |
| 103 | |
| 104 | def __hash__(self): |
| 105 | return hash(self.data) |
| 106 | |
| 107 | # |
| 108 | # XML support |
no outgoing calls