Ejemplo n.º 1
0
def type_and_magnitude(initial):
    """return string matching type and magnitude

    If initial looks like an integer, return string form of integer of
    same magnitude.  Same idea for floating point values.  Otherwise
    return a random short_string.

    """
    if initial is None or len(initial) == 0:
        return initial
    try:
        value = int(initial)
        return anon_term(initial, fixed_length_digits(len(initial)))
    except ValueError:
        try:
            value = float(initial)
            lenb4 = initial.find('.')
            return anon_term(initial, fixed_length_digits(len(initial),
                                                          (lenb4, lenb4+1)))
        except ValueError:
            return short_string(initial)
Ejemplo n.º 2
0
def test_invalid_pointfrequency():
    fixed_length_digits(1024, (1, 'end'))
Ejemplo n.º 3
0
def test_nodot_func():
    "no dots works too"
    nodot_func = fixed_length_digits(1024)
    result = nodot_func('whee')
    assert(len(result) == 1024)
    assert(result.count('.') == 0)
Ejemplo n.º 4
0
def test_dotted_func():
    "long list of digits with lots of dots"
    dotted_func = fixed_length_digits(1024, (1, 16))
    result = dotted_func('meaningless input')
    assert(len(result) == 1024)
    assert(result.count('.') > 1024 / 16)
Ejemplo n.º 5
0
        segment = self.segment_key(key)
        if segment:
            return dict.__contains__(self, segment)

        segment, element, component = self.assert_triplekey(key)
        if dict.__contains__(self, segment):
            d = dict.__getitem__(self, segment)
            return element in d and component in d[element]
        return False


config = Config()
days = config.get("anonymize", "dayshift")

"""Define functions with parameters needed to anonymize fields"""
dotted_sequence = fixed_length_digits(30, (1, 7))
short_string = fixed_length_string(10)
site_string = fixed_length_string(12, prefix="Site ")
yyyymm = random_date_delta(datetime.timedelta(days=days), "%Y%m")
ymdhms = random_date_delta(datetime.timedelta(days=days), "%Y%m%d%H%M%S")
two_digits = fixed_length_digits(2)
five_digits = fixed_length_digits(5)
six_digits = fixed_length_digits(6)
nine_digits = fixed_length_digits(9)
ten_digits = fixed_length_digits(10)

def ten_digits_starting_w_1(initial):
    """specialized anon function for NPI like numbers

    10 digits in length, starting w/ 1 to prevent integer overflow at
    2,147,483,647