2001-10-24 17:42:55 -03:00
|
|
|
"""A more or less complete dictionary like interface for the RISC OS environment."""
|
2001-03-02 01:58:11 -04:00
|
|
|
|
|
|
|
import riscos
|
|
|
|
|
|
|
|
class _Environ:
|
2001-03-07 05:05:45 -04:00
|
|
|
def __init__(self, initial = None):
|
2001-03-02 01:58:11 -04:00
|
|
|
pass
|
|
|
|
def __repr__(self):
|
|
|
|
return repr(riscos.getenvdict())
|
|
|
|
def __cmp__(self, dict):
|
2001-10-24 17:42:55 -03:00
|
|
|
return cmp(riscos.getenvdict(), dict)
|
2001-03-02 01:58:11 -04:00
|
|
|
def __len__(self):
|
|
|
|
return len(riscos.getenvdict())
|
|
|
|
def __getitem__(self, key):
|
|
|
|
ret = riscos.getenv(key)
|
2006-08-24 22:00:47 -03:00
|
|
|
if ret != None:
|
2001-03-02 01:58:11 -04:00
|
|
|
return ret
|
|
|
|
else:
|
|
|
|
raise KeyError
|
|
|
|
def __setitem__(self, key, item):
|
2001-03-07 05:08:11 -04:00
|
|
|
riscos.putenv(key, item)
|
2001-03-02 01:58:11 -04:00
|
|
|
def __delitem__(self, key):
|
|
|
|
riscos.delenv(key)
|
|
|
|
def clear(self):
|
|
|
|
# too dangerous on RISC OS
|
|
|
|
pass
|
|
|
|
def copy(self):
|
|
|
|
return riscos.getenvdict()
|
|
|
|
def keys(self): return riscos.getenvdict().keys()
|
|
|
|
def items(self): return riscos.getenvdict().items()
|
|
|
|
def values(self): return riscos.getenvdict().values()
|
|
|
|
def has_key(self, key):
|
|
|
|
value = riscos.getenv(key)
|
2006-08-24 22:06:13 -03:00
|
|
|
return value != None
|
2003-01-29 20:56:33 -04:00
|
|
|
def __contains__(self, key):
|
|
|
|
return riscos.getenv(key) is not None
|
2001-03-02 01:58:11 -04:00
|
|
|
def update(self, dict):
|
|
|
|
for k, v in dict.items():
|
|
|
|
riscos.putenv(k, v)
|
|
|
|
def get(self, key, failobj=None):
|
|
|
|
value = riscos.getenv(key)
|
2006-08-24 22:08:24 -03:00
|
|
|
if value != None:
|
2001-03-02 01:58:11 -04:00
|
|
|
return value
|
|
|
|
else:
|
|
|
|
return failobj
|