Ejemplo n.º 1
0
    def export(self) -> Dict[str, int]:
        """
        Export the counters

        :return: The counters in a processable format
        """
        out = OrderedDict()
        out['incoming_packets'] = self.incoming_packets.value
        out['outgoing_packets'] = self.outgoing_packets.value
        out['unparsable_packets'] = self.unparsable_packets.value
        out['handling_errors'] = self.handling_errors.value
        out['for_other_server'] = self.for_other_server.value
        out['do_not_respond'] = self.do_not_respond.value
        out['use_multicast'] = self.use_multicast.value

        out['messages_in'] = OrderedDict()
        for message_type, counter in self.messages_in.items():
            message_type_name = message_registry[message_type].__name__
            message_type_name = camelcase_to_underscore(message_type_name)
            if message_type_name.endswith('_message'):
                message_type_name = message_type_name[:-8]
            out['messages_in'][message_type_name] = counter.value

        out['messages_out'] = OrderedDict()
        for message_type, counter in self.messages_out.items():
            message_type_name = message_registry[message_type].__name__
            message_type_name = camelcase_to_underscore(message_type_name)
            if message_type_name.endswith('_message'):
                message_type_name = message_type_name[:-8]
            out['messages_out'][message_type_name] = counter.value

        return out
Ejemplo n.º 2
0
 def test_camelcase_to_underscore(self):
     self.assertEqual(camelcase_to_underscore('CamelCase'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('CamelCASE'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('CAMELCase'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('MyCAMELCase'), 'my_camel_case')
     self.assertEqual(camelcase_to_underscore('Camel123Case'), 'camel123_case')
     self.assertEqual(camelcase_to_underscore('CAMEL123Case'), 'camel123_case')
     self.assertEqual(camelcase_to_underscore('Camel-Case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('camel-case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('Camel_Case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('camel_case'), 'camel_case')
Ejemplo n.º 3
0
    def export(self) -> Dict[str, int]:
        """
        Export the counters

        :return: The counters in a processable format
        """
        out = OrderedDict()
        out['incoming_packets'] = self.incoming_packets.value
        out['outgoing_packets'] = self.outgoing_packets.value
        out['unparsable_packets'] = self.unparsable_packets.value
        out['handling_errors'] = self.handling_errors.value
        out['for_other_server'] = self.for_other_server.value
        out['do_not_respond'] = self.do_not_respond.value
        out['use_multicast'] = self.use_multicast.value
        out['unknown_query_type'] = self.unknown_query_type.value
        out['malformed_query'] = self.malformed_query.value
        out['not_allowed'] = self.not_allowed.value
        out['other_error'] = self.other_error.value

        out['messages_in'] = OrderedDict()
        for message_type, counter in self.messages_in.items():
            message_type_name = message_registry[message_type].__name__
            message_type_name = camelcase_to_underscore(message_type_name)
            if message_type_name.endswith('_message'):
                message_type_name = message_type_name[:-8]
            out['messages_in'][message_type_name] = counter.value

        out['messages_out'] = OrderedDict()
        for message_type, counter in self.messages_out.items():
            message_type_name = message_registry[message_type].__name__
            message_type_name = camelcase_to_underscore(message_type_name)
            if message_type_name.endswith('_message'):
                message_type_name = message_type_name[:-8]
            out['messages_out'][message_type_name] = counter.value

        return out
Ejemplo n.º 4
0
 def test_camelcase_to_underscore(self):
     self.assertEqual(camelcase_to_underscore('CamelCase'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('CamelCASE'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('CAMELCase'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('MyCAMELCase'),
                      'my_camel_case')
     self.assertEqual(camelcase_to_underscore('Camel123Case'),
                      'camel123_case')
     self.assertEqual(camelcase_to_underscore('CAMEL123Case'),
                      'camel123_case')
     self.assertEqual(camelcase_to_underscore('Camel-Case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('camel-case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('Camel_Case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('camel_case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('SimpleCamelCase'),
                      'simple_camel_case')
     self.assertEqual(camelcase_to_underscore('DHCPTest'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP-Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP--Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP_Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP__Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP-_Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP_-Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCPv6Test'), 'dhc_pv6_test')
     self.assertEqual(camelcase_to_underscore('DHCPV6Test'), 'dhcpv6_test')
     self.assertEqual(camelcase_to_underscore('DHCPVersion6plusTest'),
                      'dhcp_version6plus_test')
Ejemplo n.º 5
0
 def test_camelcase_to_underscore(self):
     self.assertEqual(camelcase_to_underscore('CamelCase'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('CamelCASE'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('CAMELCase'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('MyCAMELCase'), 'my_camel_case')
     self.assertEqual(camelcase_to_underscore('Camel123Case'), 'camel123_case')
     self.assertEqual(camelcase_to_underscore('CAMEL123Case'), 'camel123_case')
     self.assertEqual(camelcase_to_underscore('Camel-Case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('camel-case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('Camel_Case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('camel_case'), 'camel_case')
     self.assertEqual(camelcase_to_underscore('SimpleCamelCase'), 'simple_camel_case')
     self.assertEqual(camelcase_to_underscore('DHCPTest'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP-Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP--Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP_Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP__Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP-_Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCP_-Test'), 'dhcp_test')
     self.assertEqual(camelcase_to_underscore('DHCPv6Test'), 'dhc_pv6_test')
     self.assertEqual(camelcase_to_underscore('DHCPV6Test'), 'dhcpv6_test')
     self.assertEqual(camelcase_to_underscore('DHCPVersion6plusTest'), 'dhcp_version6plus_test')