diff options
Diffstat (limited to 'pyasn1/type/tag.py')
-rw-r--r-- | pyasn1/type/tag.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/pyasn1/type/tag.py b/pyasn1/type/tag.py index 6c0e2c1..d429c18 100644 --- a/pyasn1/type/tag.py +++ b/pyasn1/type/tag.py @@ -2,7 +2,7 @@ # This file is part of pyasn1 software. # # Copyright (c) 2005-2017, Ilya Etingof <etingof@gmail.com> -# License: http://pyasn1.sf.net/license.html +# License: http://snmplabs.com/pyasn1/license.html # from pyasn1 import error @@ -63,13 +63,9 @@ class Tag(object): self.__tagClassId = tagClass, tagId self.__hash = hash(self.__tagClassId) - def __str__(self): - return '[%s:%s:%s]' % (self.__tagClass, self.__tagFormat, self.__tagId) - def __repr__(self): - return '%s(tagClass=%s, tagFormat=%s, tagId=%s)' % ( - (self.__class__.__name__, self.__tagClass, self.__tagFormat, self.__tagId) - ) + representation = '[%s:%s:%s]' % (self.__tagClass, self.__tagFormat, self.__tagId) + return '<%s object at 0x%x tag %s>' % (self.__class__.__name__, id(self), representation) def __eq__(self, other): return self.__tagClassId == other @@ -168,6 +164,23 @@ class TagSet(object): *superTags: :class:`~pyasn1.type.tag.Tag` Additional *Tag* objects taking part in subtyping. + + Examples + -------- + .. code-block:: python + + class OrderNumber(NumericString): + ''' + ASN.1 specification + + Order-number ::= + [APPLICATION 5] IMPLICIT NumericString + ''' + tagSet = NumericString.tagSet.tagImplicitly( + Tag(tagClassApplication, tagFormatSimple, 5) + ) + + orderNumber = OrderNumber('1234') """ def __init__(self, baseTag=(), *superTags): self.__baseTag = baseTag @@ -178,13 +191,15 @@ class TagSet(object): self.__lenOfSuperTags = len(superTags) self.__hash = hash(self.__superTagsClassId) - def __str__(self): - return self.__superTags and '+'.join([str(x) for x in self.__superTags]) or '[untagged]' - def __repr__(self): - return '%s(%s)' % ( - self.__class__.__name__, '(), ' + ', '.join([repr(x) for x in self.__superTags]) - ) + representation = '-'.join(['%s:%s:%s' % (x.tagClass, x.tagFormat, x.tagId) + for x in self.__superTags]) + if representation: + representation = 'tags ' + representation + else: + representation = 'untagged' + + return '<%s object at 0x%x %s>' % (self.__class__.__name__, id(self), representation) def __add__(self, superTag): return self.__class__(self.__baseTag, *self.__superTags + (superTag,)) |