<commit_before>import atexit, os, re, sys
import ctypes
from ctypes.util import find_library

import ctypes
import math

class RTreeError(Exception):
    "RTree exception, indicates a RTree-related error."
    pass
    
if os.name == 'nt':
    lib_name = 'libmgrs.dll'
    try:
        local_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
        original_path = os.environ['PATH']
        os.environ['PATH'] = "%s;%s" % (local_dlls, original_path)
        rt = ctypes.PyDLL(lib_name)
        def free(m):
            try:
                free = ctypes.cdll.msvcrt.free(m)
            except WindowsError:
                pass
    except (ImportError, WindowsError):
        raise
elif os.name == 'posix':
    platform = os.uname()[0]
    lib_name = 'libmgrs.so'
    local_library_path = os.path.abspath(os.path.dirname(__file__) + "/..")
    if platform == 'Darwin':
        free = ctypes.CDLL(find_library('libc')).free
    else:
        free = ctypes.CDLL(find_library('libc.so.6')).free
    rt = ctypes.CDLL(os.path.join(local_library_path, lib_name))
else:
    raise RTreeError('Unsupported OS "%s"' % os.name)

errors = {  0x0001: "Latitude Error",
            0x0002: "Longitude Error",
            0x0004: "String Error",
            0x0008: "Precision Error",
            0x0010: "Axis Error",
            0x0020: "Inverse Flattening Error",
            0x0040: "Easting Error",
            0x0080: "Northing Error",
            0x0100: "Zone Error",
            0x0200: "Hemisphere Error"
         }

def get_errors(value):
    output = 'MGRS Errors: '
    for key in errors.keys():
        if key & value:
            output += errors[key] + " & "
    return output[:-2]
    
def TO_RADIANS(degrees):
    return (float(degrees) * math.pi/180.0)

def TO_DEGREES(radians):
    return (float(radians) * 180.0/math.pi)
<commit_msg>Simplifying libc loads on Linux and Mac.<commit_after>import atexit, os, re, sys
import ctypes
from ctypes.util import find_library

import ctypes
import math

class RTreeError(Exception):
    "RTree exception, indicates a RTree-related error."
    pass
    
if os.name == 'nt':
    lib_name = 'libmgrs.dll'
    try:
        local_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
        original_path = os.environ['PATH']
        os.environ['PATH'] = "%s;%s" % (local_dlls, original_path)
        rt = ctypes.PyDLL(lib_name)
        def free(m):
            try:
                free = ctypes.cdll.msvcrt.free(m)
            except WindowsError:
                pass
    except (ImportError, WindowsError):
        raise
elif os.name == 'posix':
    platform = os.uname()[0]
    lib_name = 'libmgrs.so'
    local_library_path = os.path.abspath(os.path.dirname(__file__) + "/..")
    free = ctypes.CDLL(find_library('c')).free
    rt = ctypes.CDLL(os.path.join(local_library_path, lib_name))
else:
    raise RTreeError('Unsupported OS "%s"' % os.name)

errors = {  0x0001: "Latitude Error",
            0x0002: "Longitude Error",
            0x0004: "String Error",
            0x0008: "Precision Error",
            0x0010: "Axis Error",
            0x0020: "Inverse Flattening Error",
            0x0040: "Easting Error",
            0x0080: "Northing Error",
            0x0100: "Zone Error",
            0x0200: "Hemisphere Error"
         }

def get_errors(value):
    output = 'MGRS Errors: '
    for key in errors.keys():
        if key & value:
            output += errors[key] + " & "
    return output[:-2]
    
def TO_RADIANS(degrees):
    return (float(degrees) * math.pi/180.0)

def TO_DEGREES(radians):
    return (float(radians) * 180.0/math.pi)

{'fraction_non_alphanumeric': 0.13344407530454042, 'fraction_numerical': 0.03349944629014397, 'mean_word_length': 2.2845454545454547, 'pattern_counts': {'":': 0, '<': 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': '706135', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1229, 'n_words': 274}