Skip to content

WIP: Convert constants to enums#473

Merged
rthalley merged 6 commits intorthalley:masterfrom
bwelling:enum
May 19, 2020
Merged

WIP: Convert constants to enums#473
rthalley merged 6 commits intorthalley:masterfrom
bwelling:enum

Conversation

@bwelling
Copy link
Copy Markdown
Collaborator

Create RdataType and RdataClass enums, and change the constants in the dns.rdatatype and rdataclass modules to use them.

In rdataclass, remove _by_text and _by_value, and just use the enum methods directly. In rdatatype, this doesn't completely work, because of type registration and the inconveniently named NSAP-PTR type, so keep the existing arrays that mostly duplicate the enum mapping for now.

Add to_enum methods to both, which take either an int or a string, and convert to an enumerated value, if possible (that is, if the type or class is known).

Change existing callers that support both int or str to use to_enum, and also add this to other places, like dns.rdata.from_wire and dns.rdata.from_text. This doesn't touch the dns.resolver or dns.trio.resolver calls, to avoid conflicts.

Marking this as WIP, since while the tests pass, there could still be something missing. Also, it might be possible to remove the duplicate arrays from rdatatype, or do other things in better ways.

bwelling added 4 commits May 18, 2020 10:25
The flags are defined in dnskeybase, and additionally visible in DNSKEY
and CDNSKEY.

Also, remove flags_to_text_set() and flags_from_text_set().  The
DNSKEY record doesn't support text flags; this was leftover from
the KEY record.

Remove tests that are no longer needed, and update other tests for these
changes.
@bwelling bwelling changed the title WIP: Convert rdatatype/rdataclass to enum. WIP: Convert constants to enums May 18, 2020
bwelling added 2 commits May 18, 2020 14:07
Add more checking to dns.rdata.register_type, to ensure that an existing
type mnemonic isn't overwritten.  Use the enum functionality for mapping
names to values and values to names, rather than duplicating it.
@rthalley rthalley merged commit 32ef3f3 into rthalley:master May 19, 2020
@pspacek
Copy link
Copy Markdown
Collaborator

pspacek commented May 20, 2020

❤️ Thanks!

nrhall pushed a commit to nrhall/dnspython that referenced this pull request Jun 23, 2020
WIP: Convert constants to enums
@JasonCoombs
Copy link
Copy Markdown

In rdataclass, remove _by_text and _by_value, and just use the enum methods directly.

this causes doh to fail when dnspython version == 2.0

https://github.com/opendns/doh-client

@bwelling
Copy link
Copy Markdown
Collaborator Author

The doh-client software is relying on a private method, which is an inherently unsafe thing to do. The fact that it stopped working when a private method was changed is a problem with doh-client, not dnspython.

JasonCoombs pushed a commit to JasonCoombs/doh-client that referenced this pull request Aug 27, 2020
Not meant to be a comprehensive update. This edit has been unit tested only once, and not exhaustively. At first glance this appears to work.

See also: rthalley/dnspython#473 (comment)
@JasonCoombs
Copy link
Copy Markdown

Agree. The proposed PR to fix this problem is here, for anyone else who wants doh-client to work with dnspython version 2.0

opendns/doh-client#1

aramg pushed a commit to opendns/doh-client that referenced this pull request Oct 26, 2020
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.

4 participants