<commit_before># -*- coding: utf-8 -*-

import ldap
import os.path
import subprocess
from subprocess import Popen, check_call
from time import sleep


def get_real_path():
    """
    Get absolute path of this module
    """
    return os.path.realpath(os.path.dirname(__file__))


def get_url_path(path=get_real_path()):
    """
    make path ready for url parameter
    """
    return path.replace('/', '%2F')

def get_default_config_file():
    """
    Get the absolute path to the default slapd.conf
    """
    return os.path.join(get_real_path(), 'slapd.conf')

class LdapServer(object):
    """
    Manager for OpenLDAP testing server
    """
    def __init__(self, port=1381, tls_port=1382, config_file=get_default_config_file(), path=get_real_path()):
        self.server = None
        self.port = port
        self.tls_port = tls_port
        self.config_file = os.path.realpath(config_file)
        self.path = path

    def __del__(self):
        """
        destructor
        """
        self.stop()

    def load_data(self, ldif_file='testdata.ldif'):
        """
        Reset ldap to ldif_file
        """
        check_call(['rm', '-rf', '%s/ldapdata' % self.path])
        check_call(['mkdir', '-p', '%s/ldapdata' % self.path])
        check_call(['slapadd', '-l', os.path.join(self.path, ldif_file), '-f', self.config_file, '-d', '0'],
                stdout = open("/dev/null", "w"), cwd = self.path)

    def ldapi_url(self):
        """
        The ldapi://-URL this LDAP server uses
        """
        return 'ldapi://{0}%2Fldapi'.format(get_url_path(self.path))

    def start(self, clean=True):
        """
        start ldap server
        """
        if clean:
            self.load_data()
        self.server = Popen(['slapd', '-f', self.config_file, '-h', self.ldapi_url(), '-d', '0'],
             cwd = self.path,
             )
        # Busy wait until LDAP is ready
        tries = 0
        while tries < 100:
            tries += 1
            try:
                connection = ldap.initialize(self.ldapi_url())
                connection.simple_bind_s('cn=admin,dc=example,dc=com', 'admin')
                break
            except ldap.SERVER_DOWN:
                sleep(0.05)
        return

    def stop(self):
        """
        stop ldap server
        """
        if self.server:
            self.server.terminate()
        self.server = None

    def restart(self):
        """
        restart ldapserver without clearing the server
        """
        self.stop()
        self.start(clean=False)

<commit_msg>change documentation style to doxygen in openldap/__init__.py<commit_after># -*- coding: utf-8 -*-

import ldap
import os.path
import subprocess
from subprocess import Popen, check_call
from time import sleep


## Get absolute path of this module
def get_real_path():
    return os.path.realpath(os.path.dirname(__file__))


## make path ready for url parameter
def get_url_path(path=get_real_path()):
    return path.replace('/', '%2F')

## Get the absolute path to the default slapd.conf
def get_default_config_file():
    return os.path.join(get_real_path(), 'slapd.conf')


## Manager for OpenLDAP testing server
class LdapServer(object):
    def __init__(self, port=1381, tls_port=1382, config_file=get_default_config_file(), path=get_real_path()):
        self.server = None
        self.port = port
        self.tls_port = tls_port
        self.config_file = os.path.realpath(config_file)
        self.path = path

    ## destructor
    def __del__(self):
        self.stop()

    ## Reset ldap to ldif_file
    def load_data(self, ldif_file='testdata.ldif'):
        check_call(['rm', '-rf', '%s/ldapdata' % self.path])
        check_call(['mkdir', '-p', '%s/ldapdata' % self.path])
        check_call(['slapadd', '-l', os.path.join(self.path, ldif_file), '-f', self.config_file, '-d', '0'],
                stdout = open("/dev/null", "w"), cwd = self.path)

    ## The ldapi://-URL this LDAP server uses
    def ldapi_url(self):
        return 'ldapi://{0}%2Fldapi'.format(get_url_path(self.path))

    ## start ldap server
    def start(self, clean=True):
        if clean:
            self.load_data()
        self.server = Popen(['slapd', '-f', self.config_file, '-h', self.ldapi_url(), '-d', '0'],
             cwd = self.path,
             )
        # Busy wait until LDAP is ready
        tries = 0
        while tries < 100:
            tries += 1
            try:
                connection = ldap.initialize(self.ldapi_url())
                connection.simple_bind_s('cn=admin,dc=example,dc=com', 'admin')
                break
            except ldap.SERVER_DOWN:
                sleep(0.05)
        return

    ## stop ldap server
    def stop(self):
        if self.server:
            self.server.terminate()
        self.server = None

    ## restart ldapserver without clearing the server
    def restart(self):
        self.stop()
        self.start(clean=False)


{'fraction_non_alphanumeric': 0.13583990297149787, 'fraction_numerical': 0.008894279361229027, 'mean_word_length': 2.1963824289405687, 'pattern_counts': {'":': 0, '<': 5, '<?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': '727873', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1552, 'n_words': 364}