Proposal for a new if-else hierarchy:
```
if PY3K:
    if not isinstance(password, (str, bytes)):
        password = str(password)
    if isinstance(password, string)
        #Put here line 141 to 150 without returns
else:
    if not isinstance(password, (unicode, str)):
        password= str(password)
    if isinstance(password, unicode):
        password = password.encode('u8')
return password
```
This makes it easier in my opinion and solves the problem mentioned in my comment in line 156