mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
Fix errors reported by mypy
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
f3ba709d21
commit
bfd0544ff8
13 changed files with 68 additions and 71 deletions
|
|
@ -83,7 +83,7 @@ class Connection: # export
|
|||
raise Exception(f'Failed to bind to {c.ldap_uri} with dn {c.bind_dn} ({e})')
|
||||
self.__ldap = ret
|
||||
self.__backtrace = backtrace
|
||||
self.__object_classes: dict[str, ObjectClass]|None = None
|
||||
self.__object_classes_by_oid: dict[str, ObjectClass]|None = None
|
||||
self.__object_class_tree: nx.Graph|None = None
|
||||
self.__object_classes_by_name: dict[str, ObjectClass]|None = None
|
||||
|
||||
|
|
@ -93,12 +93,10 @@ class Connection: # export
|
|||
|
||||
def add(self, attrs: dict[str, bytes], dn: str|None=None):
|
||||
if dn is None:
|
||||
dn = attrs.get('dn')
|
||||
if dn is None:
|
||||
if not 'dn' in attrs:
|
||||
raise Exception('No DN to add an LDAP entry to')
|
||||
else:
|
||||
attrs = copy.deepcopy(attrs)
|
||||
del attrs['dn']
|
||||
attrs = copy.deepcopy(attrs)
|
||||
del attrs['dn']
|
||||
try:
|
||||
slog(INFO, f'LDAP: Add [{dn}] -> {attrs}')
|
||||
self.__ldap.add_s(dn, ldap.modlist.addModlist(attrs))
|
||||
|
|
@ -175,14 +173,14 @@ class Connection: # export
|
|||
assert_not_empty=False,
|
||||
):
|
||||
|
||||
def __walk_cb_find(conn: Connection, entry, context):
|
||||
def __walk_cb_find(conn: Connection, entry: Any, context: Any):
|
||||
result.append(entry)
|
||||
|
||||
def __search():
|
||||
return f'{base} -> "{filterstr}"'
|
||||
|
||||
try:
|
||||
result = []
|
||||
result: list[Any] = []
|
||||
self.walk(__walk_cb_find, base, scope=scope, filterstr=filterstr, attrlist=attrlist)
|
||||
except Exception as e:
|
||||
slog(ERR, f'Failed search {__search()} ({e})')
|
||||
|
|
@ -194,9 +192,9 @@ class Connection: # export
|
|||
return result
|
||||
|
||||
@property
|
||||
def object_classes(self) -> list[ObjectClass]:
|
||||
def object_classes(self) -> dict[str, ObjectClass]:
|
||||
#def object_classes(self):
|
||||
if self.__object_classes is None:
|
||||
if self.__object_classes_by_oid is None:
|
||||
res = self.find(base='', scope=ldap.SCOPE_BASE, filterstr='(objectClass=*)', attrlist=['subschemaSubentry'])
|
||||
dn = res[0][1]['subschemaSubentry'][0].decode('utf-8') # Usually yields cn=Subschema
|
||||
res = self.find(base=dn, scope=ldap.SCOPE_BASE, filterstr='(objectClass=*)', attrlist=['*', '+'])
|
||||
|
|
@ -204,13 +202,13 @@ class Connection: # export
|
|||
subschema_subentry = ldap.cidict.cidict(subschema_entry[1])
|
||||
subschema = ldap.schema.SubSchema(subschema_subentry)
|
||||
object_class_oids = subschema.listall(ObjectClass)
|
||||
self.__object_classes = {
|
||||
self.__object_classes_by_oid = {
|
||||
oid: subschema.get_obj(ObjectClass, oid) for oid in object_class_oids
|
||||
}
|
||||
return self.__object_classes
|
||||
return self.__object_classes_by_oid
|
||||
|
||||
@property
|
||||
def object_class_by_name(self):
|
||||
def object_class_by_name(self) -> dict[str, ObjectClass]:
|
||||
if self.__object_classes_by_name is None:
|
||||
ret: dict[str, ObjectClass] = {}
|
||||
self.__object_classes_by_name = ret
|
||||
|
|
@ -230,7 +228,7 @@ class Connection: # export
|
|||
def object_class_path(self, leaf: str|ObjectClass):
|
||||
def cb(oc, context):
|
||||
ret.append(oc)
|
||||
ret = []
|
||||
ret: list[str] = []
|
||||
self.__oc_recurse_to_top(leaf, cb, None)
|
||||
return reversed(ret)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue