summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/dns/classes.py
diff options
context:
space:
mode:
Diffstat (limited to 'project2/proj2_s4498062/dns/classes.py')
-rw-r--r--project2/proj2_s4498062/dns/classes.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/project2/proj2_s4498062/dns/classes.py b/project2/proj2_s4498062/dns/classes.py
new file mode 100644
index 0000000..b6123cd
--- /dev/null
+++ b/project2/proj2_s4498062/dns/classes.py
@@ -0,0 +1,54 @@
+""" DNS CLASS and QCLASS values
+
+This module contains an Enum of CLASS and QCLASS values. The Enum also contains
+a method for converting values to strings. See sections 3.2.4 and 3.2.5 of RFC
+1035 for more information.
+"""
+
+
+class Class(object):
+ """ Enum of CLASS and QCLASS values
+
+ Usage:
+ >>> Class.IN
+ 1
+ >>> Class.ANY
+ 255
+ """
+
+ # pylint: disable=invalid-name
+ IN = 1
+ CS = 2
+ CH = 3
+ HS = 4
+ ANY = 255
+
+ by_string = {
+ "IN": IN,
+ "CS": CS,
+ "CH": CH,
+ "HS": HS,
+ "*": ANY
+ }
+
+ by_value = dict([(y, x) for x, y in by_string.items()])
+
+ @staticmethod
+ def to_string(class_):
+ """ Convert a Class to a string
+
+ Usage:
+ >>> Class.to_string(Class.IN)
+ 'IN'
+ """
+ return Class.by_value[class_]
+
+ @staticmethod
+ def from_string(string):
+ """ Convert a string to a Class
+
+ Usage:
+ >>> Class.from_string('IN')
+ 1
+ """
+ return Class.by_string[string]