MCPcopy
hub / github.com/scrapy/scrapy / set_environ

Function set_environ

scrapy/utils/misc.py:222–236  ·  view source on GitHub ↗

Temporarily set environment variables inside the context manager and fully restore previous environment afterwards

(**kwargs: str)

Source from the content-addressed store, hash-verified

220
221@contextmanager
222def set_environ(**kwargs: str) -> Iterator[None]:
223 """Temporarily set environment variables inside the context manager and
224 fully restore previous environment afterwards
225 """
226
227 original_env = {k: os.environ.get(k) for k in kwargs}
228 os.environ.update(kwargs)
229 try:
230 yield
231 finally:
232 for k, v in original_env.items():
233 if v is None:
234 del os.environ[k]
235 else:
236 os.environ[k] = v
237
238
239def walk_callable(node: ast.AST) -> Iterable[ast.AST]:

Calls 3

itemsMethod · 0.80
getMethod · 0.45
updateMethod · 0.45