<commit_before>#!/usr/bin/env python
#
# (C) Copyright 2014 <NAME> aka neoCrimeLabs ( http://neocri.me/ )
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Lesser General Public License
# (LGPL) version 2.1 which accompanies this distribution, and is available at
# http://www.gnu.org/licenses/lgpl-2.1.html
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# Contributors:
#     <NAME> aka neoCrimeLabs ( http://neocri.me/ )


# Note:  This work is strongly based on the works of others found on various forums
# I took what worked, fixed what didn't, then rewrote as an installable module

import ldap
from   ldap.controls import SimplePagedResultsControl

class


class LdapPagedSearch( object ):


    def __init__( self, url , username, password, pageSize = 1000, maxPages = 0 ):
        ldap.set_option( ldap.OPT_REFERRALS, 0 )

        self.username               = username
        self.password               = password
        self.pageSize               = pageSize
        self.maxPages               = maxPages
        self.ldap                   = ldap.initialize( url )
        self.ldap.protocol_version  = ldap.VERSION3
        self.pageType               = SimplePagedResultsControl.controlType
        self.responseCodes          = { self.pageType: SimplePagedResultsControl, }
        self.connected              = False
        self.directSearch           = False


    def __enter__(self):
        self.ldap.bind_s( self.username, self.password )
        self.connected = True
        return self


    def __exit__(self, type, value, traceback):
        self.ldap.unbind_s()
        self.connected = False


    def _getPageCookie( self, serverControls ):
        cookie = None

        for control in serverControls:
            if control.controlType == self.pageType:
                cookie = control.cookie
                break
        return cookie


    def _setPageControl( self, cookie = '' ):
        return SimplePagedResultsControl( True, self.pageSize, cookie = cookie )


    def _handleResults(self, data, callback):
        results = []<commit_msg>initial commit<commit_after>#!/usr/bin/env python
#
# (C) Copyright 2014 <NAME> aka neoCrimeLabs ( http://neocri.me/ )
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Lesser General Public License
# (LGPL) version 2.1 which accompanies this distribution, and is available at
# http://www.gnu.org/licenses/lgpl-2.1.html
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# Contributors:
#     <NAME> aka neoCrimeLabs ( http://neocri.me/ )


# Note:  This work is strongly based on the works of others found on various forums
# I took what worked, fixed what didn't, then rewrote as an installable module

import ldap
from   ldap.controls import SimplePagedResultsControl


class LdapPagedSearch( object ):


    def __init__( self, url , username, password, pageSize = 1000, maxPages = 0 ):
        ldap.set_option( ldap.OPT_REFERRALS, 0 )

        self.username               = username
        self.password               = password
        self.pageSize               = pageSize
        self.maxPages               = maxPages
        self.ldap                   = ldap.initialize( url )
        self.ldap.protocol_version  = ldap.VERSION3
        self.pageType               = SimplePagedResultsControl.controlType
        self.responseCodes          = { self.pageType: SimplePagedResultsControl, }
        self.connected              = False
        self.directSearch           = False


    def __enter__( self ):
        if self.connected is False:
            self.ldap.bind_s( self.username, self.password )
            self.connected = True
        return self


    def __exit__( self, type, value, traceback ):
        if self.connected is True:
            self.connected = False
            self.ldap.unbind_s()


    def _getPageCookie( self, serverControls ):
        cookie = None

        for control in serverControls:
            if control.controlType == self.pageType:
                cookie = control.cookie
                break
        return cookie


    def _setPageControl( self, cookie = '' ):
        return SimplePagedResultsControl( True, self.pageSize, cookie = cookie )


    def _handleResults(self, data, callback):
        results = []
{'fraction_non_alphanumeric': 0.07466110531803963, 'fraction_numerical': 0.006256517205422315, 'mean_word_length': 2.3121546961325965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '335330', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1238, 'n_words': 430}