<commit_before># -*- coding: utf-8 ; test-case-name: bridgedb.test.test_Dist -*-
#
# This file is part of BridgeDB, a Tor bridge distribution system.
#
# :authors: <NAME>
#           <NAME> 0xA3ADB67A2CDB8B35 <<EMAIL>>
#           <NAME> 0x017DD169EA793BE2 <<EMAIL>>
# :copyright: (c) 2013-2014, Isis Lovecruft
#             (c) 2013-2014, <NAME>
#             (c) 2007-2014, The Tor Project, Inc.
# :license: 3-Clause BSD, see LICENSE for licensing information

"""This module has functions to decide which bridges to hand out to whom."""

import bridgedb.Bridges
import bridgedb.Storage
import bridgedb.util as util

import logging
import re
import time
from ipaddr import IPv6Address, IPAddress

from bridgedb.crypto import getHMAC
from bridgedb.crypto import getHMACFunc
from bridgedb.Filters import filterAssignBridgesToRing
from bridgedb.Filters import filterBridgesByRules
from bridgedb.Filters import filterBridgesByIP4
from bridgedb.Filters import filterBridgesByIP6


def uniformMap(ip):
    """Map an IP to an arbitrary 'area' string, such that any two /24 addresses
    get the same string.

    >>> from bridgedb import Dist
    >>> Dist.uniformMap('1.2.3.4')
    '1.2.3'

    :param str ip: A string representing an IPv4 or IPv6 address.
    """
    if type(IPAddress(ip)) is IPv6Address:
        return ":".join(IPv6Address(ip).exploded.split(':')[:4])
    else:
        return ".".join(ip.split(".")[:3])

def getNumBridgesPerAnswer(ring, max_bridges_per_answer=3):
    if len(ring) < 20:
        n_bridges_per_answer = 1
    if 20 <= len(ring) < 100:
        n_bridges_per_answer = min(2, max_bridges_per_answer)
    if len(ring) >= 100:
        n_bridges_per_answer = max_bridges_per_answer
<commit_msg>PEP8 reorder import statements in Dist.<commit_after># -*- coding: utf-8 ; test-case-name: bridgedb.test.test_Dist -*-
#
# This file is part of BridgeDB, a Tor bridge distribution system.
#
# :authors: <NAME>
#           <NAME> 0xA3ADB67A2CDB8B35 <<EMAIL>>
#           <NAME> 0x017DD169EA793BE2 <<EMAIL>>
# :copyright: (c) 2013-2014, Isis Lovecruft
#             (c) 2013-2014, <NAME>
#             (c) 2007-2014, The Tor Project, Inc.
# :license: 3-Clause BSD, see LICENSE for licensing information

"""This module has functions to decide which bridges to hand out to whom."""

import logging
import re
import time

from ipaddr import IPv6Address
from ipaddr import IPAddress

import bridgedb.Bridges
import bridgedb.Storage

from bridgedb import util
from bridgedb.crypto import getHMAC
from bridgedb.crypto import getHMACFunc
from bridgedb.Filters import filterAssignBridgesToRing
from bridgedb.Filters import filterBridgesByRules
from bridgedb.Filters import filterBridgesByIP4
from bridgedb.Filters import filterBridgesByIP6


def uniformMap(ip):
    """Map an IP to an arbitrary 'area' string, such that any two /24 addresses
    get the same string.

    >>> from bridgedb import Dist
    >>> Dist.uniformMap('1.2.3.4')
    '1.2.3'

    :param str ip: A string representing an IPv4 or IPv6 address.
    """
    if type(IPAddress(ip)) is IPv6Address:
        return ":".join(IPv6Address(ip).exploded.split(':')[:4])
    else:
        return ".".join(ip.split(".")[:3])

def getNumBridgesPerAnswer(ring, max_bridges_per_answer=3):
    if len(ring) < 20:
        n_bridges_per_answer = 1
    if 20 <= len(ring) < 100:
        n_bridges_per_answer = min(2, max_bridges_per_answer)
    if len(ring) >= 100:
        n_bridges_per_answer = max_bridges_per_answer

{'fraction_non_alphanumeric': 0.10591274397244546, 'fraction_numerical': 0.0439150401836969, 'mean_word_length': 3.60978835978836, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5354874', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1153, 'n_words': 344}