diff options
author | Ilya Etingof <etingof@gmail.com> | 2017-10-16 23:45:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-16 23:45:38 +0200 |
commit | d1f9acd3859b7e40494bd619ab2e1c52dd72379c (patch) | |
tree | e4b24cff7c18da7461f12f773173fe539157e344 /pyasn1 | |
parent | e9371571a198af2c49151155f7a8ca9aa72580b9 (diff) | |
download | pyasn1-git-d1f9acd3859b7e40494bd619ab2e1c52dd72379c.tar.gz |
Remove None initializer support (#91)
* `None` legacy initializer support removed
* Default value for `Null` removed
Diffstat (limited to 'pyasn1')
-rw-r--r-- | pyasn1/codec/ber/decoder.py | 2 | ||||
-rw-r--r-- | pyasn1/type/base.py | 15 | ||||
-rw-r--r-- | pyasn1/type/univ.py | 22 |
3 files changed, 19 insertions, 20 deletions
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py index f2c4e4a..82bf19a 100644 --- a/pyasn1/codec/ber/decoder.py +++ b/pyasn1/codec/ber/decoder.py @@ -284,7 +284,7 @@ class NullDecoder(AbstractSimpleDecoder): head, tail = substrate[:length], substrate[length:] - component = self._createComponent(asn1Spec, tagSet, None, **options) + component = self._createComponent(asn1Spec, tagSet, noValue, **options) if head: raise error.PyAsn1Error('Unexpected %d-octet substrate for Null' % length) diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py index 3270e0a..5d5d71b 100644 --- a/pyasn1/type/base.py +++ b/pyasn1/type/base.py @@ -119,7 +119,7 @@ class Asn1ItemBase(Asn1Item): @staticmethod def isNoValue(*values): for value in values: - if value is not None and value is not noValue: + if value is not noValue: return False return True @@ -185,8 +185,9 @@ class NoValue(object): def __getattr__(self, attr): if attr in self.skipMethods: - raise AttributeError('attribute %s not present' % attr) - raise error.PyAsn1Error('No value for "%s"' % attr) + raise AttributeError('Attribute %s not present' % attr) + + raise error.PyAsn1Error('Attempted "%s" operation on ASN.1 schema object' % attr) def __repr__(self): return '%s()' % self.__class__.__name__ @@ -201,7 +202,7 @@ class AbstractSimpleAsn1Item(Asn1ItemBase): def __init__(self, value=noValue, **kwargs): Asn1ItemBase.__init__(self, **kwargs) - if value is noValue or value is None: + if value is noValue: value = self.defaultValue else: value = self.prettyIn(value) @@ -307,7 +308,7 @@ class AbstractSimpleAsn1Item(Asn1ItemBase): : new instance of |ASN.1| type/value """ - if value is noValue or value is None: + if value is noValue: if not kwargs: return self @@ -349,7 +350,7 @@ class AbstractSimpleAsn1Item(Asn1ItemBase): : new instance of |ASN.1| type/value """ - if value is noValue or value is None: + if value is noValue: if not kwargs: return self @@ -448,7 +449,7 @@ class AbstractConstructedAsn1Item(Asn1ItemBase): representation = '%s(%s)' % (self.__class__.__name__, ', '.join(representation)) if self._componentValues: for idx, component in enumerate(self._componentValues): - if component is None or component is noValue: + if component is noValue: continue representation += '.setComponentByPosition(%d, %s)' % (idx, repr(component)) return representation diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py index 8e78f77..f30e631 100644 --- a/pyasn1/type/univ.py +++ b/pyasn1/type/univ.py @@ -414,7 +414,7 @@ class BitString(base.AbstractSimpleAsn1Item): return self.bitLength def __init__(self, value=noValue, **kwargs): - if value is noValue or value is None: + if value is noValue: if kwargs: try: value = self.fromBinaryString(kwargs.pop('binValue'), internalFormat=True) @@ -428,7 +428,7 @@ class BitString(base.AbstractSimpleAsn1Item): except KeyError: pass - if value is noValue or value is None: + if value is noValue: if self.defaultBinValue is not noValue: value = self.fromBinaryString(self.defaultBinValue, internalFormat=True) @@ -839,7 +839,7 @@ class OctetString(base.AbstractSimpleAsn1Item): def __init__(self, value=noValue, **kwargs): if kwargs: - if value is noValue or value is None: + if value is noValue: try: value = self.fromBinaryString(kwargs.pop('binValue')) @@ -852,7 +852,7 @@ class OctetString(base.AbstractSimpleAsn1Item): except KeyError: pass - if value is noValue or value is None: + if value is noValue: if self.defaultBinValue is not noValue: value = self.fromBinaryString(self.defaultBinValue) @@ -1158,7 +1158,7 @@ class Null(OctetString): Parameters ---------- value : :class:`str` or :py:class:`~pyasn1.type.univ.Null` object - Python empty string literal or *Null* class instance. + Python empty string literal or any object that evaluates to `False` tagSet: :py:class:`~pyasn1.type.tag.TagSet` Object representing non-default ASN.1 tag(s) @@ -1168,7 +1168,6 @@ class Null(OctetString): : :py:class:`pyasn1.error.PyAsn1Error` On constraint violation or bad initializer. """ - defaultValue = ''.encode() # This is tightly constrained #: Set (on class, not on instance) or return a #: :py:class:`~pyasn1.type.tag.TagSet` object representing ASN.1 tag(s) @@ -1232,6 +1231,11 @@ class Null(OctetString): """ return OctetString.subtype(self, value, **kwargs) + def prettyIn(self, value): + if value: + return value + + return octets.str2octs('') if sys.version_info[0] <= 2: intTypes = (int, long) @@ -1879,9 +1883,6 @@ class SequenceOfAndSetOfBase(base.AbstractConstructedAsn1Item): IndexError: When idx > len(self) """ - if value is None: # backward compatibility - value = noValue - componentType = self.componentType try: @@ -2319,9 +2320,6 @@ class SequenceAndSetBase(base.AbstractConstructedAsn1Item): ------- self """ - if value is None: # backward compatibility - value = noValue - componentType = self.componentType componentTypeLen = self._componentTypeLen |