[Python-3000] setup.py fails in the py3k-struni branch

Guido van Rossum guido at python.org
Wed Jun 13 23:53:50 CEST 2007


I couldn't get this exact patch to apply, but I implemented something
equivalent in the py3kstruni branch. See revisions 55964 and 55965.
Thanks for the suggestion!

--Guido

On 6/12/07, Ron Adam <rrr at ronadam.com> wrote:
> Guido van Rossum wrote:
> > On 6/7/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> >> >> The os.environ.get() method probably should return a unicode
> >> string. (?)
> >> >
> >> > Indeed -- care to contribute a patch?
> >>
> >> Ideally, such a patch would make use of the Win32 Unicode API for
> >> environment variables on Windows. People had already been complaining
> >> that they can't have "funny characters" in the value of an environment
> >> variable, even though the UI allows them to set the variable just fine.
> >
> > Yeah, but the Windows build of py3k is currently badly broken (e.g.
> > the _fileio.c extension probably doesn't work at all) -- and I don't
> > have access to a Windows box to work on it. I'm afraid 3.0a1 will be
> > released without Windows support. Of course I'm counting on others to
> > fix that before 3.0 final is released.
> >
> > I don't mind for now that the posix.environ variable contains 8-bit
> > strings -- people shouldn't be importing that anyway.
>
>
> Here's a diff of the patch.  It looks like this may be backported to 2.6
> since it isn't Unicode specific but casts to the current str type.
>
>
>
> Cast environ keys and values to current python str type in os.py
> Added test for environ string types to test_os.py
> Fixed test_update2, bug 1110478 test, that was being skipped.
>
> Test test_tmpfile in test_os.py fails.  Haven't looked into it yet.
>
>
> Index: Lib/os.py
> ===================================================================
> --- Lib/os.py   (revision 55924)
> +++ Lib/os.py   (working copy)
> @@ -505,7 +505,8 @@
>               def copy(self):
>                   return dict(self)
>
> -
> +    # Make sure all environment keys and values are correct str type.
> +    environ = dict([(str(k), str(v)) for k, v in environ.items()])
>       environ = _Environ(environ)
>
>   def getenv(key, default=None):
> Index: Lib/test/test_os.py
> ===================================================================
> --- Lib/test/test_os.py (revision 55924)
> +++ Lib/test/test_os.py (working copy)
> @@ -266,12 +266,25 @@
>           os.environ.clear()
>           os.environ.update(self.__save)
>
> +class EnvironTests2(unittest.TestCase):
> +    """Test os.environ for specific problems."""
> +    def setUp(self):
> +        self.__save = dict(os.environ)
> +    def tearDown(self):
> +        os.environ.clear()
> +        os.environ.update(self.__save)
>       # Bug 1110478
>       def test_update2(self):
>           if os.path.exists("/bin/sh"):
>               os.environ.update(HELLO="World")
>               value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
>               self.assertEquals(value, "World")
> +    # Verify environ keys and values from the OS are of the
> +    # correct str type.
> +    def test_keyvalue_types(self):
> +        for key, val in os.environ.items():
> +            self.assertEquals(type(key), str)
> +            self.assertEquals(type(val), str)
>
>   class WalkTests(unittest.TestCase):
>       """Tests for os.walk()."""
> @@ -466,6 +479,7 @@
>           TemporaryFileTests,
>           StatAttributeTests,
>           EnvironTests,
> +        EnvironTests2,
>           WalkTests,
>           MakedirTests,
>           DevNullTests,
>
>
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list