X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/55f0fc7026f9f95101f881768aece40d9c50773b..98a1d50bd9c33b6cc9f281617400374e306378f7:/catacomb/__init__.py?ds=sidebyside diff --git a/catacomb/__init__.py b/catacomb/__init__.py index 24f3a61..bd8aa57 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -387,12 +387,15 @@ class BaseRat (object): return type(me)(me._d*n, me._n*d) __div__ = __truediv__ __rdiv__ = __rtruediv__ - def __cmp__(me, you): + def _order(me, you, op): n, d = _split_rat(you) - return cmp(me._n*d, n*me._d) - def __rcmp__(me, you): - n, d = _split_rat(you) - return cmp(n*me._d, me._n*d) + return op(me._n*d, n*me._d) + def __eq__(me, you): return me._order(you, lambda x, y: x == y) + def __ne__(me, you): return me._order(you, lambda x, y: x != y) + def __le__(me, you): return me._order(you, lambda x, y: x <= y) + def __lt__(me, you): return me._order(you, lambda x, y: x < y) + def __gt__(me, you): return me._order(you, lambda x, y: x > y) + def __ge__(me, you): return me._order(you, lambda x, y: x >= y) class IntRat (BaseRat): RING = MP @@ -652,10 +655,23 @@ _augment(KeySZSet, _tmp) ### Key data objects. class _tmp: + def merge(me, file, report = None): + """KF.merge(FILE, [report = ])""" + name = file.name + lno = 1 + for line in file: + me.mergeline(name, lno, line, report) + lno += 1 + return me def __repr__(me): return '%s(%r)' % (_clsname(me), me.name) _augment(KeyFile, _tmp) class _tmp: + def extract(me, file, filter = ''): + """KEY.extract(FILE, [filter = ])""" + line = me.extractline(filter) + file.write(line) + return me def __repr__(me): return '%s(%r)' % (_clsname(me), me.fulltag) _augment(Key, _tmp)