How to use the ldap3.utils.ciDict.CaseInsensitiveDict function in ldap3

To help you get started, we’ve selected a few ldap3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cannatag / ldap3 / test / testCaseInsensitiveDictionary.py View on Github external
def test_modify_value_in_case_insentitive_dict_different_case_key(self):
        cid = CaseInsensitiveDict()
        cid['oNe'] = 1
        cid['tWo'] = 2
        cid[3] = 3
        self.assertEqual(cid['ONE'], 1)
        self.assertEqual(cid['oNe'], 1)
        cid['one'] = 'ONE'
        self.assertEqual(cid['ONE'], 'ONE')
        self.assertEqual(cid['oNe'], 'ONE')
        self.assertEqual(cid['TWO'], 2)
        self.assertEqual(cid['two'], 2)
        self.assertEqual(cid[3], 3)
github cannatag / ldap3 / test / testCaseInsensitiveDictionary.py View on Github external
def test_add_values_to_case_insentitive_dict(self):
        cid = CaseInsensitiveDict()
        cid['oNe'] = 1
        cid['tWo'] = 2
        cid[3] = 3
        self.assertEqual(cid['ONE'], 1)
        self.assertEqual(cid['one'], 1)
        self.assertEqual(cid['TWO'], 2)
        self.assertEqual(cid['two'], 2)
        self.assertEqual(cid[3], 3)
github cannatag / ldap3 / test / testCaseInsensitiveDictionary.py View on Github external
def test_case_insensitive_dict_contains_same_case_key(self):
        cid = CaseInsensitiveDict()
        cid['oNe'] = 1
        cid['tWo'] = 2
        cid[3] = 3
        self.assertTrue('oNe' in cid)
        self.assertFalse('THREE' in cid)
        self.assertFalse(4 in cid)
github cannatag / ldap3 / test / testCaseInsensitiveDictionary.py View on Github external
def test_create_empty_case_insensitive_dict(self):
        cid = CaseInsensitiveDict()
        self.assertTrue(isinstance(cid, CaseInsensitiveDict))
github cannatag / ldap3 / test / testCaseInsensitiveDictionary.py View on Github external
def test_equality_case_insensitive_dict_with_different_case(self):
        cid = CaseInsensitiveDict()
        cid['one'] = 1
        cid['two'] = 2
        cid[3] = 3

        cid2 = CaseInsensitiveDict()
        cid2['ONE'] = 1
        cid2['TWO'] = 2
        cid2[3] = 3

        self.assertEqual(cid, cid2)
github cannatag / ldap3 / ldap3 / operation / search.py View on Github external
def checked_attributes_to_dict(attribute_list, schema=None, custom_formatter=None):
    conf_case_insensitive_attributes = get_config_parameter('CASE_INSENSITIVE_ATTRIBUTE_NAMES')

    checked_attributes = CaseInsensitiveDict() if conf_case_insensitive_attributes else dict()
    for attribute in attribute_list:
        name = str(attribute['type'])
        checked_attributes[name] = format_attribute_values(schema, name, decode_raw_vals(attribute['vals']) or [], custom_formatter)
    return checked_attributes
github grawity / code / lib / python / nullroute / ldap.py View on Github external
def increment_attr(conn, dn, attr, incr=1):
    # optimization: RFC 4525 Modify-Increment + RFC 4527 Post-Read
    if _has_control(conn, LDAP_CONTROL_POSTREAD) and \
       _has_feature(conn, LDAP_FEATURE_MODIFY_INCREMENT):
        # this is far uglier than the Perl version already
        postread_ctrl = ldap3.protocol.rfc4527.post_read_control([attr])
        res = conn.modify(dn,
                          {attr: [(ldap3.MODIFY_INCREMENT, incr)]},
                          controls=[postread_ctrl])
        if not res:
            raise Exception("modify-increment failed", conn.result)
        res = conn.result["controls"][LDAP_CONTROL_POSTREAD]["value"]["result"]
        res = CaseInsensitiveDict(res)
        return res[attr][0]

    done = False
    wait = 0
    while not done:
        val = read_attr(conn, dn, attr)
        val = int(val[0]) if val else 0
        # _cas_attr
        done = conn.modify(dn,
                           {attr: [(ldap3.MODIFY_DELETE, val),
                                   (ldap3.MODIFY_ADD, val + incr)]})
        if not done:
            Core.debug("modify failed: %r", conn.result)
            wait += 1
            time.usleep(0.05 * 2**int(rand(wait)))
    return val+incr
github cannatag / ldap3 / ldap3 / utils / ciDict.py View on Github external
def copy(self):
        return CaseInsensitiveDict(self._store)
github cannatag / ldap3 / ldap3 / operation / search.py View on Github external
def raw_attributes_to_dict_fast(attribute_list):
    conf_case_insensitive_attributes = get_config_parameter('CASE_INSENSITIVE_ATTRIBUTE_NAMES')
    attributes = CaseInsensitiveDict() if conf_case_insensitive_attributes else dict()
    for attribute in attribute_list:
        attributes[to_unicode(attribute[3][0][3], from_server=True)] = decode_raw_vals_fast(attribute[3][1][3])

    return attributes