When object is decoded, ``decoded`` property is true and you can safely
use following properties:
-* ``offset`` -- position from initial offset where object's tag is started
+* ``offset`` -- position including initial offset where object's tag starts
* ``tlen`` -- length of object's tag
* ``llen`` -- length of object's length value
* ``vlen`` -- length of object's value
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
# 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
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
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()
)
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):
def copy(self):
obj = self.__class__(_specs=self.specs)
- obj._value = self._value
+ value = self._value
+ if value is not None:
+ value = (value[0], value[1])
+ obj._value = value
obj.tag = self.tag
obj._expl = self._expl
obj.default = self.default
self._expl == their._expl
)
+ def __lt__(self, their):
+ return self._value < their._value
+
def __call__(
self,
value=None,
)
def __lt__(self, their):
- return self._value < their
-
- def __gt__(self, their):
- return self._value > their
+ return self._value < their._value
def __call__(
self,