sys.setdefaultencoding('utf8') causing issues #82

Open
encodingissue opened this Issue Jan 14, 2011 · 3 comments

Comments

Projects
None yet
4 participants
@encodingissue

sys.setdefaultencoding('utf8')

I am using Python 2. I believe my system relies on the default encoding not being changed to UTF-8 in many places. Is there a work-around to avoid using this line of code (from basexmpp.py)? I would gladly encode individual strings in SleekXMPP to UTF-8 (or ASCII if that is what is expected), but I do not know where in the SleekXMPP code theses changes would need to be added. Are there any other ideas of possible work-arounds? Or any guidance on how to hard-code Python 2 compatibility by encoding certain strings individually?

@fritzy

This comment has been minimized.

Show comment Hide comment
@fritzy

fritzy Feb 5, 2011

Owner

We've discussed changing some of the xmlstream reading/rewriting functions to load/install different versions depending on which version of Python you're using. This may not be enough, and needs a bit more research.

Owner

fritzy commented Feb 5, 2011

We've discussed changing some of the xmlstream reading/rewriting functions to load/install different versions depending on which version of Python you're using. This may not be enough, and needs a bit more research.

@legastero

This comment has been minimized.

Show comment Hide comment
@legastero

legastero Feb 20, 2011

Collaborator

We may be able to get things to work without needing to duplicate everything by using:
# -*- coding: utf-8
from future import unicode_literals

It would obviate the need to use the 'u' prefix on strings, but it would be required in probably every file, especially ones defining stanza classes. Again, more research is needed. The main issue is just ensuring that user data is always Unicode.

Collaborator

legastero commented Feb 20, 2011

We may be able to get things to work without needing to duplicate everything by using:
# -*- coding: utf-8
from future import unicode_literals

It would obviate the need to use the 'u' prefix on strings, but it would be required in probably every file, especially ones defining stanza classes. Again, more research is needed. The main issue is just ensuring that user data is always Unicode.

@ThiefMaster

This comment has been minimized.

Show comment Hide comment
@ThiefMaster

ThiefMaster Aug 19, 2016

Changing the global default encoding without any way to disable it is completely inappropriate for a library. 😠

This is invasive and there is a reason why the function is removed from the sys module by Python itself.

ThiefMaster commented Aug 19, 2016

Changing the global default encoding without any way to disable it is completely inappropriate for a library. 😠

This is invasive and there is a reason why the function is removed from the sys module by Python itself.

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