<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def patch(self, **kw):
 """Update the environment for the duration of a context."""

    old_environ = self._environ
    self._environ = self._environ.copy()
    self._environ.update(kw)
    yield
    self._environ = old_environ