[Python-porting] Text version of os.environ for six?
Benjamin Peterson
benjamin at python.org
Wed Aug 8 00:43:31 EDT 2018
On Wed, Jul 25, 2018, at 11:05, Toshio Kuratomi wrote:
> Hey al ( benjaminp in particular ;-),
>
> Today, in my project, I had a need for reading some environment values
> as text strings. This is automatic in Python3 but in Python2 the
> values are byte strings. I wrote a little proxy class to do this:
> https://gist.github.com/abadger/6c873f999649a0be0e6ce5a96690ec6f#file-gistfile1-txt-L9
>
> I was wondering if this is something that would be worthwhile to
> contribute to six? If so, what requirements would be wanted? Things
> I can think of:
>
> * Use sys.getfilesystemencoding() to decode the environment.
Except not on windows where the environment is UTF-16.
> * Cache the decoded values.
> * Where should it live in six? six.environ ?
> * I assume that in six, we'd want six.environ to be an instance of the
> class rather than making users instantiate their own TetEnviron class,
> correct?
Yes. I suppose the other question is if six.environ would need to have the same magical behavior of os.environ. I.e., calling os.getenv and os.putenv on __getitem__ and __setitem__.
>
> Let me know if you think this is within the scope of six and I'll go
> through the normal steps of opening a Pull Request and so forth.
It's at least worth opening a GitHub issue, so others can easily register interest.
More information about the Python-porting
mailing list