Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/pip/_internal/utils/models.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 """Utilities for defining models | |
2 """ | |
3 | |
4 import operator | |
5 | |
6 | |
7 class KeyBasedCompareMixin(object): | |
8 """Provides comparison capabilities that is based on a key | |
9 """ | |
10 | |
11 def __init__(self, key, defining_class): | |
12 self._compare_key = key | |
13 self._defining_class = defining_class | |
14 | |
15 def __hash__(self): | |
16 return hash(self._compare_key) | |
17 | |
18 def __lt__(self, other): | |
19 return self._compare(other, operator.__lt__) | |
20 | |
21 def __le__(self, other): | |
22 return self._compare(other, operator.__le__) | |
23 | |
24 def __gt__(self, other): | |
25 return self._compare(other, operator.__gt__) | |
26 | |
27 def __ge__(self, other): | |
28 return self._compare(other, operator.__ge__) | |
29 | |
30 def __eq__(self, other): | |
31 return self._compare(other, operator.__eq__) | |
32 | |
33 def __ne__(self, other): | |
34 return self._compare(other, operator.__ne__) | |
35 | |
36 def _compare(self, other, method): | |
37 if not isinstance(other, self._defining_class): | |
38 return NotImplemented | |
39 | |
40 return method(self._compare_key, other._compare_key) |