/
usr
/
lib
/
python3
/
dist-packages
/
twisted
/
python
/
/usr/lib/python3/dist-packages/twisted/python
mkdir
upload
Name
Size
Mode
Actions
test/
-
0755
rm
_pydoctortemplates/
-
0755
rm
__pycache__/
-
0755
rm
compat.py
16931
0644
edit
dl
rm
components.py
14199
0644
edit
dl
rm
constants.py
513
0644
edit
dl
rm
context.py
4054
0644
edit
dl
rm
deprecate.py
27668
0644
edit
dl
rm
failure.py
27007
0644
edit
dl
rm
fakepwd.py
6732
0644
edit
dl
rm
filepath.py
54023
0644
edit
dl
rm
formmethod.py
12107
0644
edit
dl
rm
htmlizer.py
3626
0644
edit
dl
rm
lockfile.py
8026
0644
edit
dl
rm
log.py
22302
0644
edit
dl
rm
logfile.py
10119
0644
edit
dl
rm
modules.py
26715
0644
edit
dl
rm
monkey.py
2164
0644
edit
dl
rm
procutils.py
1371
0644
edit
dl
rm
randbytes.py
3459
0644
edit
dl
rm
rebuild.py
7122
0644
edit
dl
rm
reflect.py
20480
0644
edit
dl
rm
release.py
1104
0644
edit
dl
rm
roots.py
7178
0644
edit
dl
rm
runtime.py
5924
0644
edit
dl
rm
sendmsg.py
2682
0644
edit
dl
rm
shortcut.py
2302
0644
edit
dl
rm
syslog.py
3652
0644
edit
dl
rm
systemd.py
2987
0644
edit
dl
rm
text.py
5417
0644
edit
dl
rm
threadable.py
3327
0644
edit
dl
rm
threadpool.py
10203
0644
edit
dl
rm
twisted-completion.zsh
1371
0644
edit
dl
rm
url.py
244
0644
edit
dl
rm
urlpath.py
8447
0644
edit
dl
rm
usage.py
34577
0644
edit
dl
rm
util.py
27432
0644
edit
dl
rm
versions.py
273
0644
edit
dl
rm
win32.py
4794
0644
edit
dl
rm
zippath.py
9028
0644
edit
dl
rm
zipstream.py
9680
0644
edit
dl
rm
_appdirs.py
820
0644
edit
dl
rm
_inotify.py
3496
0644
edit
dl
rm
_pydoctor.py
6735
0644
edit
dl
rm
_release.py
18879
0644
edit
dl
rm
_shellcomp.py
25279
0644
edit
dl
rm
_textattributes.py
9097
0644
edit
dl
rm
_tzhelper.py
3128
0644
edit
dl
rm
_url.py
228
0644
edit
dl
rm
__init__.py
598
0644
edit
dl
rm
Edit:
/usr/lib/python3/dist-packages/twisted/python/context.py
(4054B)
# -*- test-case-name: twisted.test.test_context -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Dynamic pseudo-scoping for Python. Call functions with context.call({key: value}, func); func and functions that it calls will be able to use 'context.get(key)' to retrieve 'value'. This is thread-safe. """ from threading import local from typing import Dict, Type defaultContextDict: Dict[Type[object], Dict[str, str]] = {} setDefault = defaultContextDict.__setitem__ class ContextTracker: """ A L{ContextTracker} provides a way to pass arbitrary key/value data up and down a call stack without passing them as parameters to the functions on that call stack. This can be useful when functions on the top and bottom of the call stack need to cooperate but the functions in between them do not allow passing the necessary state. For example:: from twisted.python.context import call, get def handleRequest(request): call({'request-id': request.id}, renderRequest, request.url) def renderRequest(url): renderHeader(url) renderBody(url) def renderHeader(url): return "the header" def renderBody(url): return "the body (request id=%r)" % (get("request-id"),) This should be used sparingly, since the lack of a clear connection between the two halves can result in code which is difficult to understand and maintain. @ivar contexts: A C{list} of C{dict}s tracking the context state. Each new L{ContextTracker.callWithContext} pushes a new C{dict} onto this stack for the duration of the call, making the data available to the function called and restoring the previous data once it is complete.. """ def __init__(self): self.contexts = [defaultContextDict] def callWithContext(self, newContext, func, *args, **kw): """ Call C{func(*args, **kw)} such that the contents of C{newContext} will be available for it to retrieve using L{getContext}. @param newContext: A C{dict} of data to push onto the context for the duration of the call to C{func}. @param func: A callable which will be called. @param args: Any additional positional arguments to pass to C{func}. @param kw: Any additional keyword arguments to pass to C{func}. @return: Whatever is returned by C{func} @raise Exception: Whatever is raised by C{func}. """ self.contexts.append(newContext) try: return func(*args, **kw) finally: self.contexts.pop() def getContext(self, key, default=None): """ Retrieve the value for a key from the context. @param key: The key to look up in the context. @param default: The value to return if C{key} is not found in the context. @return: The value most recently remembered in the context for C{key}. """ for ctx in reversed(self.contexts): try: return ctx[key] except KeyError: pass return default class ThreadedContextTracker: def __init__(self): self.storage = local() def currentContext(self): try: return self.storage.ct except AttributeError: ct = self.storage.ct = ContextTracker() return ct def callWithContext(self, ctx, func, *args, **kw): return self.currentContext().callWithContext(ctx, func, *args, **kw) def getContext(self, key, default=None): return self.currentContext().getContext(key, default) theContextTracker = ThreadedContextTracker() call = theContextTracker.callWithContext get = theContextTracker.getContext def installContextTracker(ctr): global theContextTracker global call global get theContextTracker = ctr call = theContextTracker.callWithContext get = theContextTracker.getContext
Save
cmd:
run