[issue1181] Redefine clear() for os.environ to use unsetenv() if possible

2007-09-19 Thread Martin Horcicka

New submission from Martin Horcicka:

This patch makes os.environ.clear() to have the same effect as:

for name in os.environ.keys():
del os.environ[name]

I believe that most people expect the effects to be the same anyway.

The practical benefit is a simpler redefinition of the whole environment
if desired (e.g. in scripts run via sudo on unix systems).

--
components: Library (Lib)
files: os.py.patch
messages: 56048
nosy: horcicka
severity: normal
status: open
title: Redefine clear() for os.environ to use unsetenv() if possible
type: behavior

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1181>
__Index: Lib/os.py
===
--- Lib/os.py	(revision 58212)
+++ Lib/os.py	(working copy)
@@ -446,6 +446,11 @@
 def __delitem__(self, key):
 unsetenv(key)
 del self.data[key.upper()]
+
+def clear(self):
+for key in self.data.keys():
+unsetenv(key)
+del self.data[key]
 def has_key(self, key):
 return key.upper() in self.data
 def __contains__(self, key):
@@ -503,6 +508,11 @@
 def __delitem__(self, key):
 unsetenv(key)
 del self.data[key]
+
+def clear(self):
+for key in self.data.keys():
+unsetenv(key)
+del self.data[key]
 def copy(self):
 return dict(self)
 
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1208] Match object should be guaranteed to always be true

2007-09-26 Thread Martin Horcicka

New submission from Martin Horcicka:

Many people expect the match object from the re module to always be
true. They use it this way:

if regexp.match(string): do_something()

Some people do not expect it and use it differently:

if regexp.match(string) is not None: do_something()

Even in the standard library both ways are used. The first way is
simpler and nicer and thus better, in my opinion.

Current implementation of the match object (implemented as
_sre.SRE_Match object in Modules/_sre.c) seems to guarantee the trueness
(someone should check it) but in fact, there is no guarantee described
in the documentation.

--
components: Documentation, Library (Lib)
messages: 56149
nosy: horcicka
severity: normal
status: open
title: Match object should be guaranteed to always be true
type: behavior

__
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1208>
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com