Skip to content

Commit

Permalink
Merge pull request topazproject#521 from michelboaventura/env_delete
Browse files Browse the repository at this point in the history
Implements ENV#delete
  • Loading branch information
alex committed Mar 18, 2013
2 parents 9b39c7d + b85adea commit 1378fb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 0 additions & 3 deletions spec/tags/core/env/delete_tags.txt

This file was deleted.

13 changes: 13 additions & 0 deletions topaz/objects/envobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ def method_subscript_assign(self, space, key, value):
raise space.error(space.w_ArgumentError, "bad environment variable value")
os.environ[key] = value
return space.newstr_fromstr(value)

@classdef.method("delete", key="str")
def method_delete(self, space, key, block=None):
if "\0" in key:
raise space.error(space.w_ArgumentError, "bad environment variable name")
try:
val = os.environ[key]
except KeyError:
if block is not None:
space.invoke_block(block, [space.newstr_fromstr(key)])
return space.w_nil
del os.environ[key]
return space.newstr_fromstr(val)

0 comments on commit 1378fb3

Please sign in to comment.