diff options
| author | Arthur Gautier <baloo@gandi.net> | 2016-03-29 17:51:13 +0000 |
|---|---|---|
| committer | Arthur Gautier <baloo@gandi.net> | 2016-04-21 15:33:05 +0000 |
| commit | 5f59c1f3071e2ba6aad4f163ec7884ca8e4f1cc4 (patch) | |
| tree | 3d4d523604f965db8e4ebea3d24d1aad24c41415 /dns/flags.py | |
| parent | c1a2e4585a1404ee0cfaa6d2d2ad072e8807ef3e (diff) | |
| download | dnspython-5f59c1f3071e2ba6aad4f163ec7884ca8e4f1cc4.tar.gz | |
python3 support
Signed-off-by: Arthur Gautier <baloo@gandi.net>
Diffstat (limited to 'dns/flags.py')
| -rw-r--r-- | dns/flags.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/dns/flags.py b/dns/flags.py index 35a8305..388d6aa 100644 --- a/dns/flags.py +++ b/dns/flags.py @@ -30,17 +30,17 @@ CD = 0x0010 DO = 0x8000 _by_text = { - 'QR' : QR, - 'AA' : AA, - 'TC' : TC, - 'RD' : RD, - 'RA' : RA, - 'AD' : AD, - 'CD' : CD + 'QR': QR, + 'AA': AA, + 'TC': TC, + 'RD': RD, + 'RA': RA, + 'AD': AD, + 'CD': CD } _edns_by_text = { - 'DO' : DO + 'DO': DO } @@ -48,12 +48,13 @@ _edns_by_text = { # cannot make any mistakes (e.g. omissions, cut-and-paste errors) that # would cause the mappings not to be true inverses. -_by_value = dict([(y, x) for x, y in _by_text.iteritems()]) +_by_value = dict((y, x) for x, y in _by_text.items()) + +_edns_by_value = dict((y, x) for x, y in _edns_by_text.items()) -_edns_by_value = dict([(y, x) for x, y in _edns_by_text.iteritems()]) def _order_flags(table): - order = list(table.iteritems()) + order = list(table.items()) order.sort() order.reverse() return order @@ -62,6 +63,7 @@ _flags_order = _order_flags(_by_value) _edns_flags_order = _order_flags(_edns_by_value) + def _from_text(text, table): flags = 0 tokens = text.split() @@ -69,6 +71,7 @@ def _from_text(text, table): flags = flags | table[t.upper()] return flags + def _to_text(flags, table, order): text_flags = [] for k, v in order: @@ -76,6 +79,7 @@ def _to_text(flags, table, order): text_flags.append(v) return ' '.join(text_flags) + def from_text(text): """Convert a space-separated list of flag text values into a flags value. @@ -83,13 +87,14 @@ def from_text(text): return _from_text(text, _by_text) + def to_text(flags): """Convert a flags value into a space-separated list of flag text values. @rtype: string""" return _to_text(flags, _by_value, _flags_order) - + def edns_from_text(text): """Convert a space-separated list of EDNS flag text values into a EDNS @@ -98,6 +103,7 @@ def edns_from_text(text): return _from_text(text, _edns_by_text) + def edns_to_text(flags): """Convert an EDNS flags value into a space-separated list of EDNS flag text values. |
