<commit_before>#! /usr/bin/env python
import sys
sys.path.insert(0, '/data/project/whois/local/lib/python2.7/site-packages')

from ipwhois import IPWhois
import cgitb
import cgi
import json
import os

PROVIDERS = {
    'ARIN': lambda x: 'http://whois.arin.net/rest/ip/' + x,
    'RIPE': lambda x: 'https://apps.db.ripe.net/search/query.html?searchtext=%s#resultsAnchor' % x,
    'AFRINIC': lambda x: 'http://afrinic.net/cgi-bin/whois?searchtext=' + x,
    'APNIC': lambda x: 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' + x,
    'LACNIC': lambda x: 'http://lacnic.net/cgi-bin/lacnic/whois?lg=EN&amp;query=' + x
}

def format_new_lines(s):
    return s.replace('\n', '<br/>')

def format_table(dct, target):
    if isinstance(dct, list):
        return '\n'.join(format_table(x, target) for x in dct)
    ret = '<div class="table-responsive"><table class="table table-condensed"><tbody>'
    for (k,v) in dct.items():
          if v is None or len(v) == 0 or v == 'NA' or v == 'None':
              ret += '<tr class="text-muted"><th>%s</th><td>%s</td></tr>' % (k, v)
          elif isinstance(v, basestring):
              if k == 'asn_registry' and PROVIDERS.has_key(v.upper()):<commit_msg>Add ordering to keys in the results<commit_after>#! /usr/bin/env python
import sys
sys.path.insert(0, '/data/project/whois/local/lib/python2.7/site-packages')

from ipwhois import IPWhois
import cgitb
import cgi
import json
import os

PROVIDERS = {
    'ARIN': lambda x: 'http://whois.arin.net/rest/ip/' + x,
    'RIPE': lambda x: 'https://apps.db.ripe.net/search/query.html?searchtext=%s#resultsAnchor' % x,
    'AFRINIC': lambda x: 'http://afrinic.net/cgi-bin/whois?searchtext=' + x,
    'APNIC': lambda x: 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext=' + x,
    'LACNIC': lambda x: 'http://lacnic.net/cgi-bin/lacnic/whois?lg=EN&amp;query=' + x
}

def order_keys(x):
    keys = dict((y,x) for (x,y) in enumerate([
        'asn_registry', 'asn_country_code', 'asn_date', 'query', 'asn_cidr', 'nets',
        'name', 'description', 'address', 'city', 'state', 'country', 'postal_code',
        'cidr', 'range', 'created', 'updated', 'handle', 'abuse_emails', 'tech_emails', 'misc_emails']))
    if keys.has_key(x):
        return '0_%04d' % keys[x]
    else:
        return '1_%s' % x

def format_new_lines(s):
    return s.replace('\n', '<br/>')

def format_table(dct, target):
    if isinstance(dct, list):
        return '\n'.join(format_table(x, target) for x in dct)
    ret = '<div class="table-responsive"><table class="table table-condensed"><tbody>'
    for (k,v) in sorted(dct.items(), key=lambda x: order_keys(x[0])):
          if v is None or len(v) == 0 or v == 'NA' or v == 'None':
              ret += '<tr class="text-muted"><th>%s</th><td>%s</td></tr>' % (k, v)
          elif isinstance(v, basestring):
              if k == 'asn_registry' and PROVIDERS.has_key(v.upper()):
{'fraction_non_alphanumeric': 0.19613259668508287, 'fraction_numerical': 0.004488950276243094, 'mean_word_length': 3.463790446841294, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '200124', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1107, 'n_words': 242}