summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2015-06-06 08:37:12 +0000
committerelie <elie>2015-06-06 08:37:12 +0000
commitfe784bc6e56bcd75d613b01f9d2d912a32f2dce2 (patch)
treecdfc0b8d3ba553b9b790b1171e58448fbbd10d02
parent17b8d1d5f880d959a47f562238a91a7bf6a040af (diff)
downloadpyasn1-fe784bc6e56bcd75d613b01f9d2d912a32f2dce2.tar.gz
Asn1Item.hasValue() added to easily distinguish initalized ASN.1 objects
from uninitialized ones (e.g. pure pyasn1 types)
-rw-r--r--CHANGES2
-rw-r--r--pyasn1/type/base.py9
2 files changed, 8 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index c6ecfc6..1ccd415 100644
--- a/CHANGES
+++ b/CHANGES
@@ -50,6 +50,8 @@ Revision 0.1.8rc3
- Float typed mantissa initializer to REAL type for base 2 added.
- Encoding bases 8 and 16 support for REAL type binary encoder added.
- More strict CER/DER encoders added for GeneralizedTime and UTCTime types.
+- Asn1Item.hasValue() added to easily distinguish initalized ASN.1 objects
+ from uninitialized ones (e.g. pure types).
- Fix to REAL type binary decoder to handle different bases and scale factor.
- Fix to TagSet.repr() to include [obsolete] baseTag information.
- Fix to broken REAL type decoding handling.
diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py
index 600ae98..155ed74 100644
--- a/pyasn1/type/base.py
+++ b/pyasn1/type/base.py
@@ -101,6 +101,9 @@ class AbstractSimpleAsn1Item(Asn1ItemBase):
def __bool__(self): return bool(self._value)
def __hash__(self): return self.__hashedValue
+ def hasValue(self):
+ return not isinstance(self._value, NoValue)
+
def clone(self, value=None, tagSet=None, subtypeSpec=None):
if value is None and tagSet is None and subtypeSpec is None:
return self
@@ -132,10 +135,10 @@ class AbstractSimpleAsn1Item(Asn1ItemBase):
def prettyOut(self, value): return str(value)
def prettyPrint(self, scope=0):
- if self._value is noValue:
- return '<no value>'
- else:
+ if self.hasValue():
return self.prettyOut(self._value)
+ else:
+ return '<no value>'
# XXX Compatibility stub
def prettyPrinter(self, scope=0): return self.prettyPrint(scope)