Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldapmod.py/ldap3.py: Force modlist for search/modify/etc. to be str types #47029

Merged
merged 2 commits into from
Apr 12, 2018

Conversation

terminalmage
Copy link
Contributor

@terminalmage terminalmage commented Apr 11, 2018

This is done by adding a to_str argument to our decode helpers which allows you to force the string/bytestring to be converted to a str type, and then using that new functionality in ldapmod.py/ldap3.py.

Resolves #46859.
Resolves #46887.

This allows for the string to be forced to a str type instead of
unicode on PY2.
@terminalmage terminalmage changed the title ldapmod.py: Force attrs to be str types ldapmod.py/ldap3.py: Force modlist for search/modify/etc. to be str types Apr 11, 2018
@angeloudy
Copy link
Contributor

Even with to_str=False, the decode function will call _decode_func = salt.utils.stringutils.to_unicode, which will still return str

def to_unicode(s, encoding=None, errors='strict', normalize=False):
    '''
    Given str or unicode, return unicode (str for python 3)
    '''
    def _normalize(s):
        return unicodedata.normalize('NFC', s) if normalize else s

    if six.PY3:
        if isinstance(s, str):
            return _normalize(s)
        elif isinstance(s, (bytes, bytearray)):
            return _normalize(to_str(s, encoding, errors))
        raise TypeError('expected str, bytes, or bytearray')
    else:
        # This needs to be str and not six.string_types, since if the string is
        # already a unicode type, it does not need to be decoded (and doing so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants