Deepwalker / trafaret

Ultimate transformation library that supports validation, contexts and aiohttp.
http://trafaret.readthedocs.org/en/latest/
BSD 2-Clause "Simplified" License
177 stars 31 forks source link

No FromString/ToBytes? #104

Closed Dreamsorcerer closed 4 years ago

Dreamsorcerer commented 4 years ago

There is a FromBytes object to convert to string. It would be nice to have the inverse to convert to bytes.

Deepwalker commented 4 years ago

Do you have real use case? How it should look like? ToBytes(encoding='utf-8')?

Dreamsorcerer commented 4 years ago

Looks reasonable, yes. Use case is to pass an argument such as a password into a password hashing function, which requires bytes.

login = t.Dict({"password": t.ToBytes(encoding="utf-8"), "username": t.String()})
hashlib.scrypt(login["password"], ...)