pyceo/ceod/model/utils.py

28 lines
732 B
Python

from typing import Dict, List
def bytes_to_strings(data: Dict[str, List[bytes]]) -> Dict[str, List[str]]:
"""Convert the attribute values from bytes to strings"""
return {
key: [b.decode() for b in val]
for key, val in data.items()
}
def strings_to_bytes(data: Dict[str, List[str]]) -> Dict[str, List[bytes]]:
"""Convert the attribute values from strings to bytes"""
return {
key: [b.encode() for b in val]
for key, val in data.items()
}
def dn_to_uid(dn: str) -> str:
"""Extract the UID from an LDAP DN.
Examples:
dn_to_uid('uid=ctdalek,ou=People,dc=csclub,dc=uwaterloo,dc=ca')
-> 'ctdalek'
"""
return dn.split(',', 1)[0].split('=')[1]