-
Notifications
You must be signed in to change notification settings - Fork 275
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
Add encoding utility #12
Comments
That seems reasonable. What were you planning on calling it? |
Does this need to support all of unicode? It doesn't seem that blindly encoding something in utf-8 is what you'd always want. Would encoding with just ascii be sufficient? Also, it does extra work in Python 2 if you pass a |
Original comment by Claude Paroz (Bitbucket: claudep, GitHub: claudep): I think that the use case for Python 2 is clearly to take a Unicode string and transform it into a utf-8 byte string. Using the 'ascii' encoding would lead to UnicodeEncodeError in many cases. Surely, testing if it is already a byte string could be a nice addition (Python 2, again). |
I'm wondering if using utf-8 is always the correct thing to do. For example, with type(), non-ascii identifiers should not be used in Python 2, since it doesn't support them. time.strftime will always return a byte-string thus leaking the utf-8 into the return value. |
Original comment by Aymeric Augustin (Bitbucket: aaugustin, GitHub: aaugustin): We revisited significant parts of Vinay Sajip's experimental port since opening this issue, and we probably aren't going to need this function. When Python 2 requires a byte string and Python 3 a unicode string, Django uses:
|
Original comment by Aymeric Augustin (Bitbucket: aaugustin, GitHub: aaugustin): We revisited significant parts of Vinay Sajip's experimental port since opening this issue, and we probably aren't going to need this function. When Python 2 requires a byte string and Python 3 a unicode string, Django uses:
|
Add 'patch_with_metaclass' which provides a more complete interface for supporting metaclass-based classes across Python versions.
Originally reported by: Claude Paroz (Bitbucket: claudep, GitHub: claudep)
Hi,
We're planning to embed six in Django as the blessed Python 3 compatibility layer. One thing we're missing is a function that returns a byte string on Python 2 and Unicode in Python 3. This is typically useful when providing arguments for strftime() or type(). Our current implementation is:
We could of course provide it in some of our own modules, but it would be nice to have it in six, unless you suggest a better replacement.
The text was updated successfully, but these errors were encountered: