summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/dns/rcodes.py
diff options
context:
space:
mode:
Diffstat (limited to 'project2/proj2_s4498062/dns/rcodes.py')
-rw-r--r--project2/proj2_s4498062/dns/rcodes.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/project2/proj2_s4498062/dns/rcodes.py b/project2/proj2_s4498062/dns/rcodes.py
new file mode 100644
index 0000000..4f40621
--- /dev/null
+++ b/project2/proj2_s4498062/dns/rcodes.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python2
+
+""" DNS RCODE values
+
+This module contains an Enum of RCODE values. See section 4.1.4 of RFC 1035 for
+more info.
+"""
+
+
+class RCode(object):
+ """ Enum of RCODE values
+
+ Usage:
+ >>> NoError
+ 0
+ >>> NXDomain
+ 3
+ """
+
+ NoError = 0
+ FormErr = 1
+ ServFail = 2
+ NXDomain = 3
+ NotImp = 4
+ Refused = 5
+ YXDomain = 6
+ YXRRSet = 7
+ NXRRSet = 8
+ NotAuth = 9
+ NotZone = 10
+ BADVERS = 16
+ BADSIG = 16
+ BADKEY = 17
+ BADTIME = 18
+ BADMODE = 19
+ BADNAME = 20
+ BADALG = 21
+ BADTRUNC = 22
+
+ by_string = {
+ "NoError": NoError,
+ "FormErr": FormErr,
+ "ServFail": ServFail,
+ "NXDomain": NXDomain,
+ "NotImp": NotImp,
+ "Refused": Refused,
+ "YXDomain": YXDomain,
+ "YXRRSet": YXRRSet,
+ "NXRRSet": NXRRSet,
+ "NotAuth": NotAuth,
+ "NotZone": NotZone,
+ "BADVERS": BADVERS,
+ "BADSIG": BADSIG,
+ "BADKEY": BADKEY,
+ "BADTIME": BADTIME,
+ "BADMODE": BADMODE,
+ "BADNAME": BADNAME,
+ "BADALG": BADALG,
+ "BADTRUNC": BADTRUNC
+ }
+
+ by_value = dict([(y, x) for x, y in by_string.items()])
+
+ @staticmethod
+ def to_string(rcode):
+ """ Convert an RCode to a string
+
+ Usage:
+ >>> RCode.to_string(RCode.NoError)
+ 'NoError'
+ """
+ return RCode.by_value[rcode]
+
+ @staticmethod
+ def from_string(string):
+ """ Convert a string to an RCode
+
+ Usage:
+ >>> RCode.from_string('NoError')
+ 0
+ """
+ return RCode.by_string[string]