def test_bad_option_length(self): with self.assertRaisesRegex(ValueError, 'must end with a 0-length label'): DomainSearchListOption.parse( bytes.fromhex('0018000c') + b'\x08steffann\x02nl\x00') with self.assertRaisesRegex(ValueError, 'exceeds available buffer'): DomainSearchListOption.parse( bytes.fromhex('0018000e') + b'\x08steffann\x02nl\x00\x01')
def combine( self, existing_options: Iterable[DomainSearchListOption] ) -> DomainSearchListOption: """ Combine multiple options into one. :param existing_options: The existing options to include domain names from :return: The combined option """ domains = [] # Add from existing options first for option in existing_options: for domain in option.search_list: if domain not in domains: domains.append(domain) # Then add our own for domain in self.option.dns_servers: if domain not in domains: domains.append(domain) # And return a new option with the combined addresses return DomainSearchListOption(search_list=domains)
def test_bad_option_length(self): with self.assertRaisesRegex(ValueError, 'must end with a 0-length label'): DomainSearchListOption.parse(bytes.fromhex('0018000c') + b'\x08steffann\x02nl\x00') with self.assertRaisesRegex(ValueError, 'exceeds available buffer'): DomainSearchListOption.parse(bytes.fromhex('0018000e') + b'\x08steffann\x02nl\x00\x01')
def __init__(self, search_list: [str]): option = DomainSearchListOption(search_list=search_list) option.validate() super().__init__(option)
def setUp(self): self.option_bytes = bytes.fromhex( '0018000d') + b'\x08steffann\x02nl\x00' self.option_object = DomainSearchListOption( search_list=['steffann.nl']) self.parse_option()
def __init__(self, search_list: Iterable[str], always_send: bool = False): option = DomainSearchListOption(search_list=search_list) option.validate() super().__init__(option, always_send=always_send)