<commit_before>import sys
from lib.bot import *
from lib.utils import *
from lib.event import *
from lib.cache import *
from cymrulib import *

MINIMUM_BGP_PREFIX_IPV4 = 24
MINIMUM_BGP_PREFIX_IPV6 = 128 # FIXME

class CymruExpertBot(Bot):
    
    def init(self):
        self.cache = Cache(
                            self.parameters.cache_host,
                            self.parameters.cache_port,
                            self.parameters.cache_id,
                            self.parameters.cache_ttl
                          )

    
    def process(self):
        event = self.receive_message()
        if event:
            
            for ip in event.values("ip"):
                
                ip, ip_version, ip_integer = is_ip(ip)
                
                if ip:
                    if ip_version == 4:
                        cache_key = bin(ip_integer)[2 : MINIMUM_BGP_PREFIX_IPV4 + 2]
                    else:
                        cache_key = bin(ip_integer)[2 : MINIMUM_BGP_PREFIX_IPV6 + 2]
                    
                    query_result = self.cache.get(cache_key)
                    
                    if not query_result:
                        query_result = Cymru.query(ip, ip_version)
                        self.cache.set(cache_key, query_result)
                        
                    asn, bgp, cc, registry, allocated, as_name = Cymru.parse(query_result)

                    event.clean('cymru asn')
                    event.clear('cymru bgp prefix')
                    event.clear('cymru cc')
                    event.clear('cymru registry')
                    event.clear('cymru allocated')
                    event.clear('cymru as name')

                    event.add('cymru asn', asn)
                    event.add('cymru bgp prefix', bgp)
                    event.add('cymru cc', cc)
                    event.add('cymru registry', registry)
                    event.add('cymru allocated', allocated)
                    event.add('cymru as name', as_name)

                    self.send_message(event)
        self.acknowledge_message()
        
if __name__ == "__main__":
    bot = CymruExpertBot(sys.argv[1])
    bot.start()<commit_msg>Update cymru.py<commit_after>import sys
from lib.bot import *
from lib.utils import *
from lib.event import *
from lib.cache import *
from cymrulib import *

MINIMUM_BGP_PREFIX_IPV4 = 24
MINIMUM_BGP_PREFIX_IPV6 = 128 # FIXME

class CymruExpertBot(Bot):
    
    def init(self):
        self.cache = Cache(
                            self.parameters.cache_host,
                            self.parameters.cache_port,
                            self.parameters.cache_id,
                            self.parameters.cache_ttl
                          )

    
    def process(self):
        event = self.receive_message()
        if event:
            
            for ip in event.values("ip"):
                
                ip, ip_version, ip_integer = is_ip(ip)
                
                if ip:
                    if ip_version == 4:
                        cache_key = bin(ip_integer)[2 : MINIMUM_BGP_PREFIX_IPV4 + 2]
                    else:
                        cache_key = bin(ip_integer)[2 : MINIMUM_BGP_PREFIX_IPV6 + 2]
                    
                    query_result = self.cache.get(cache_key)
                    
                    if not query_result:
                        query_result = Cymru.query(ip, ip_version)
                        self.cache.set(cache_key, query_result)
                        
                    asn, bgp, cc, registry, allocated, as_name = Cymru.parse(query_result)

                    event.clear('cymru asn')
                    event.clear('cymru bgp prefix')
                    event.clear('cymru cc')
                    event.clear('cymru registry')
                    event.clear('cymru allocated')
                    event.clear('cymru as name')

                    event.add('cymru asn', asn)
                    event.add('cymru bgp prefix', bgp)
                    event.add('cymru cc', cc)
                    event.add('cymru registry', registry)
                    event.add('cymru allocated', allocated)
                    event.add('cymru as name', as_name)

                    self.send_message(event)
        self.acknowledge_message()
        
if __name__ == "__main__":
    bot = CymruExpertBot(sys.argv[1])
    bot.start()
{'fraction_non_alphanumeric': 0.083596214511041, 'fraction_numerical': 0.0067598017124831005, 'mean_word_length': 1.2073595226255593, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7035629', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1191, 'n_words': 238}