/
opt
/
imh-python
/
lib
/
python3.9
/
site-packages
/
IPython
/
core
/
/opt/imh-python/lib/python3.9/site-packages/IPython/core
mkdir
upload
Name
Size
Mode
Actions
magics/
-
0755
rm
profile/
-
0755
rm
tests/
-
0755
rm
__pycache__/
-
0755
rm
alias.py
10034
0644
edit
dl
rm
application.py
18937
0644
edit
dl
rm
async_helpers.py
4297
0644
edit
dl
rm
autocall.py
1991
0644
edit
dl
rm
builtin_trap.py
3009
0644
edit
dl
rm
compilerop.py
7730
0644
edit
dl
rm
completer.py
117850
0644
edit
dl
rm
completerlib.py
12365
0644
edit
dl
rm
crashhandler.py
8508
0644
edit
dl
rm
debugger.py
38872
0644
edit
dl
rm
display.py
42503
0644
edit
dl
rm
displayhook.py
12962
0644
edit
dl
rm
displaypub.py
4944
0644
edit
dl
rm
display_functions.py
12918
0644
edit
dl
rm
display_trap.py
2098
0644
edit
dl
rm
error.py
1734
0644
edit
dl
rm
events.py
5251
0644
edit
dl
rm
excolors.py
4928
0644
edit
dl
rm
extensions.py
5780
0644
edit
dl
rm
formatters.py
34981
0644
edit
dl
rm
getipython.py
912
0644
edit
dl
rm
guarded_eval.py
25037
0644
edit
dl
rm
history.py
34475
0644
edit
dl
rm
historyapp.py
5909
0644
edit
dl
rm
hooks.py
5663
0644
edit
dl
rm
inputsplitter.py
29041
0644
edit
dl
rm
inputtransformer.py
18184
0644
edit
dl
rm
inputtransformer2.py
29393
0644
edit
dl
rm
interactiveshell.py
153761
0644
edit
dl
rm
latex_symbols.py
31288
0644
edit
dl
rm
logger.py
8441
0644
edit
dl
rm
macro.py
1734
0644
edit
dl
rm
magic.py
28899
0644
edit
dl
rm
magic_arguments.py
9734
0644
edit
dl
rm
oinspect.py
39898
0644
edit
dl
rm
page.py
11753
0644
edit
dl
rm
payload.py
1758
0644
edit
dl
rm
payloadpage.py
1431
0644
edit
dl
rm
prefilter.py
25588
0644
edit
dl
rm
profileapp.py
10631
0644
edit
dl
rm
profiledir.py
8029
0644
edit
dl
rm
prompts.py
607
0644
edit
dl
rm
pylabtools.py
14018
0644
edit
dl
rm
release.py
2178
0644
edit
dl
rm
shellapp.py
17845
0644
edit
dl
rm
splitinput.py
4836
0644
edit
dl
rm
ultratb.py
55803
0644
edit
dl
rm
usage.py
13542
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/opt/imh-python/lib/python3.9/site-packages/IPython/core/async_helpers.py
(4297B)
""" Async helper function that are invalid syntax on Python 3.5 and below. This code is best effort, and may have edge cases not behaving as expected. In particular it contain a number of heuristics to detect whether code is effectively async and need to run in an event loop or not. Some constructs (like top-level `return`, or `yield`) are taken care of explicitly to actually raise a SyntaxError and stay as close as possible to Python semantics. """ import ast import asyncio import inspect from functools import wraps _asyncio_event_loop = None def get_asyncio_loop(): """asyncio has deprecated get_event_loop Replicate it here, with our desired semantics: - always returns a valid, not-closed loop - not thread-local like asyncio's, because we only want one loop for IPython - if called from inside a coroutine (e.g. in ipykernel), return the running loop .. versionadded:: 8.0 """ try: return asyncio.get_running_loop() except RuntimeError: # not inside a coroutine, # track our own global pass # not thread-local like asyncio's, # because we only track one event loop to run for IPython itself, # always in the main thread. global _asyncio_event_loop if _asyncio_event_loop is None or _asyncio_event_loop.is_closed(): _asyncio_event_loop = asyncio.new_event_loop() return _asyncio_event_loop class _AsyncIORunner: def __call__(self, coro): """ Handler for asyncio autoawait """ return get_asyncio_loop().run_until_complete(coro) def __str__(self): return "asyncio" _asyncio_runner = _AsyncIORunner() class _AsyncIOProxy: """Proxy-object for an asyncio Any coroutine methods will be wrapped in event_loop.run_ """ def __init__(self, obj, event_loop): self._obj = obj self._event_loop = event_loop def __repr__(self): return f"<_AsyncIOProxy({self._obj!r})>" def __getattr__(self, key): attr = getattr(self._obj, key) if inspect.iscoroutinefunction(attr): # if it's a coroutine method, # return a threadsafe wrapper onto the _current_ asyncio loop @wraps(attr) def _wrapped(*args, **kwargs): concurrent_future = asyncio.run_coroutine_threadsafe( attr(*args, **kwargs), self._event_loop ) return asyncio.wrap_future(concurrent_future) return _wrapped else: return attr def __dir__(self): return dir(self._obj) def _curio_runner(coroutine): """ handler for curio autoawait """ import curio return curio.run(coroutine) def _trio_runner(async_fn): import trio async def loc(coro): """ We need the dummy no-op async def to protect from trio's internal. See https://github.com/python-trio/trio/issues/89 """ return await coro return trio.run(loc, async_fn) def _pseudo_sync_runner(coro): """ A runner that does not really allow async execution, and just advance the coroutine. See discussion in https://github.com/python-trio/trio/issues/608, Credit to Nathaniel Smith """ try: coro.send(None) except StopIteration as exc: return exc.value else: # TODO: do not raise but return an execution result with the right info. raise RuntimeError( "{coro_name!r} needs a real async loop".format(coro_name=coro.__name__) ) def _should_be_async(cell: str) -> bool: """Detect if a block of code need to be wrapped in an `async def` Attempt to parse the block of code, it it compile we're fine. Otherwise we wrap if and try to compile. If it works, assume it should be async. Otherwise Return False. Not handled yet: If the block of code has a return statement as the top level, it will be seen as async. This is a know limitation. """ try: code = compile( cell, "<>", "exec", flags=getattr(ast, "PyCF_ALLOW_TOP_LEVEL_AWAIT", 0x0) ) return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE except (SyntaxError, MemoryError): return False
Save
cmd:
run