[core] Decode environment variables with filesystem encoding

This PR fixes the problem with non-ASCII characters in environment variables under python2 in windows (described in #3854 #2918 #3217) by introducing compat versions of `os.getenv` and `os.path.expanduser`.
`compat_getenv` decodes variables with filesystem encoding
`compat_expanduser` is a copypasted implementation from python 2.7 with env variable extraction via `compat_getenv`.