[Python-Dev] Re: os module UserDict

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Wed, 7 Mar 2001 07:38:52 +0100


> Yes, it's from me. Unfortunately a whitespace problem with me, my editor
> and my diffutils required Guido to apply most of the patches manually...

I see. What do you think about the patch included below? It also gives
you the default argument to os.getenv, which riscosmodule does not
have.

> In plat-riscos there is a different UserDict-like implementation of
> environ which is imported at the top of os.py in the 'riscos' part.
> 'name != "riscos"' just avoids overriding this. Maybe it would have
> been better to include riscosenviron._Environ into os.py, as this would
> look - and be - less hacky?

No, I think it is good to have the platform-specific code in platform
modules, and only merge them appropiately in os.py.

> P.S.: How can I subscribe to python-dev (at least read-only)?

You can't; it is by invitation only. You can find the archives at

http://mail.python.org/pipermail/python-dev/

Regards,
Martin

Index: os.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os.py,v
retrieving revision 1.46
diff -u -r1.46 os.py
--- os.py	2001/03/06 15:26:07	1.46
+++ os.py	2001/03/07 06:31:34
@@ -346,17 +346,19 @@
     raise exc, arg
 
 
-if name != "riscos":
-    # Change environ to automatically call putenv() if it exists
-    try:
-        # This will fail if there's no putenv
-        putenv
-    except NameError:
-        pass
-    else:
-        import UserDict
+# Change environ to automatically call putenv() if it exists
+try:
+    # This will fail if there's no putenv
+    putenv
+except NameError:
+    pass
+else:
+    import UserDict
 
-    if name in ('os2', 'nt', 'dos'):  # Where Env Var Names Must Be UPPERCASE
+    if name == "riscos":
+        # On RISC OS, all env access goes through getenv and putenv
+        from riscosenviron import _Environ
+    elif name in ('os2', 'nt', 'dos'):  # Where Env Var Names Must Be UPPERCASE
         # But we store them as upper case
         class _Environ(UserDict.UserDict):
             def __init__(self, environ):
Index: plat-riscos/riscosenviron.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-riscos/riscosenviron.py,v
retrieving revision 1.1
diff -u -r1.1 riscosenviron.py
--- plat-riscos/riscosenviron.py	2001/03/02 05:55:07	1.1
+++ plat-riscos/riscosenviron.py	2001/03/07 06:31:34
@@ -3,7 +3,7 @@
 import riscos
 
 class _Environ:
-    def __init__(self):
+    def __init__(self, initial = None):
         pass
     def __repr__(self):
         return repr(riscos.getenvdict())