Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Enum with Tag for pretty repr #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Julien00859
Copy link

@Julien00859 Julien00859 commented Dec 21, 2024

Hello there! First time contributing. I've tried to follow the contributing steps but couldn't make tox detect my pyenv config. I manually tested 2.7 and 3.10.

I was playing around with an interactive python and some x509 certificate, but I had to refer to the documentation every time I peeked at the next tag because I never remember the enumeration values.

So this PR makes printing a Tag prints the value from the enums, instead of some obscure integer:

Tag(nr=<Numbers.BitString: 0x03>, typ=<Types.Primitive: 0x00>, cls=<Classes.Universal: 0x00>)

Instead of

Tag(nr=3, typ=0, cls=0)

Note that in case of a non-universal class, it keeps the nr as as integer. If I understood it correctly, non-universal class are for user-defined types, so nr=1 isn't always a Numbers.Boolean right?


I've tried different approach before settling on the one proposed here. Another of my attemps was to try and change the namedtuple for a collections.abc.Sequence to get control on the __init__ and __repr__. The code turned out too complicated due to the py2-compat.


By the way, running the tox tests on the master branch yields some errors.

flake8 complains about the unused from numbers import Number import. sphinx complains that the https://tox.wiki/en/latest/install.html url is not found (HTTP 404). sphinx autodoc complains that the docstrings of asn1.Encoder.construct is broken.

@andrivet
Copy link
Owner

Thank you for the PR. I will look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants