| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9a6e62b commit 47b9ff6
57 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -379,6 +379,7 @@ PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *); | |||
| 379 | 379 | PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *); | |
| 380 | 380 | PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int); | |
| 381 | 381 | PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int); | |
| 382 | + PyAPI_FUNC(PyObject *) Py_CmpToRich(int op, int cmp); | ||
| 382 | 383 | PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *); | |
| 383 | 384 | PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *); | |
| 384 | 385 | PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,7 +116,7 @@ def tell(self): | |||
| 116 | 116 | _complain_ifclosed(self.closed) | |
| 117 | 117 | return self.pos | |
| 118 | 118 | ||
| 119 | - def read(self, n = -1): | ||
| 119 | + def read(self, n=None): | ||
| 120 | 120 | """Read at most size bytes from the file | |
| 121 | 121 | (less if the read hits EOF before obtaining size bytes). | |
| 122 | 122 | ||
@@ -128,6 +128,8 @@ def read(self, n = -1): | |||
| 128 | 128 | if self.buflist: | |
| 129 | 129 | self.buf += ''.join(self.buflist) | |
| 130 | 130 | self.buflist = [] | |
| 131 | + if n is None: | ||
| 132 | + n = -1 | ||
| 131 | 133 | if n < 0: | |
| 132 | 134 | newpos = self.len | |
| 133 | 135 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,11 +8,16 @@ def __init__(self, dict=None, **kwargs): | |||
| 8 | 8 | if len(kwargs): | |
| 9 | 9 | self.update(kwargs) | |
| 10 | 10 | def __repr__(self): return repr(self.data) | |
| 11 | - def __cmp__(self, dict): | ||
| 11 | + def __eq__(self, dict): | ||
| 12 | 12 | if isinstance(dict, UserDict): | |
| 13 | - return cmp(self.data, dict.data) | ||
| 13 | + return self.data == dict.data | ||
| 14 | 14 | else: | |
| 15 | - return cmp(self.data, dict) | ||
| 15 | + return self.data == dict | ||
| 16 | + def __ne__(self, dict): | ||
| 17 | + if isinstance(dict, UserDict): | ||
| 18 | + return self.data != dict.data | ||
| 19 | + else: | ||
| 20 | + return self.data != dict | ||
| 16 | 21 | def __len__(self): return len(self.data) | |
| 17 | 22 | def __getitem__(self, key): | |
| 18 | 23 | if key in self.data: | |
@@ -162,11 +167,13 @@ def get(self, key, default=None): | |||
| 162 | 167 | return default | |
| 163 | 168 | def __repr__(self): | |
| 164 | 169 | return repr(dict(self.iteritems())) | |
| 165 | - def __cmp__(self, other): | ||
| 166 | - if other is None: | ||
| 167 | - return 1 | ||
| 170 | + def __eq__(self, other): | ||
| 171 | + if isinstance(other, DictMixin): | ||
| 172 | + other = dict(other.iteritems()) | ||
| 173 | + return dict(self.iteritems()) == other | ||
| 174 | + def __ne__(self, other): | ||
| 168 | 175 | if isinstance(other, DictMixin): | |
| 169 | 176 | other = dict(other.iteritems()) | |
| 170 | - return cmp(dict(self.iteritems()), other) | ||
| 177 | + return dict(self.iteritems()) != other | ||
| 171 | 178 | def __len__(self): | |
| 172 | 179 | return len(self.keys()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,11 +25,37 @@ def __float__(self): return float(self.data) | |||
| 25 | 25 | def __complex__(self): return complex(self.data) | |
| 26 | 26 | def __hash__(self): return hash(self.data) | |
| 27 | 27 | ||
| 28 | - def __cmp__(self, string): | ||
| 28 | + def __eq__(self, string): | ||
| 29 | 29 | if isinstance(string, UserString): | |
| 30 | - return cmp(self.data, string.data) | ||
| 30 | + return self.data == string.data | ||
| 31 | 31 | else: | |
| 32 | - return cmp(self.data, string) | ||
| 32 | + return self.data == string | ||
| 33 | + def __ne__(self, string): | ||
| 34 | + if isinstance(string, UserString): | ||
| 35 | + return self.data != string.data | ||
| 36 | + else: | ||
| 37 | + return self.data != string | ||
| 38 | + def __lt__(self, string): | ||
| 39 | + if isinstance(string, UserString): | ||
| 40 | + return self.data < string.data | ||
| 41 | + else: | ||
| 42 | + return self.data < string | ||
| 43 | + def __le__(self, string): | ||
| 44 | + if isinstance(string, UserString): | ||
| 45 | + return self.data <= string.data | ||
| 46 | + else: | ||
| 47 | + return self.data <= string | ||
| 48 | + def __gt__(self, string): | ||
| 49 | + if isinstance(string, UserString): | ||
| 50 | + return self.data > string.data | ||
| 51 | + else: | ||
| 52 | + return self.data > string | ||
| 53 | + def __ge__(self, string): | ||
| 54 | + if isinstance(string, UserString): | ||
| 55 | + return self.data >= string.data | ||
| 56 | + else: | ||
| 57 | + return self.data >= string | ||
| 58 | + | ||
| 33 | 59 | def __contains__(self, char): | |
| 34 | 60 | return char in self.data | |
| 35 | 61 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,10 +2,10 @@ | |||
| 2 | 2 | from ctypes import * | |
| 3 | 3 | ||
| 4 | 4 | class MyInt(c_int): | |
| 5 | - def __cmp__(self, other): | ||
| 5 | + def __eq__(self, other): | ||
| 6 | 6 | if type(other) != MyInt: | |
| 7 | - return -1 | ||
| 8 | - return cmp(self.value, other.value) | ||
| 7 | + return NotImplementedError | ||
| 8 | + return self.value == other.value | ||
| 9 | 9 | ||
| 10 | 10 | class Test(unittest.TestCase): | |
| 11 | 11 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -706,6 +706,26 @@ def __ne__(self, other): | |||
| 706 | 706 | return NotImplemented | |
| 707 | 707 | return self.__cmp__(other) != 0 | |
| 708 | 708 | ||
| 709 | + def __lt__(self, other): | ||
| 710 | + if not isinstance(other, (Decimal, int, long)): | ||
| 711 | + return NotImplemented | ||
| 712 | + return self.__cmp__(other) < 0 | ||
| 713 | + | ||
| 714 | + def __le__(self, other): | ||
| 715 | + if not isinstance(other, (Decimal, int, long)): | ||
| 716 | + return NotImplemented | ||
| 717 | + return self.__cmp__(other) <= 0 | ||
| 718 | + | ||
| 719 | + def __gt__(self, other): | ||
| 720 | + if not isinstance(other, (Decimal, int, long)): | ||
| 721 | + return NotImplemented | ||
| 722 | + return self.__cmp__(other) > 0 | ||
| 723 | + | ||
| 724 | + def __ge__(self, other): | ||
| 725 | + if not isinstance(other, (Decimal, int, long)): | ||
| 726 | + return NotImplemented | ||
| 727 | + return self.__cmp__(other) >= 0 | ||
| 728 | + | ||
| 709 | 729 | def compare(self, other, context=None): | |
| 710 | 730 | """Compares one to another. | |
| 711 | 731 | ||
@@ -1894,6 +1914,7 @@ def to_integral(self, rounding=None, context=None): | |||
| 1894 | 1914 | ans = self._check_nans(context=context) | |
| 1895 | 1915 | if ans: | |
| 1896 | 1916 | return ans | |
| 1917 | + return self | ||
| 1897 | 1918 | if self._exp >= 0: | |
| 1898 | 1919 | return self | |
| 1899 | 1920 | if context is None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,8 @@ | |||
| 32 | 32 | class Version: | |
| 33 | 33 | """Abstract base class for version numbering classes. Just provides | |
| 34 | 34 | constructor (__init__) and reproducer (__repr__), because those | |
| 35 | - seem to be the same for all version numbering classes. | ||
| 35 | + seem to be the same for all version numbering classes; and route | ||
| 36 | + rich comparisons to __cmp__. | ||
| 36 | 37 | """ | |
| 37 | 38 | ||
| 38 | 39 | def __init__ (self, vstring=None): | |
@@ -42,6 +43,42 @@ def __init__ (self, vstring=None): | |||
| 42 | 43 | def __repr__ (self): | |
| 43 | 44 | return "%s ('%s')" % (self.__class__.__name__, str(self)) | |
| 44 | 45 | ||
| 46 | + def __eq__(self, other): | ||
| 47 | + c = self.__cmp__(other) | ||
| 48 | + if c is NotImplemented: | ||
| 49 | + return c | ||
| 50 | + return c == 0 | ||
| 51 | + | ||
| 52 | + def __ne__(self, other): | ||
| 53 | + c = self.__cmp__(other) | ||
| 54 | + if c is NotImplemented: | ||
| 55 | + return c | ||
| 56 | + return c != 0 | ||
| 57 | + | ||
| 58 | + def __lt__(self, other): | ||
| 59 | + c = self.__cmp__(other) | ||
| 60 | + if c is NotImplemented: | ||
| 61 | + return c | ||
| 62 | + return c < 0 | ||
| 63 | + | ||
| 64 | + def __le__(self, other): | ||
| 65 | + c = self.__cmp__(other) | ||
| 66 | + if c is NotImplemented: | ||
| 67 | + return c | ||
| 68 | + return c <= 0 | ||
| 69 | + | ||
| 70 | + def __gt__(self, other): | ||
| 71 | + c = self.__cmp__(other) | ||
| 72 | + if c is NotImplemented: | ||
| 73 | + return c | ||
| 74 | + return c > 0 | ||
| 75 | + | ||
| 76 | + def __ge__(self, other): | ||
| 77 | + c = self.__cmp__(other) | ||
| 78 | + if c is NotImplemented: | ||
| 79 | + return c | ||
| 80 | + return c >= 0 | ||
| 81 | + | ||
| 45 | 82 | ||
| 46 | 83 | # Interface for version-number classes -- must be implemented | |
| 47 | 84 | # by the following classes (the concrete ones -- Version should | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -469,11 +469,12 @@ def __repr__(self): | |||
| 469 | 469 | ||
| 470 | 470 | ||
| 471 | 471 | # This lets us sort tests by name: | |
| 472 | - def __cmp__(self, other): | ||
| 472 | + def __lt__(self, other): | ||
| 473 | 473 | if not isinstance(other, DocTest): | |
| 474 | - return -1 | ||
| 475 | - return cmp((self.name, self.filename, self.lineno, id(self)), | ||
| 476 | - (other.name, other.filename, other.lineno, id(other))) | ||
| 474 | + return NotImplemented | ||
| 475 | + return ((self.name, self.filename, self.lineno, id(self)) | ||
| 476 | + < | ||
| 477 | + (other.name, other.filename, other.lineno, id(other))) | ||
| 477 | 478 | ||
| 478 | 479 | ###################################################################### | |
| 479 | 480 | ## 3. DocTestParser | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -838,13 +838,13 @@ def __str__(self): | |||
| 838 | 838 | ||
| 839 | 839 | __repr__ = _repr | |
| 840 | 840 | ||
| 841 | - def __cmp__(self, other): | ||
| 841 | + def __eq__(self, other): | ||
| 842 | 842 | if isinstance(other, Values): | |
| 843 | - return cmp(self.__dict__, other.__dict__) | ||
| 843 | + return self.__dict__ == other.__dict__ | ||
| 844 | 844 | elif isinstance(other, types.DictType): | |
| 845 | - return cmp(self.__dict__, other) | ||
| 845 | + return self.__dict__ == other | ||
| 846 | 846 | else: | |
| 847 | - return -1 | ||
| 847 | + return NotImplemented | ||
| 848 | 848 | ||
| 849 | 849 | def _update_careful(self, dict): | |
| 850 | 850 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -374,13 +374,13 @@ def fromBase64(cls, data): | |||
| 374 | 374 | def asBase64(self, maxlinelength=76): | |
| 375 | 375 | return _encodeBase64(self.data, maxlinelength) | |
| 376 | 376 | ||
| 377 | - def __cmp__(self, other): | ||
| 377 | + def __eq__(self, other): | ||
| 378 | 378 | if isinstance(other, self.__class__): | |
| 379 | - return cmp(self.data, other.data) | ||
| 379 | + return self.data == other.data | ||
| 380 | 380 | elif isinstance(other, str): | |
| 381 | - return cmp(self.data, other) | ||
| 381 | + return self.data == other | ||
| 382 | 382 | else: | |
| 383 | - return cmp(id(self), id(other)) | ||
| 383 | + return id(self) == id(other) | ||
| 384 | 384 | ||
| 385 | 385 | def __repr__(self): | |
| 386 | 386 | return "%s(%s)" % (self.__class__.__name__, repr(self.data)) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments