From 054a4187b095dfb2184253f0498a298b7408ef72 Mon Sep 17 00:00:00 2001 From: elie Date: Thu, 30 May 2013 19:30:48 +0000 Subject: * Fix to SEQUENCE and SET types to give them their private componentTypes collection (which is a NamedTypes object) so that they won't collide in a MT execution environment. * Fix to NamedType.__repr__() to work properly. --- pyasn1/type/namedtype.py | 14 ++++++++------ pyasn1/type/univ.py | 11 +++++------ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'pyasn1') diff --git a/pyasn1/type/namedtype.py b/pyasn1/type/namedtype.py index 48967a5..c1f36f7 100644 --- a/pyasn1/type/namedtype.py +++ b/pyasn1/type/namedtype.py @@ -8,7 +8,7 @@ class NamedType: isDefaulted = 0 def __init__(self, name, t): self.__name = name; self.__type = t - def __repr__(self): return '%s(%s, %s)' % ( + def __repr__(self): return '%s(%s, %r)' % ( self.__class__.__name__, self.__name, self.__type ) def getType(self): return self.__type @@ -33,10 +33,10 @@ class NamedTypes: self.__ambigiousTypes = {} def __repr__(self): - r = '%s(' % self.__class__.__name__ - for n in self.__namedTypes: - r = r + '%r, ' % (n,) - return r + ')' + return '%s(%s)' % ( + self.__class__.__name__, + ', '.join([ repr(x) for x in self.__namedTypes ]) + ) def __getitem__(self, idx): return self.__namedTypes[idx] @@ -45,7 +45,9 @@ class NamedTypes: else: def __bool__(self): return bool(self.__namedTypesLen) def __len__(self): return self.__namedTypesLen - + + def clone(self): return self.__class__(*self.__namedTypes) + def getTypeByPosition(self, idx): if idx < 0 or idx >= self.__namedTypesLen: raise error.PyAsn1Error('Type position out of range') diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py index 9cd16f8..58548b4 100644 --- a/pyasn1/type/univ.py +++ b/pyasn1/type/univ.py @@ -708,13 +708,12 @@ class SequenceAndSetBase(base.AbstractConstructedAsn1Item): componentType = namedtype.NamedTypes() def __init__(self, componentType=None, tagSet=None, subtypeSpec=None, sizeSpec=None): + if componentType is None: + componentType = self.componentType base.AbstractConstructedAsn1Item.__init__( - self, componentType, tagSet, subtypeSpec, sizeSpec - ) - if self._componentType is None: - self._componentTypeLen = 0 - else: - self._componentTypeLen = len(self._componentType) + self, componentType.clone(), tagSet, subtypeSpec, sizeSpec + ) + self._componentTypeLen = len(self._componentType) def __getitem__(self, idx): if isinstance(idx, str): -- cgit v1.2.1