def normalize(self, hostname): if not is_hostname(hostname): raise ObservableValidationError("Invalid Hostname (is_hostname={}): {}".format(is_hostname(hostname), hostname)) if hostname.endswith('.'): hostname = hostname[:-1] self.idna = unicode(idna.encode(hostname.lower())) self.value = unicode(idna.decode(hostname.lower()))
def guess_type(string): from core.observables import Url, Ip, Hostname if string and string.strip() != '': if is_url(string): return Url elif is_ip(string): return Ip elif is_hostname(string): return Hostname else: raise ObservableValidationError("{} was not recognized as a viable datatype".format(string))