<commit_before># -*- coding: utf-8 -*-
#
# Copyright © 2007  Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2.  This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.  You should have
# received a copy of the GNU General Public License along with this program;
# if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat trademarks that are
# incorporated in the source code or documentation are not subject to the GNU
# General Public License and may only be used or replicated with the express
# permission of Red Hat, Inc.
#
# Author(s): <NAME> <<EMAIL>>
#            <NAME> <<EMAIL>>
#            <NAME> <<EMAIL>>
#

'''
python-fedora, python module to interact with Fedora Infrastructure Services
'''

import ldap
from ldap import modlist
import datetime
from random import Random
import sha
from base64 import b64encode
import sys
    

class AuthError(Exception):
    pass

class Server(object):
    def __init__(self, server=None, who=None, password=None):
        ### FIXME: Before deploy, get the default server, user, and password
        # from the fedora-db-access file.
        server = server or 'localhost'
        who = who or 'cn=directory manager'
        password = password or '<PASSWORD>'

        self.ldapConn = ldap.open(server)
        self.ldapConn.simple_bind_s(who, password)

    def add(self, base, attributes):
        ''' Add a new group record to LDAP instance '''
        attributes=[ (k,v) for k,v in attributes.items() ]
        self.ldapConn.add_s(base, attributes)

    def delete(self, base):
        ''' Delete target base '''
        self.ldapConn.delete_s(base)

    def modify(self, base, attribute, new, old=None):
        ''' Modify an attribute, requires write access '''
        if new in (old, 'None'):
            return None

        #o = { attribute : old }
        #n = { attribute : new }

        ldif = []
        ldif.append((ldap.MOD_DELETE,attribute,None))
        ldif.append((ldap.MOD_ADD,attribute,new))

        #ldif = ldap.modlist.modifyModlist(o, n, ignore_oldexistent=1)
        # commit
        self.ldapConn.modify_s(base, ldif)

    def search(self, base, ldapFilter, attributes=None):
        ''' Basic search function '''
        scope = ldap.SCOPE_SUBTREE
        count = 0
        timeout = 2
        result_set = []
        try:
            result_id = self.ldapConn.search(base, scope, ldapFilter, attributes)
            while True:
                result_type, result_data = self.ldapConn.result(result_id, timeout)
                if (result_data == []):
                    break
                else:
                    if result_type == ldap.RES_SEARCH_ENTRY:
                        result_set.append(result_data)
            if len(result_set) == 0:
                return<commit_msg>Make fasLDAP.py handle None values properly, move encode('utf8') into modify.<commit_after># -*- coding: utf-8 -*-
#
# Copyright © 2007  Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2.  This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.  You should have
# received a copy of the GNU General Public License along with this program;
# if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat trademarks that are
# incorporated in the source code or documentation are not subject to the GNU
# General Public License and may only be used or replicated with the express
# permission of Red Hat, Inc.
#
# Author(s): <NAME> <<EMAIL>>
#            <NAME> <<EMAIL>>
#            <NAME> <<EMAIL>>
#

'''
python-fedora, python module to interact with Fedora Infrastructure Services
'''

import ldap
from ldap import modlist
import datetime
from random import Random
import sha
from base64 import b64encode
import sys
    

class AuthError(Exception):
    pass

class Server(object):
    def __init__(self, server=None, who=None, password=None):
        ### FIXME: Before deploy, get the default server, user, and password
        # from the fedora-db-access file.
        server = server or 'localhost'
        who = who or 'cn=directory manager'
        password = password or '<PASSWORD>'

        self.ldapConn = ldap.open(server)
        self.ldapConn.simple_bind_s(who, password)

    def add(self, base, attributes):
        ''' Add a new group record to LDAP instance '''
        attributes=[ (k,v) for k,v in attributes.items() ]
        self.ldapConn.add_s(base, attributes)

    def delete(self, base):
        ''' Delete target base '''
        self.ldapConn.delete_s(base)

    def modify(self, base, attribute, new, old=None):
        ''' Modify an attribute, requires write access '''
        if new == None:
            return None
        new = str(new).encode('utf8')
        if new == old:
            return None

        #o = { attribute : old }
        #n = { attribute : new }

        ldif = []
        ldif.append((ldap.MOD_DELETE,attribute,None))
        ldif.append((ldap.MOD_ADD,attribute,new))

        #ldif = ldap.modlist.modifyModlist(o, n, ignore_oldexistent=1)
        # commit
        self.ldapConn.modify_s(base, ldif)

    def search(self, base, ldapFilter, attributes=None):
        ''' Basic search function '''
        scope = ldap.SCOPE_SUBTREE
        count = 0
        timeout = 2
        result_set = []
        try:
            result_id = self.ldapConn.search(base, scope, ldapFilter, attributes)
            while True:
                result_type, result_data = self.ldapConn.result(result_id, timeout)
                if (result_data == []):
                    break
                else:
                    if result_type == ldap.RES_SEARCH_ENTRY:
                        result_set.append(result_data)
            if len(result_set) == 0:
                return
{'fraction_non_alphanumeric': 0.09272228989037759, 'fraction_numerical': 0.007917174177831911, 'mean_word_length': 2.552731206057328, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '2820293', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1779, 'n_words': 673}