aboutsummaryrefslogtreecommitdiff
path: root/pyasn1/type/base.py
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2017-07-22 23:25:44 +0200
committerIlya Etingof <etingof@gmail.com>2017-07-22 23:25:44 +0200
commit81ce72d492b3cd3337b8fb8af4fa63c866f109d4 (patch)
treec932a7ade114818255c77fa804689b4dc401494f /pyasn1/type/base.py
parent2e27663e279698da09c8ac984cf649b107a9c9d4 (diff)
downloadpyasn1-81ce72d492b3cd3337b8fb8af4fa63c866f109d4.tar.gz
.namedValues refactored into a read-only attribute
Also the read-only attributes guard refactored
Diffstat (limited to 'pyasn1/type/base.py')
-rw-r--r--pyasn1/type/base.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py
index 8df9d98..d9e9f09 100644
--- a/pyasn1/type/base.py
+++ b/pyasn1/type/base.py
@@ -35,20 +35,39 @@ class Asn1ItemBase(Asn1Item):
typeId = None
def __init__(self, tagSet=None, subtypeSpec=None):
- self._readOnlyAttrs = set()
if tagSet is not None:
self.tagSet = tagSet
if subtypeSpec is not None:
self.subtypeSpec = subtypeSpec
- self._readOnlyAttrs.update(('subtypeSpec', 'tagSet'))
+ self.readOnly = 'subtypeSpec'
+ self.readOnly = 'tagSet'
def __setattr__(self, name, value):
- if not name.startswith('_') and name in self._readOnlyAttrs:
- raise error.PyAsn1Error('read-only instance attribute "%s"' % name)
+ if not name.startswith('_'):
+ try:
+ if name in self._readOnly:
+ raise error.PyAsn1Error('read-only instance attribute "%s"' % name)
+
+ except AttributeError:
+ pass
super(Asn1ItemBase, self).__setattr__(name, value)
@property
+ def readOnly(self):
+ return self._readOnly
+
+ @readOnly.setter
+ def readOnly(self, value):
+ try:
+ self._readOnly.add(value)
+
+ except AttributeError:
+ self._readOnly = set()
+
+ self._readOnly.add(value)
+
+ @property
def effectiveTagSet(self):
"""For |ASN.1| type is equivalent to *tagSet*
"""
@@ -455,7 +474,8 @@ class AbstractConstructedAsn1Item(Asn1ItemBase):
if sizeSpec is not None:
self.sizeSpec = sizeSpec
self._componentValues = []
- self._readOnlyAttrs.update(('componentType', 'sizeSpec'))
+ self.readOnly = 'componentType'
+ self.readOnly = 'sizeSpec'
def __repr__(self):
representation = []