X-Git-Url: http://www.git.cypherpunks.ru/?p=pyderasn.git;a=blobdiff_plain;f=pyderasn.py;h=acf5fbe8174b3007e9399783dc3c996d4e505d00;hp=4ae1eb0814182f065fa045d1c89b7a9f6c11e9ba;hb=821d914c81314c0df3d0791efa783c196eb0a96b;hpb=f2ceb9912635bbb6e8999a257bcc5fdb473df01c diff --git a/pyderasn.py b/pyderasn.py index 4ae1eb0..acf5fbe 100755 --- a/pyderasn.py +++ b/pyderasn.py @@ -318,6 +318,7 @@ from collections import OrderedDict from datetime import datetime from math import ceil +from six import add_metaclass from six import binary_type from six import byte2int from six import indexbytes @@ -655,6 +656,13 @@ def len_decode(data): # Base class ######################################################################## +class AutoAddSlots(type): + def __new__(cls, name, bases, _dict): + _dict["__slots__"] = _dict.get("__slots__", ()) + return type.__new__(cls, name, bases, _dict) + + +@add_metaclass(AutoAddSlots) class Obj(object): """Common ASN.1 object class @@ -709,7 +717,7 @@ class Obj(object): def decoded(self): """Is object decoded? """ - return self.llen > 0 + return (self.llen + self.vlen) > 0 def copy(self): # pragma: no cover """Make a copy of object, safe to be mutated @@ -727,6 +735,18 @@ class Obj(object): def __str__(self): # pragma: no cover return self.__bytes__() if PY2 else self.__unicode__() + def __ne__(self, their): + return not(self == their) + + def __gt__(self, their): # pragma: no cover + return not(self < their) + + def __le__(self, their): # pragma: no cover + return (self == their) or (self < their) + + def __ge__(self, their): # pragma: no cover + return (self == their) or (self > their) + def _encode(self): # pragma: no cover raise NotImplementedError() @@ -1319,10 +1339,7 @@ class Integer(Obj): ) def __lt__(self, their): - return self._value < their - - def __gt__(self, their): - return self._value > their + return self._value < their._value @property def named(self): @@ -1938,6 +1955,9 @@ class OctetString(Obj): self._expl == their._expl ) + def __lt__(self, their): + return self._value < their._value + def __call__( self, value=None, @@ -2305,10 +2325,7 @@ class ObjectIdentifier(Obj): ) def __lt__(self, their): - return self._value < their - - def __gt__(self, their): - return self._value > their + return self._value < their._value def __call__( self,