How to use the ldap3.utils.ciDict.CaseInsensitiveWithAliasDict 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 / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_len_empty(self):
        cid = CaseInsensitiveWithAliasDict()
        self.assertEqual(len(cid), 0)
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_explicit_add_same_alias_to_different_key_same_case(self):
        cid = CaseInsensitiveWithAliasDict()
        cid['oNe', 'oNe-A'] = 1
        cid['tWo'] = 2
        try:
            cid.set_alias('tWo', 'oNe-A')
        except KeyError:
            self.assertTrue(True)
        except Exception:
            self.fail('wrong exception')
        else:
            self.fail('double alias')
        self.assertEqual(cid._store, {'oNe': 1, 'tWo': 2})
        self.assertEqual(cid._aliases, {'one-a': 'one'})
        self.assertEqual(cid._alias_keymap, {'one': ['one-a']})
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_add_same_alias_twice_to_same_key_different_case(self):
        cid = CaseInsensitiveWithAliasDict()
        try:
            cid['oNe', 'oNe-A', 'ONE-A'] = 1
        except KeyError:
            self.assertTrue(True)
        except Exception:
            self.fail('wrong exception')

        self.assertEqual(cid._store, {'oNe': 1})
        self.assertEqual(cid._aliases, {'one-a': 'one'})
        self.assertEqual(cid._alias_keymap, {'one': ['one-a']})
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_implicit_add_multiple_aliases_to_same_key(self):
        cid = CaseInsensitiveWithAliasDict()
        cid['oNe', 'oNe-A', 'oNe-B'] = 1
        cid['tWo'] = 2
        self.assertEqual(len(cid), 2)
        self.assertEqual(cid['oNe'], 1)
        self.assertEqual(cid['oNe-A'], 1)
        self.assertEqual(cid['oNe-B'], 1)
        self.assertEqual(cid['tWo'], 2)
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_delete_item_same_case_key(self):
        cid = CaseInsensitiveWithAliasDict()
        cid['oNe'] = 1
        cid['tWo'] = 2
        cid[3] = 3
        self.assertEqual(cid['ONE'], 1)
        self.assertEqual(cid['oNe'], 1)
        del cid['oNe']
        self.assertEqual(cid['TWO'], 2)
        self.assertEqual(cid['two'], 2)
        self.assertEqual(cid[3], 3)

        try:
            cid['oNe']
        except KeyError:
            self.assertTrue(True)
        except Exception:
            self.assertTrue(False)
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_add_alias_to_key_same_case(self):
        cid = CaseInsensitiveWithAliasDict()
        cid['oNe'] = 1
        cid['tWo'] = 2
        cid.set_alias('oNe', 'oNe-A')
        self.assertEqual(len(cid), 2)
        self.assertEqual(cid['oNe'], 1)
        self.assertEqual(cid['oNe-A'], 1)
        self.assertEqual(cid['tWo'], 2)
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_delete_alias_same_case(self):
        cid = CaseInsensitiveWithAliasDict()
        cid['oNe', 'oNe-A', 'oNe-B'] = 1
        cid['tWo'] = 2
        self.assertEqual(len(cid), 2)
        del cid['oNe-A']
        self.assertEqual(len(cid), 2)
        self.assertEqual(cid['oNe'], 1)
        self.assertEqual(cid['oNe-B'], 1)
        try:
            cid['oNe-A']
        except KeyError:
            self.assertTrue(True)
        except Exception:
            self.assertTrue(False)
        else:
            self.fail('key still present')
        self.assertEqual(cid._store, {'oNe': 1, 'tWo': 2})
github cannatag / ldap3 / test / testCaseInsensitiveWithAliasDictionary.py View on Github external
def test_contains_same_case_key(self):
        cid = CaseInsensitiveWithAliasDict()
        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 / ldap3 / abstract / cursor.py View on Github external
def _get_attributes(self, response, attr_defs, entry):
        """Assign the result of the LDAP query to the Entry object dictionary.

        If the optional 'post_query' callable is present in the AttrDef it is called with each value of the attribute and the callable result is stored in the attribute.

        Returns the default value for missing attributes.
        If the 'dereference_dn' in AttrDef is a ObjectDef then the attribute values are treated as distinguished name and the relevant entry is retrieved and stored in the attribute value.

        """
        conf_operational_attribute_prefix = get_config_parameter('ABSTRACTION_OPERATIONAL_ATTRIBUTE_PREFIX')
        conf_attributes_excluded_from_object_def = [v.lower() for v in get_config_parameter('ATTRIBUTES_EXCLUDED_FROM_OBJECT_DEF')]
        attributes = CaseInsensitiveWithAliasDict()
        used_attribute_names = set()
        for attr in attr_defs:
            attr_def = attr_defs[attr]
            attribute_name = None
            for attr_name in response['attributes']:
                if attr_def.name.lower() == attr_name.lower():
                    attribute_name = attr_name
                    break

            if attribute_name or attr_def.default is not NotImplemented:  # attribute value found in result or default value present - NotImplemented allows use of None as default
                attribute = self.attribute_class(attr_def, entry, self)
                attribute.response = response
                attribute.raw_values = response['raw_attributes'][attribute_name] if attribute_name else None
                if attr_def.post_query and attr_def.name in response['attributes'] and response['raw_attributes'] != list():
                    attribute.values = attr_def.post_query(attr_def.key, response['attributes'][attribute_name])
                else: