From 872e11deb29e87eddcfaca76d555acc16e329653 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 14 Apr 2016 20:07:12 +0200 Subject: Added project2 framework --- project2/proj2_s4498062/dns/classes.py | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 project2/proj2_s4498062/dns/classes.py (limited to 'project2/proj2_s4498062/dns/classes.py') diff --git a/project2/proj2_s4498062/dns/classes.py b/project2/proj2_s4498062/dns/classes.py new file mode 100644 index 0000000..aeb1da7 --- /dev/null +++ b/project2/proj2_s4498062/dns/classes.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python2 + +""" 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 + """ + + 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_): + return Class.by_value[class_] + + @staticmethod + def from_string(string): + return Class.by_string[string] -- cgit v1.2.3