Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- janus/lib/python3.10/asyncio/__pycache__/__init__.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/__main__.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/base_events.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/base_futures.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/base_subprocess.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/base_tasks.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/constants.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/coroutines.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/events.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/exceptions.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/format_helpers.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/futures.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/locks.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/log.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/mixins.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/proactor_events.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/protocols.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/queues.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/runners.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/selector_events.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/sslproto.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/staggered.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/streams.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/subprocess.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/tasks.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/threads.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/transports.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/trsock.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/unix_events.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/windows_events.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/__pycache__/windows_utils.cpython-310.pyc +0 -0
- janus/lib/python3.10/asyncio/base_futures.py +80 -0
- janus/lib/python3.10/asyncio/base_subprocess.py +285 -0
- janus/lib/python3.10/asyncio/constants.py +27 -0
- janus/lib/python3.10/asyncio/log.py +7 -0
- janus/lib/python3.10/asyncio/proactor_events.py +875 -0
- janus/lib/python3.10/asyncio/queues.py +245 -0
- janus/lib/python3.10/asyncio/runners.py +73 -0
- janus/lib/python3.10/asyncio/sslproto.py +739 -0
- janus/lib/python3.10/asyncio/staggered.py +149 -0
- janus/lib/python3.10/asyncio/streams.py +726 -0
- janus/lib/python3.10/asyncio/transports.py +335 -0
- janus/lib/python3.10/asyncio/trsock.py +206 -0
- janus/lib/python3.10/asyncio/unix_events.py +1466 -0
- janus/lib/python3.10/html/__init__.py +132 -0
- janus/lib/python3.10/html/__pycache__/__init__.cpython-310.pyc +0 -0
- janus/lib/python3.10/html/__pycache__/parser.cpython-310.pyc +0 -0
- janus/lib/python3.10/html/entities.py +2510 -0
- janus/lib/python3.10/html/parser.py +462 -0
.gitattributes
CHANGED
|
@@ -462,3 +462,4 @@ janus/lib/python3.10/site-packages/pip/_vendor/pkg_resources/__pycache__/__init_
|
|
| 462 |
janus/lib/python3.10/site-packages/regex/__pycache__/test_regex.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 463 |
janus/lib/python3.10/site-packages/numpy/ma/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 464 |
janus/lib/python3.10/site-packages/numpy/linalg/__pycache__/_linalg.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 462 |
janus/lib/python3.10/site-packages/regex/__pycache__/test_regex.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 463 |
janus/lib/python3.10/site-packages/numpy/ma/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 464 |
janus/lib/python3.10/site-packages/numpy/linalg/__pycache__/_linalg.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 465 |
+
janus/lib/python3.10/site-packages/pkg_resources/__pycache__/__init__.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
janus/lib/python3.10/asyncio/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (739 Bytes). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/__main__.cpython-310.pyc
ADDED
|
Binary file (3.46 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/base_events.cpython-310.pyc
ADDED
|
Binary file (52.1 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/base_futures.cpython-310.pyc
ADDED
|
Binary file (2.17 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/base_subprocess.cpython-310.pyc
ADDED
|
Binary file (9.38 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/base_tasks.cpython-310.pyc
ADDED
|
Binary file (2.24 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/constants.cpython-310.pyc
ADDED
|
Binary file (840 Bytes). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/coroutines.cpython-310.pyc
ADDED
|
Binary file (6.62 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/events.cpython-310.pyc
ADDED
|
Binary file (28.6 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/exceptions.cpython-310.pyc
ADDED
|
Binary file (2.72 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/format_helpers.cpython-310.pyc
ADDED
|
Binary file (2.59 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/futures.cpython-310.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/locks.cpython-310.pyc
ADDED
|
Binary file (14.4 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/log.cpython-310.pyc
ADDED
|
Binary file (483 Bytes). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/mixins.cpython-310.pyc
ADDED
|
Binary file (1.07 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/proactor_events.cpython-310.pyc
ADDED
|
Binary file (24.7 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/protocols.cpython-310.pyc
ADDED
|
Binary file (8.29 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/queues.cpython-310.pyc
ADDED
|
Binary file (8.3 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/runners.cpython-310.pyc
ADDED
|
Binary file (2.09 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/selector_events.cpython-310.pyc
ADDED
|
Binary file (29.8 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/sslproto.cpython-310.pyc
ADDED
|
Binary file (22.2 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/staggered.cpython-310.pyc
ADDED
|
Binary file (4.44 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/streams.cpython-310.pyc
ADDED
|
Binary file (20.4 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/subprocess.cpython-310.pyc
ADDED
|
Binary file (7.32 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/tasks.cpython-310.pyc
ADDED
|
Binary file (24.2 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/threads.cpython-310.pyc
ADDED
|
Binary file (1.24 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/transports.cpython-310.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/trsock.cpython-310.pyc
ADDED
|
Binary file (7.84 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/unix_events.cpython-310.pyc
ADDED
|
Binary file (41.9 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/windows_events.cpython-310.pyc
ADDED
|
Binary file (24.4 kB). View file
|
|
|
janus/lib/python3.10/asyncio/__pycache__/windows_utils.cpython-310.pyc
ADDED
|
Binary file (4.75 kB). View file
|
|
|
janus/lib/python3.10/asyncio/base_futures.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ()
|
| 2 |
+
|
| 3 |
+
import reprlib
|
| 4 |
+
from _thread import get_ident
|
| 5 |
+
|
| 6 |
+
from . import format_helpers
|
| 7 |
+
|
| 8 |
+
# States for Future.
|
| 9 |
+
_PENDING = 'PENDING'
|
| 10 |
+
_CANCELLED = 'CANCELLED'
|
| 11 |
+
_FINISHED = 'FINISHED'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def isfuture(obj):
|
| 15 |
+
"""Check for a Future.
|
| 16 |
+
|
| 17 |
+
This returns True when obj is a Future instance or is advertising
|
| 18 |
+
itself as duck-type compatible by setting _asyncio_future_blocking.
|
| 19 |
+
See comment in Future for more details.
|
| 20 |
+
"""
|
| 21 |
+
return (hasattr(obj.__class__, '_asyncio_future_blocking') and
|
| 22 |
+
obj._asyncio_future_blocking is not None)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _format_callbacks(cb):
|
| 26 |
+
"""helper function for Future.__repr__"""
|
| 27 |
+
size = len(cb)
|
| 28 |
+
if not size:
|
| 29 |
+
cb = ''
|
| 30 |
+
|
| 31 |
+
def format_cb(callback):
|
| 32 |
+
return format_helpers._format_callback_source(callback, ())
|
| 33 |
+
|
| 34 |
+
if size == 1:
|
| 35 |
+
cb = format_cb(cb[0][0])
|
| 36 |
+
elif size == 2:
|
| 37 |
+
cb = '{}, {}'.format(format_cb(cb[0][0]), format_cb(cb[1][0]))
|
| 38 |
+
elif size > 2:
|
| 39 |
+
cb = '{}, <{} more>, {}'.format(format_cb(cb[0][0]),
|
| 40 |
+
size - 2,
|
| 41 |
+
format_cb(cb[-1][0]))
|
| 42 |
+
return f'cb=[{cb}]'
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# bpo-42183: _repr_running is needed for repr protection
|
| 46 |
+
# when a Future or Task result contains itself directly or indirectly.
|
| 47 |
+
# The logic is borrowed from @reprlib.recursive_repr decorator.
|
| 48 |
+
# Unfortunately, the direct decorator usage is impossible because of
|
| 49 |
+
# AttributeError: '_asyncio.Task' object has no attribute '__module__' error.
|
| 50 |
+
#
|
| 51 |
+
# After fixing this thing we can return to the decorator based approach.
|
| 52 |
+
_repr_running = set()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _future_repr_info(future):
|
| 56 |
+
# (Future) -> str
|
| 57 |
+
"""helper function for Future.__repr__"""
|
| 58 |
+
info = [future._state.lower()]
|
| 59 |
+
if future._state == _FINISHED:
|
| 60 |
+
if future._exception is not None:
|
| 61 |
+
info.append(f'exception={future._exception!r}')
|
| 62 |
+
else:
|
| 63 |
+
key = id(future), get_ident()
|
| 64 |
+
if key in _repr_running:
|
| 65 |
+
result = '...'
|
| 66 |
+
else:
|
| 67 |
+
_repr_running.add(key)
|
| 68 |
+
try:
|
| 69 |
+
# use reprlib to limit the length of the output, especially
|
| 70 |
+
# for very long strings
|
| 71 |
+
result = reprlib.repr(future._result)
|
| 72 |
+
finally:
|
| 73 |
+
_repr_running.discard(key)
|
| 74 |
+
info.append(f'result={result}')
|
| 75 |
+
if future._callbacks:
|
| 76 |
+
info.append(_format_callbacks(future._callbacks))
|
| 77 |
+
if future._source_traceback:
|
| 78 |
+
frame = future._source_traceback[-1]
|
| 79 |
+
info.append(f'created at {frame[0]}:{frame[1]}')
|
| 80 |
+
return info
|
janus/lib/python3.10/asyncio/base_subprocess.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
import subprocess
|
| 3 |
+
import warnings
|
| 4 |
+
|
| 5 |
+
from . import protocols
|
| 6 |
+
from . import transports
|
| 7 |
+
from .log import logger
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class BaseSubprocessTransport(transports.SubprocessTransport):
|
| 11 |
+
|
| 12 |
+
def __init__(self, loop, protocol, args, shell,
|
| 13 |
+
stdin, stdout, stderr, bufsize,
|
| 14 |
+
waiter=None, extra=None, **kwargs):
|
| 15 |
+
super().__init__(extra)
|
| 16 |
+
self._closed = False
|
| 17 |
+
self._protocol = protocol
|
| 18 |
+
self._loop = loop
|
| 19 |
+
self._proc = None
|
| 20 |
+
self._pid = None
|
| 21 |
+
self._returncode = None
|
| 22 |
+
self._exit_waiters = []
|
| 23 |
+
self._pending_calls = collections.deque()
|
| 24 |
+
self._pipes = {}
|
| 25 |
+
self._finished = False
|
| 26 |
+
|
| 27 |
+
if stdin == subprocess.PIPE:
|
| 28 |
+
self._pipes[0] = None
|
| 29 |
+
if stdout == subprocess.PIPE:
|
| 30 |
+
self._pipes[1] = None
|
| 31 |
+
if stderr == subprocess.PIPE:
|
| 32 |
+
self._pipes[2] = None
|
| 33 |
+
|
| 34 |
+
# Create the child process: set the _proc attribute
|
| 35 |
+
try:
|
| 36 |
+
self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
|
| 37 |
+
stderr=stderr, bufsize=bufsize, **kwargs)
|
| 38 |
+
except:
|
| 39 |
+
self.close()
|
| 40 |
+
raise
|
| 41 |
+
|
| 42 |
+
self._pid = self._proc.pid
|
| 43 |
+
self._extra['subprocess'] = self._proc
|
| 44 |
+
|
| 45 |
+
if self._loop.get_debug():
|
| 46 |
+
if isinstance(args, (bytes, str)):
|
| 47 |
+
program = args
|
| 48 |
+
else:
|
| 49 |
+
program = args[0]
|
| 50 |
+
logger.debug('process %r created: pid %s',
|
| 51 |
+
program, self._pid)
|
| 52 |
+
|
| 53 |
+
self._loop.create_task(self._connect_pipes(waiter))
|
| 54 |
+
|
| 55 |
+
def __repr__(self):
|
| 56 |
+
info = [self.__class__.__name__]
|
| 57 |
+
if self._closed:
|
| 58 |
+
info.append('closed')
|
| 59 |
+
if self._pid is not None:
|
| 60 |
+
info.append(f'pid={self._pid}')
|
| 61 |
+
if self._returncode is not None:
|
| 62 |
+
info.append(f'returncode={self._returncode}')
|
| 63 |
+
elif self._pid is not None:
|
| 64 |
+
info.append('running')
|
| 65 |
+
else:
|
| 66 |
+
info.append('not started')
|
| 67 |
+
|
| 68 |
+
stdin = self._pipes.get(0)
|
| 69 |
+
if stdin is not None:
|
| 70 |
+
info.append(f'stdin={stdin.pipe}')
|
| 71 |
+
|
| 72 |
+
stdout = self._pipes.get(1)
|
| 73 |
+
stderr = self._pipes.get(2)
|
| 74 |
+
if stdout is not None and stderr is stdout:
|
| 75 |
+
info.append(f'stdout=stderr={stdout.pipe}')
|
| 76 |
+
else:
|
| 77 |
+
if stdout is not None:
|
| 78 |
+
info.append(f'stdout={stdout.pipe}')
|
| 79 |
+
if stderr is not None:
|
| 80 |
+
info.append(f'stderr={stderr.pipe}')
|
| 81 |
+
|
| 82 |
+
return '<{}>'.format(' '.join(info))
|
| 83 |
+
|
| 84 |
+
def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
|
| 85 |
+
raise NotImplementedError
|
| 86 |
+
|
| 87 |
+
def set_protocol(self, protocol):
|
| 88 |
+
self._protocol = protocol
|
| 89 |
+
|
| 90 |
+
def get_protocol(self):
|
| 91 |
+
return self._protocol
|
| 92 |
+
|
| 93 |
+
def is_closing(self):
|
| 94 |
+
return self._closed
|
| 95 |
+
|
| 96 |
+
def close(self):
|
| 97 |
+
if self._closed:
|
| 98 |
+
return
|
| 99 |
+
self._closed = True
|
| 100 |
+
|
| 101 |
+
for proto in self._pipes.values():
|
| 102 |
+
if proto is None:
|
| 103 |
+
continue
|
| 104 |
+
proto.pipe.close()
|
| 105 |
+
|
| 106 |
+
if (self._proc is not None and
|
| 107 |
+
# has the child process finished?
|
| 108 |
+
self._returncode is None and
|
| 109 |
+
# the child process has finished, but the
|
| 110 |
+
# transport hasn't been notified yet?
|
| 111 |
+
self._proc.poll() is None):
|
| 112 |
+
|
| 113 |
+
if self._loop.get_debug():
|
| 114 |
+
logger.warning('Close running child process: kill %r', self)
|
| 115 |
+
|
| 116 |
+
try:
|
| 117 |
+
self._proc.kill()
|
| 118 |
+
except ProcessLookupError:
|
| 119 |
+
pass
|
| 120 |
+
|
| 121 |
+
# Don't clear the _proc reference yet: _post_init() may still run
|
| 122 |
+
|
| 123 |
+
def __del__(self, _warn=warnings.warn):
|
| 124 |
+
if not self._closed:
|
| 125 |
+
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
|
| 126 |
+
self.close()
|
| 127 |
+
|
| 128 |
+
def get_pid(self):
|
| 129 |
+
return self._pid
|
| 130 |
+
|
| 131 |
+
def get_returncode(self):
|
| 132 |
+
return self._returncode
|
| 133 |
+
|
| 134 |
+
def get_pipe_transport(self, fd):
|
| 135 |
+
if fd in self._pipes:
|
| 136 |
+
return self._pipes[fd].pipe
|
| 137 |
+
else:
|
| 138 |
+
return None
|
| 139 |
+
|
| 140 |
+
def _check_proc(self):
|
| 141 |
+
if self._proc is None:
|
| 142 |
+
raise ProcessLookupError()
|
| 143 |
+
|
| 144 |
+
def send_signal(self, signal):
|
| 145 |
+
self._check_proc()
|
| 146 |
+
self._proc.send_signal(signal)
|
| 147 |
+
|
| 148 |
+
def terminate(self):
|
| 149 |
+
self._check_proc()
|
| 150 |
+
self._proc.terminate()
|
| 151 |
+
|
| 152 |
+
def kill(self):
|
| 153 |
+
self._check_proc()
|
| 154 |
+
self._proc.kill()
|
| 155 |
+
|
| 156 |
+
async def _connect_pipes(self, waiter):
|
| 157 |
+
try:
|
| 158 |
+
proc = self._proc
|
| 159 |
+
loop = self._loop
|
| 160 |
+
|
| 161 |
+
if proc.stdin is not None:
|
| 162 |
+
_, pipe = await loop.connect_write_pipe(
|
| 163 |
+
lambda: WriteSubprocessPipeProto(self, 0),
|
| 164 |
+
proc.stdin)
|
| 165 |
+
self._pipes[0] = pipe
|
| 166 |
+
|
| 167 |
+
if proc.stdout is not None:
|
| 168 |
+
_, pipe = await loop.connect_read_pipe(
|
| 169 |
+
lambda: ReadSubprocessPipeProto(self, 1),
|
| 170 |
+
proc.stdout)
|
| 171 |
+
self._pipes[1] = pipe
|
| 172 |
+
|
| 173 |
+
if proc.stderr is not None:
|
| 174 |
+
_, pipe = await loop.connect_read_pipe(
|
| 175 |
+
lambda: ReadSubprocessPipeProto(self, 2),
|
| 176 |
+
proc.stderr)
|
| 177 |
+
self._pipes[2] = pipe
|
| 178 |
+
|
| 179 |
+
assert self._pending_calls is not None
|
| 180 |
+
|
| 181 |
+
loop.call_soon(self._protocol.connection_made, self)
|
| 182 |
+
for callback, data in self._pending_calls:
|
| 183 |
+
loop.call_soon(callback, *data)
|
| 184 |
+
self._pending_calls = None
|
| 185 |
+
except (SystemExit, KeyboardInterrupt):
|
| 186 |
+
raise
|
| 187 |
+
except BaseException as exc:
|
| 188 |
+
if waiter is not None and not waiter.cancelled():
|
| 189 |
+
waiter.set_exception(exc)
|
| 190 |
+
else:
|
| 191 |
+
if waiter is not None and not waiter.cancelled():
|
| 192 |
+
waiter.set_result(None)
|
| 193 |
+
|
| 194 |
+
def _call(self, cb, *data):
|
| 195 |
+
if self._pending_calls is not None:
|
| 196 |
+
self._pending_calls.append((cb, data))
|
| 197 |
+
else:
|
| 198 |
+
self._loop.call_soon(cb, *data)
|
| 199 |
+
|
| 200 |
+
def _pipe_connection_lost(self, fd, exc):
|
| 201 |
+
self._call(self._protocol.pipe_connection_lost, fd, exc)
|
| 202 |
+
self._try_finish()
|
| 203 |
+
|
| 204 |
+
def _pipe_data_received(self, fd, data):
|
| 205 |
+
self._call(self._protocol.pipe_data_received, fd, data)
|
| 206 |
+
|
| 207 |
+
def _process_exited(self, returncode):
|
| 208 |
+
assert returncode is not None, returncode
|
| 209 |
+
assert self._returncode is None, self._returncode
|
| 210 |
+
if self._loop.get_debug():
|
| 211 |
+
logger.info('%r exited with return code %r', self, returncode)
|
| 212 |
+
self._returncode = returncode
|
| 213 |
+
if self._proc.returncode is None:
|
| 214 |
+
# asyncio uses a child watcher: copy the status into the Popen
|
| 215 |
+
# object. On Python 3.6, it is required to avoid a ResourceWarning.
|
| 216 |
+
self._proc.returncode = returncode
|
| 217 |
+
self._call(self._protocol.process_exited)
|
| 218 |
+
self._try_finish()
|
| 219 |
+
|
| 220 |
+
# wake up futures waiting for wait()
|
| 221 |
+
for waiter in self._exit_waiters:
|
| 222 |
+
if not waiter.cancelled():
|
| 223 |
+
waiter.set_result(returncode)
|
| 224 |
+
self._exit_waiters = None
|
| 225 |
+
|
| 226 |
+
async def _wait(self):
|
| 227 |
+
"""Wait until the process exit and return the process return code.
|
| 228 |
+
|
| 229 |
+
This method is a coroutine."""
|
| 230 |
+
if self._returncode is not None:
|
| 231 |
+
return self._returncode
|
| 232 |
+
|
| 233 |
+
waiter = self._loop.create_future()
|
| 234 |
+
self._exit_waiters.append(waiter)
|
| 235 |
+
return await waiter
|
| 236 |
+
|
| 237 |
+
def _try_finish(self):
|
| 238 |
+
assert not self._finished
|
| 239 |
+
if self._returncode is None:
|
| 240 |
+
return
|
| 241 |
+
if all(p is not None and p.disconnected
|
| 242 |
+
for p in self._pipes.values()):
|
| 243 |
+
self._finished = True
|
| 244 |
+
self._call(self._call_connection_lost, None)
|
| 245 |
+
|
| 246 |
+
def _call_connection_lost(self, exc):
|
| 247 |
+
try:
|
| 248 |
+
self._protocol.connection_lost(exc)
|
| 249 |
+
finally:
|
| 250 |
+
self._loop = None
|
| 251 |
+
self._proc = None
|
| 252 |
+
self._protocol = None
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
class WriteSubprocessPipeProto(protocols.BaseProtocol):
|
| 256 |
+
|
| 257 |
+
def __init__(self, proc, fd):
|
| 258 |
+
self.proc = proc
|
| 259 |
+
self.fd = fd
|
| 260 |
+
self.pipe = None
|
| 261 |
+
self.disconnected = False
|
| 262 |
+
|
| 263 |
+
def connection_made(self, transport):
|
| 264 |
+
self.pipe = transport
|
| 265 |
+
|
| 266 |
+
def __repr__(self):
|
| 267 |
+
return f'<{self.__class__.__name__} fd={self.fd} pipe={self.pipe!r}>'
|
| 268 |
+
|
| 269 |
+
def connection_lost(self, exc):
|
| 270 |
+
self.disconnected = True
|
| 271 |
+
self.proc._pipe_connection_lost(self.fd, exc)
|
| 272 |
+
self.proc = None
|
| 273 |
+
|
| 274 |
+
def pause_writing(self):
|
| 275 |
+
self.proc._protocol.pause_writing()
|
| 276 |
+
|
| 277 |
+
def resume_writing(self):
|
| 278 |
+
self.proc._protocol.resume_writing()
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
class ReadSubprocessPipeProto(WriteSubprocessPipeProto,
|
| 282 |
+
protocols.Protocol):
|
| 283 |
+
|
| 284 |
+
def data_received(self, data):
|
| 285 |
+
self.proc._pipe_data_received(self.fd, data)
|
janus/lib/python3.10/asyncio/constants.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
|
| 3 |
+
# After the connection is lost, log warnings after this many write()s.
|
| 4 |
+
LOG_THRESHOLD_FOR_CONNLOST_WRITES = 5
|
| 5 |
+
|
| 6 |
+
# Seconds to wait before retrying accept().
|
| 7 |
+
ACCEPT_RETRY_DELAY = 1
|
| 8 |
+
|
| 9 |
+
# Number of stack entries to capture in debug mode.
|
| 10 |
+
# The larger the number, the slower the operation in debug mode
|
| 11 |
+
# (see extract_stack() in format_helpers.py).
|
| 12 |
+
DEBUG_STACK_DEPTH = 10
|
| 13 |
+
|
| 14 |
+
# Number of seconds to wait for SSL handshake to complete
|
| 15 |
+
# The default timeout matches that of Nginx.
|
| 16 |
+
SSL_HANDSHAKE_TIMEOUT = 60.0
|
| 17 |
+
|
| 18 |
+
# Used in sendfile fallback code. We use fallback for platforms
|
| 19 |
+
# that don't support sendfile, or for TLS connections.
|
| 20 |
+
SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 256
|
| 21 |
+
|
| 22 |
+
# The enum should be here to break circular dependencies between
|
| 23 |
+
# base_events and sslproto
|
| 24 |
+
class _SendfileMode(enum.Enum):
|
| 25 |
+
UNSUPPORTED = enum.auto()
|
| 26 |
+
TRY_NATIVE = enum.auto()
|
| 27 |
+
FALLBACK = enum.auto()
|
janus/lib/python3.10/asyncio/log.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Logging configuration."""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Name the logger after the package.
|
| 7 |
+
logger = logging.getLogger(__package__)
|
janus/lib/python3.10/asyncio/proactor_events.py
ADDED
|
@@ -0,0 +1,875 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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event loop using a proactor and related classes.
|
| 2 |
+
|
| 3 |
+
A proactor is a "notify-on-completion" multiplexer. Currently a
|
| 4 |
+
proactor is only implemented on Windows with IOCP.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
__all__ = 'BaseProactorEventLoop',
|
| 8 |
+
|
| 9 |
+
import io
|
| 10 |
+
import os
|
| 11 |
+
import socket
|
| 12 |
+
import warnings
|
| 13 |
+
import signal
|
| 14 |
+
import threading
|
| 15 |
+
import collections
|
| 16 |
+
|
| 17 |
+
from . import base_events
|
| 18 |
+
from . import constants
|
| 19 |
+
from . import futures
|
| 20 |
+
from . import exceptions
|
| 21 |
+
from . import protocols
|
| 22 |
+
from . import sslproto
|
| 23 |
+
from . import transports
|
| 24 |
+
from . import trsock
|
| 25 |
+
from .log import logger
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _set_socket_extra(transport, sock):
|
| 29 |
+
transport._extra['socket'] = trsock.TransportSocket(sock)
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
transport._extra['sockname'] = sock.getsockname()
|
| 33 |
+
except socket.error:
|
| 34 |
+
if transport._loop.get_debug():
|
| 35 |
+
logger.warning(
|
| 36 |
+
"getsockname() failed on %r", sock, exc_info=True)
|
| 37 |
+
|
| 38 |
+
if 'peername' not in transport._extra:
|
| 39 |
+
try:
|
| 40 |
+
transport._extra['peername'] = sock.getpeername()
|
| 41 |
+
except socket.error:
|
| 42 |
+
# UDP sockets may not have a peer name
|
| 43 |
+
transport._extra['peername'] = None
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class _ProactorBasePipeTransport(transports._FlowControlMixin,
|
| 47 |
+
transports.BaseTransport):
|
| 48 |
+
"""Base class for pipe and socket transports."""
|
| 49 |
+
|
| 50 |
+
def __init__(self, loop, sock, protocol, waiter=None,
|
| 51 |
+
extra=None, server=None):
|
| 52 |
+
super().__init__(extra, loop)
|
| 53 |
+
self._set_extra(sock)
|
| 54 |
+
self._sock = sock
|
| 55 |
+
self.set_protocol(protocol)
|
| 56 |
+
self._server = server
|
| 57 |
+
self._buffer = None # None or bytearray.
|
| 58 |
+
self._read_fut = None
|
| 59 |
+
self._write_fut = None
|
| 60 |
+
self._pending_write = 0
|
| 61 |
+
self._conn_lost = 0
|
| 62 |
+
self._closing = False # Set when close() called.
|
| 63 |
+
self._called_connection_lost = False
|
| 64 |
+
self._eof_written = False
|
| 65 |
+
if self._server is not None:
|
| 66 |
+
self._server._attach()
|
| 67 |
+
self._loop.call_soon(self._protocol.connection_made, self)
|
| 68 |
+
if waiter is not None:
|
| 69 |
+
# only wake up the waiter when connection_made() has been called
|
| 70 |
+
self._loop.call_soon(futures._set_result_unless_cancelled,
|
| 71 |
+
waiter, None)
|
| 72 |
+
|
| 73 |
+
def __repr__(self):
|
| 74 |
+
info = [self.__class__.__name__]
|
| 75 |
+
if self._sock is None:
|
| 76 |
+
info.append('closed')
|
| 77 |
+
elif self._closing:
|
| 78 |
+
info.append('closing')
|
| 79 |
+
if self._sock is not None:
|
| 80 |
+
info.append(f'fd={self._sock.fileno()}')
|
| 81 |
+
if self._read_fut is not None:
|
| 82 |
+
info.append(f'read={self._read_fut!r}')
|
| 83 |
+
if self._write_fut is not None:
|
| 84 |
+
info.append(f'write={self._write_fut!r}')
|
| 85 |
+
if self._buffer:
|
| 86 |
+
info.append(f'write_bufsize={len(self._buffer)}')
|
| 87 |
+
if self._eof_written:
|
| 88 |
+
info.append('EOF written')
|
| 89 |
+
return '<{}>'.format(' '.join(info))
|
| 90 |
+
|
| 91 |
+
def _set_extra(self, sock):
|
| 92 |
+
self._extra['pipe'] = sock
|
| 93 |
+
|
| 94 |
+
def set_protocol(self, protocol):
|
| 95 |
+
self._protocol = protocol
|
| 96 |
+
|
| 97 |
+
def get_protocol(self):
|
| 98 |
+
return self._protocol
|
| 99 |
+
|
| 100 |
+
def is_closing(self):
|
| 101 |
+
return self._closing
|
| 102 |
+
|
| 103 |
+
def close(self):
|
| 104 |
+
if self._closing:
|
| 105 |
+
return
|
| 106 |
+
self._closing = True
|
| 107 |
+
self._conn_lost += 1
|
| 108 |
+
if not self._buffer and self._write_fut is None:
|
| 109 |
+
self._loop.call_soon(self._call_connection_lost, None)
|
| 110 |
+
if self._read_fut is not None:
|
| 111 |
+
self._read_fut.cancel()
|
| 112 |
+
self._read_fut = None
|
| 113 |
+
|
| 114 |
+
def __del__(self, _warn=warnings.warn):
|
| 115 |
+
if self._sock is not None:
|
| 116 |
+
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
|
| 117 |
+
self._sock.close()
|
| 118 |
+
|
| 119 |
+
def _fatal_error(self, exc, message='Fatal error on pipe transport'):
|
| 120 |
+
try:
|
| 121 |
+
if isinstance(exc, OSError):
|
| 122 |
+
if self._loop.get_debug():
|
| 123 |
+
logger.debug("%r: %s", self, message, exc_info=True)
|
| 124 |
+
else:
|
| 125 |
+
self._loop.call_exception_handler({
|
| 126 |
+
'message': message,
|
| 127 |
+
'exception': exc,
|
| 128 |
+
'transport': self,
|
| 129 |
+
'protocol': self._protocol,
|
| 130 |
+
})
|
| 131 |
+
finally:
|
| 132 |
+
self._force_close(exc)
|
| 133 |
+
|
| 134 |
+
def _force_close(self, exc):
|
| 135 |
+
if self._empty_waiter is not None and not self._empty_waiter.done():
|
| 136 |
+
if exc is None:
|
| 137 |
+
self._empty_waiter.set_result(None)
|
| 138 |
+
else:
|
| 139 |
+
self._empty_waiter.set_exception(exc)
|
| 140 |
+
if self._closing and self._called_connection_lost:
|
| 141 |
+
return
|
| 142 |
+
self._closing = True
|
| 143 |
+
self._conn_lost += 1
|
| 144 |
+
if self._write_fut:
|
| 145 |
+
self._write_fut.cancel()
|
| 146 |
+
self._write_fut = None
|
| 147 |
+
if self._read_fut:
|
| 148 |
+
self._read_fut.cancel()
|
| 149 |
+
self._read_fut = None
|
| 150 |
+
self._pending_write = 0
|
| 151 |
+
self._buffer = None
|
| 152 |
+
self._loop.call_soon(self._call_connection_lost, exc)
|
| 153 |
+
|
| 154 |
+
def _call_connection_lost(self, exc):
|
| 155 |
+
if self._called_connection_lost:
|
| 156 |
+
return
|
| 157 |
+
try:
|
| 158 |
+
self._protocol.connection_lost(exc)
|
| 159 |
+
finally:
|
| 160 |
+
# XXX If there is a pending overlapped read on the other
|
| 161 |
+
# end then it may fail with ERROR_NETNAME_DELETED if we
|
| 162 |
+
# just close our end. First calling shutdown() seems to
|
| 163 |
+
# cure it, but maybe using DisconnectEx() would be better.
|
| 164 |
+
if hasattr(self._sock, 'shutdown') and self._sock.fileno() != -1:
|
| 165 |
+
self._sock.shutdown(socket.SHUT_RDWR)
|
| 166 |
+
self._sock.close()
|
| 167 |
+
self._sock = None
|
| 168 |
+
server = self._server
|
| 169 |
+
if server is not None:
|
| 170 |
+
server._detach()
|
| 171 |
+
self._server = None
|
| 172 |
+
self._called_connection_lost = True
|
| 173 |
+
|
| 174 |
+
def get_write_buffer_size(self):
|
| 175 |
+
size = self._pending_write
|
| 176 |
+
if self._buffer is not None:
|
| 177 |
+
size += len(self._buffer)
|
| 178 |
+
return size
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class _ProactorReadPipeTransport(_ProactorBasePipeTransport,
|
| 182 |
+
transports.ReadTransport):
|
| 183 |
+
"""Transport for read pipes."""
|
| 184 |
+
|
| 185 |
+
def __init__(self, loop, sock, protocol, waiter=None,
|
| 186 |
+
extra=None, server=None, buffer_size=65536):
|
| 187 |
+
self._pending_data_length = -1
|
| 188 |
+
self._paused = True
|
| 189 |
+
super().__init__(loop, sock, protocol, waiter, extra, server)
|
| 190 |
+
|
| 191 |
+
self._data = bytearray(buffer_size)
|
| 192 |
+
self._loop.call_soon(self._loop_reading)
|
| 193 |
+
self._paused = False
|
| 194 |
+
|
| 195 |
+
def is_reading(self):
|
| 196 |
+
return not self._paused and not self._closing
|
| 197 |
+
|
| 198 |
+
def pause_reading(self):
|
| 199 |
+
if self._closing or self._paused:
|
| 200 |
+
return
|
| 201 |
+
self._paused = True
|
| 202 |
+
|
| 203 |
+
# bpo-33694: Don't cancel self._read_fut because cancelling an
|
| 204 |
+
# overlapped WSASend() loss silently data with the current proactor
|
| 205 |
+
# implementation.
|
| 206 |
+
#
|
| 207 |
+
# If CancelIoEx() fails with ERROR_NOT_FOUND, it means that WSASend()
|
| 208 |
+
# completed (even if HasOverlappedIoCompleted() returns 0), but
|
| 209 |
+
# Overlapped.cancel() currently silently ignores the ERROR_NOT_FOUND
|
| 210 |
+
# error. Once the overlapped is ignored, the IOCP loop will ignores the
|
| 211 |
+
# completion I/O event and so not read the result of the overlapped
|
| 212 |
+
# WSARecv().
|
| 213 |
+
|
| 214 |
+
if self._loop.get_debug():
|
| 215 |
+
logger.debug("%r pauses reading", self)
|
| 216 |
+
|
| 217 |
+
def resume_reading(self):
|
| 218 |
+
if self._closing or not self._paused:
|
| 219 |
+
return
|
| 220 |
+
|
| 221 |
+
self._paused = False
|
| 222 |
+
if self._read_fut is None:
|
| 223 |
+
self._loop.call_soon(self._loop_reading, None)
|
| 224 |
+
|
| 225 |
+
length = self._pending_data_length
|
| 226 |
+
self._pending_data_length = -1
|
| 227 |
+
if length > -1:
|
| 228 |
+
# Call the protocol methode after calling _loop_reading(),
|
| 229 |
+
# since the protocol can decide to pause reading again.
|
| 230 |
+
self._loop.call_soon(self._data_received, self._data[:length], length)
|
| 231 |
+
|
| 232 |
+
if self._loop.get_debug():
|
| 233 |
+
logger.debug("%r resumes reading", self)
|
| 234 |
+
|
| 235 |
+
def _eof_received(self):
|
| 236 |
+
if self._loop.get_debug():
|
| 237 |
+
logger.debug("%r received EOF", self)
|
| 238 |
+
|
| 239 |
+
try:
|
| 240 |
+
keep_open = self._protocol.eof_received()
|
| 241 |
+
except (SystemExit, KeyboardInterrupt):
|
| 242 |
+
raise
|
| 243 |
+
except BaseException as exc:
|
| 244 |
+
self._fatal_error(
|
| 245 |
+
exc, 'Fatal error: protocol.eof_received() call failed.')
|
| 246 |
+
return
|
| 247 |
+
|
| 248 |
+
if not keep_open:
|
| 249 |
+
self.close()
|
| 250 |
+
|
| 251 |
+
def _data_received(self, data, length):
|
| 252 |
+
if self._paused:
|
| 253 |
+
# Don't call any protocol method while reading is paused.
|
| 254 |
+
# The protocol will be called on resume_reading().
|
| 255 |
+
assert self._pending_data_length == -1
|
| 256 |
+
self._pending_data_length = length
|
| 257 |
+
return
|
| 258 |
+
|
| 259 |
+
if length == 0:
|
| 260 |
+
self._eof_received()
|
| 261 |
+
return
|
| 262 |
+
|
| 263 |
+
if isinstance(self._protocol, protocols.BufferedProtocol):
|
| 264 |
+
try:
|
| 265 |
+
protocols._feed_data_to_buffered_proto(self._protocol, data)
|
| 266 |
+
except (SystemExit, KeyboardInterrupt):
|
| 267 |
+
raise
|
| 268 |
+
except BaseException as exc:
|
| 269 |
+
self._fatal_error(exc,
|
| 270 |
+
'Fatal error: protocol.buffer_updated() '
|
| 271 |
+
'call failed.')
|
| 272 |
+
return
|
| 273 |
+
else:
|
| 274 |
+
self._protocol.data_received(data)
|
| 275 |
+
|
| 276 |
+
def _loop_reading(self, fut=None):
|
| 277 |
+
length = -1
|
| 278 |
+
data = None
|
| 279 |
+
try:
|
| 280 |
+
if fut is not None:
|
| 281 |
+
assert self._read_fut is fut or (self._read_fut is None and
|
| 282 |
+
self._closing)
|
| 283 |
+
self._read_fut = None
|
| 284 |
+
if fut.done():
|
| 285 |
+
# deliver data later in "finally" clause
|
| 286 |
+
length = fut.result()
|
| 287 |
+
if length == 0:
|
| 288 |
+
# we got end-of-file so no need to reschedule a new read
|
| 289 |
+
return
|
| 290 |
+
|
| 291 |
+
data = self._data[:length]
|
| 292 |
+
else:
|
| 293 |
+
# the future will be replaced by next proactor.recv call
|
| 294 |
+
fut.cancel()
|
| 295 |
+
|
| 296 |
+
if self._closing:
|
| 297 |
+
# since close() has been called we ignore any read data
|
| 298 |
+
return
|
| 299 |
+
|
| 300 |
+
# bpo-33694: buffer_updated() has currently no fast path because of
|
| 301 |
+
# a data loss issue caused by overlapped WSASend() cancellation.
|
| 302 |
+
|
| 303 |
+
if not self._paused:
|
| 304 |
+
# reschedule a new read
|
| 305 |
+
self._read_fut = self._loop._proactor.recv_into(self._sock, self._data)
|
| 306 |
+
except ConnectionAbortedError as exc:
|
| 307 |
+
if not self._closing:
|
| 308 |
+
self._fatal_error(exc, 'Fatal read error on pipe transport')
|
| 309 |
+
elif self._loop.get_debug():
|
| 310 |
+
logger.debug("Read error on pipe transport while closing",
|
| 311 |
+
exc_info=True)
|
| 312 |
+
except ConnectionResetError as exc:
|
| 313 |
+
self._force_close(exc)
|
| 314 |
+
except OSError as exc:
|
| 315 |
+
self._fatal_error(exc, 'Fatal read error on pipe transport')
|
| 316 |
+
except exceptions.CancelledError:
|
| 317 |
+
if not self._closing:
|
| 318 |
+
raise
|
| 319 |
+
else:
|
| 320 |
+
if not self._paused:
|
| 321 |
+
self._read_fut.add_done_callback(self._loop_reading)
|
| 322 |
+
finally:
|
| 323 |
+
if length > -1:
|
| 324 |
+
self._data_received(data, length)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport,
|
| 328 |
+
transports.WriteTransport):
|
| 329 |
+
"""Transport for write pipes."""
|
| 330 |
+
|
| 331 |
+
_start_tls_compatible = True
|
| 332 |
+
|
| 333 |
+
def __init__(self, *args, **kw):
|
| 334 |
+
super().__init__(*args, **kw)
|
| 335 |
+
self._empty_waiter = None
|
| 336 |
+
|
| 337 |
+
def write(self, data):
|
| 338 |
+
if not isinstance(data, (bytes, bytearray, memoryview)):
|
| 339 |
+
raise TypeError(
|
| 340 |
+
f"data argument must be a bytes-like object, "
|
| 341 |
+
f"not {type(data).__name__}")
|
| 342 |
+
if self._eof_written:
|
| 343 |
+
raise RuntimeError('write_eof() already called')
|
| 344 |
+
if self._empty_waiter is not None:
|
| 345 |
+
raise RuntimeError('unable to write; sendfile is in progress')
|
| 346 |
+
|
| 347 |
+
if not data:
|
| 348 |
+
return
|
| 349 |
+
|
| 350 |
+
if self._conn_lost:
|
| 351 |
+
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
|
| 352 |
+
logger.warning('socket.send() raised exception.')
|
| 353 |
+
self._conn_lost += 1
|
| 354 |
+
return
|
| 355 |
+
|
| 356 |
+
# Observable states:
|
| 357 |
+
# 1. IDLE: _write_fut and _buffer both None
|
| 358 |
+
# 2. WRITING: _write_fut set; _buffer None
|
| 359 |
+
# 3. BACKED UP: _write_fut set; _buffer a bytearray
|
| 360 |
+
# We always copy the data, so the caller can't modify it
|
| 361 |
+
# while we're still waiting for the I/O to happen.
|
| 362 |
+
if self._write_fut is None: # IDLE -> WRITING
|
| 363 |
+
assert self._buffer is None
|
| 364 |
+
# Pass a copy, except if it's already immutable.
|
| 365 |
+
self._loop_writing(data=bytes(data))
|
| 366 |
+
elif not self._buffer: # WRITING -> BACKED UP
|
| 367 |
+
# Make a mutable copy which we can extend.
|
| 368 |
+
self._buffer = bytearray(data)
|
| 369 |
+
self._maybe_pause_protocol()
|
| 370 |
+
else: # BACKED UP
|
| 371 |
+
# Append to buffer (also copies).
|
| 372 |
+
self._buffer.extend(data)
|
| 373 |
+
self._maybe_pause_protocol()
|
| 374 |
+
|
| 375 |
+
def _loop_writing(self, f=None, data=None):
|
| 376 |
+
try:
|
| 377 |
+
if f is not None and self._write_fut is None and self._closing:
|
| 378 |
+
# XXX most likely self._force_close() has been called, and
|
| 379 |
+
# it has set self._write_fut to None.
|
| 380 |
+
return
|
| 381 |
+
assert f is self._write_fut
|
| 382 |
+
self._write_fut = None
|
| 383 |
+
self._pending_write = 0
|
| 384 |
+
if f:
|
| 385 |
+
f.result()
|
| 386 |
+
if data is None:
|
| 387 |
+
data = self._buffer
|
| 388 |
+
self._buffer = None
|
| 389 |
+
if not data:
|
| 390 |
+
if self._closing:
|
| 391 |
+
self._loop.call_soon(self._call_connection_lost, None)
|
| 392 |
+
if self._eof_written:
|
| 393 |
+
self._sock.shutdown(socket.SHUT_WR)
|
| 394 |
+
# Now that we've reduced the buffer size, tell the
|
| 395 |
+
# protocol to resume writing if it was paused. Note that
|
| 396 |
+
# we do this last since the callback is called immediately
|
| 397 |
+
# and it may add more data to the buffer (even causing the
|
| 398 |
+
# protocol to be paused again).
|
| 399 |
+
self._maybe_resume_protocol()
|
| 400 |
+
else:
|
| 401 |
+
self._write_fut = self._loop._proactor.send(self._sock, data)
|
| 402 |
+
if not self._write_fut.done():
|
| 403 |
+
assert self._pending_write == 0
|
| 404 |
+
self._pending_write = len(data)
|
| 405 |
+
self._write_fut.add_done_callback(self._loop_writing)
|
| 406 |
+
self._maybe_pause_protocol()
|
| 407 |
+
else:
|
| 408 |
+
self._write_fut.add_done_callback(self._loop_writing)
|
| 409 |
+
if self._empty_waiter is not None and self._write_fut is None:
|
| 410 |
+
self._empty_waiter.set_result(None)
|
| 411 |
+
except ConnectionResetError as exc:
|
| 412 |
+
self._force_close(exc)
|
| 413 |
+
except OSError as exc:
|
| 414 |
+
self._fatal_error(exc, 'Fatal write error on pipe transport')
|
| 415 |
+
|
| 416 |
+
def can_write_eof(self):
|
| 417 |
+
return True
|
| 418 |
+
|
| 419 |
+
def write_eof(self):
|
| 420 |
+
self.close()
|
| 421 |
+
|
| 422 |
+
def abort(self):
|
| 423 |
+
self._force_close(None)
|
| 424 |
+
|
| 425 |
+
def _make_empty_waiter(self):
|
| 426 |
+
if self._empty_waiter is not None:
|
| 427 |
+
raise RuntimeError("Empty waiter is already set")
|
| 428 |
+
self._empty_waiter = self._loop.create_future()
|
| 429 |
+
if self._write_fut is None:
|
| 430 |
+
self._empty_waiter.set_result(None)
|
| 431 |
+
return self._empty_waiter
|
| 432 |
+
|
| 433 |
+
def _reset_empty_waiter(self):
|
| 434 |
+
self._empty_waiter = None
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
class _ProactorWritePipeTransport(_ProactorBaseWritePipeTransport):
|
| 438 |
+
def __init__(self, *args, **kw):
|
| 439 |
+
super().__init__(*args, **kw)
|
| 440 |
+
self._read_fut = self._loop._proactor.recv(self._sock, 16)
|
| 441 |
+
self._read_fut.add_done_callback(self._pipe_closed)
|
| 442 |
+
|
| 443 |
+
def _pipe_closed(self, fut):
|
| 444 |
+
if fut.cancelled():
|
| 445 |
+
# the transport has been closed
|
| 446 |
+
return
|
| 447 |
+
assert fut.result() == b''
|
| 448 |
+
if self._closing:
|
| 449 |
+
assert self._read_fut is None
|
| 450 |
+
return
|
| 451 |
+
assert fut is self._read_fut, (fut, self._read_fut)
|
| 452 |
+
self._read_fut = None
|
| 453 |
+
if self._write_fut is not None:
|
| 454 |
+
self._force_close(BrokenPipeError())
|
| 455 |
+
else:
|
| 456 |
+
self.close()
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class _ProactorDatagramTransport(_ProactorBasePipeTransport,
|
| 460 |
+
transports.DatagramTransport):
|
| 461 |
+
max_size = 256 * 1024
|
| 462 |
+
def __init__(self, loop, sock, protocol, address=None,
|
| 463 |
+
waiter=None, extra=None):
|
| 464 |
+
self._address = address
|
| 465 |
+
self._empty_waiter = None
|
| 466 |
+
# We don't need to call _protocol.connection_made() since our base
|
| 467 |
+
# constructor does it for us.
|
| 468 |
+
super().__init__(loop, sock, protocol, waiter=waiter, extra=extra)
|
| 469 |
+
|
| 470 |
+
# The base constructor sets _buffer = None, so we set it here
|
| 471 |
+
self._buffer = collections.deque()
|
| 472 |
+
self._loop.call_soon(self._loop_reading)
|
| 473 |
+
|
| 474 |
+
def _set_extra(self, sock):
|
| 475 |
+
_set_socket_extra(self, sock)
|
| 476 |
+
|
| 477 |
+
def get_write_buffer_size(self):
|
| 478 |
+
return sum(len(data) for data, _ in self._buffer)
|
| 479 |
+
|
| 480 |
+
def abort(self):
|
| 481 |
+
self._force_close(None)
|
| 482 |
+
|
| 483 |
+
def sendto(self, data, addr=None):
|
| 484 |
+
if not isinstance(data, (bytes, bytearray, memoryview)):
|
| 485 |
+
raise TypeError('data argument must be bytes-like object (%r)',
|
| 486 |
+
type(data))
|
| 487 |
+
|
| 488 |
+
if not data:
|
| 489 |
+
return
|
| 490 |
+
|
| 491 |
+
if self._address is not None and addr not in (None, self._address):
|
| 492 |
+
raise ValueError(
|
| 493 |
+
f'Invalid address: must be None or {self._address}')
|
| 494 |
+
|
| 495 |
+
if self._conn_lost and self._address:
|
| 496 |
+
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
|
| 497 |
+
logger.warning('socket.sendto() raised exception.')
|
| 498 |
+
self._conn_lost += 1
|
| 499 |
+
return
|
| 500 |
+
|
| 501 |
+
# Ensure that what we buffer is immutable.
|
| 502 |
+
self._buffer.append((bytes(data), addr))
|
| 503 |
+
|
| 504 |
+
if self._write_fut is None:
|
| 505 |
+
# No current write operations are active, kick one off
|
| 506 |
+
self._loop_writing()
|
| 507 |
+
# else: A write operation is already kicked off
|
| 508 |
+
|
| 509 |
+
self._maybe_pause_protocol()
|
| 510 |
+
|
| 511 |
+
def _loop_writing(self, fut=None):
|
| 512 |
+
try:
|
| 513 |
+
if self._conn_lost:
|
| 514 |
+
return
|
| 515 |
+
|
| 516 |
+
assert fut is self._write_fut
|
| 517 |
+
self._write_fut = None
|
| 518 |
+
if fut:
|
| 519 |
+
# We are in a _loop_writing() done callback, get the result
|
| 520 |
+
fut.result()
|
| 521 |
+
|
| 522 |
+
if not self._buffer or (self._conn_lost and self._address):
|
| 523 |
+
# The connection has been closed
|
| 524 |
+
if self._closing:
|
| 525 |
+
self._loop.call_soon(self._call_connection_lost, None)
|
| 526 |
+
return
|
| 527 |
+
|
| 528 |
+
data, addr = self._buffer.popleft()
|
| 529 |
+
if self._address is not None:
|
| 530 |
+
self._write_fut = self._loop._proactor.send(self._sock,
|
| 531 |
+
data)
|
| 532 |
+
else:
|
| 533 |
+
self._write_fut = self._loop._proactor.sendto(self._sock,
|
| 534 |
+
data,
|
| 535 |
+
addr=addr)
|
| 536 |
+
except OSError as exc:
|
| 537 |
+
self._protocol.error_received(exc)
|
| 538 |
+
except Exception as exc:
|
| 539 |
+
self._fatal_error(exc, 'Fatal write error on datagram transport')
|
| 540 |
+
else:
|
| 541 |
+
self._write_fut.add_done_callback(self._loop_writing)
|
| 542 |
+
self._maybe_resume_protocol()
|
| 543 |
+
|
| 544 |
+
def _loop_reading(self, fut=None):
|
| 545 |
+
data = None
|
| 546 |
+
try:
|
| 547 |
+
if self._conn_lost:
|
| 548 |
+
return
|
| 549 |
+
|
| 550 |
+
assert self._read_fut is fut or (self._read_fut is None and
|
| 551 |
+
self._closing)
|
| 552 |
+
|
| 553 |
+
self._read_fut = None
|
| 554 |
+
if fut is not None:
|
| 555 |
+
res = fut.result()
|
| 556 |
+
|
| 557 |
+
if self._closing:
|
| 558 |
+
# since close() has been called we ignore any read data
|
| 559 |
+
data = None
|
| 560 |
+
return
|
| 561 |
+
|
| 562 |
+
if self._address is not None:
|
| 563 |
+
data, addr = res, self._address
|
| 564 |
+
else:
|
| 565 |
+
data, addr = res
|
| 566 |
+
|
| 567 |
+
if self._conn_lost:
|
| 568 |
+
return
|
| 569 |
+
if self._address is not None:
|
| 570 |
+
self._read_fut = self._loop._proactor.recv(self._sock,
|
| 571 |
+
self.max_size)
|
| 572 |
+
else:
|
| 573 |
+
self._read_fut = self._loop._proactor.recvfrom(self._sock,
|
| 574 |
+
self.max_size)
|
| 575 |
+
except OSError as exc:
|
| 576 |
+
self._protocol.error_received(exc)
|
| 577 |
+
except exceptions.CancelledError:
|
| 578 |
+
if not self._closing:
|
| 579 |
+
raise
|
| 580 |
+
else:
|
| 581 |
+
if self._read_fut is not None:
|
| 582 |
+
self._read_fut.add_done_callback(self._loop_reading)
|
| 583 |
+
finally:
|
| 584 |
+
if data:
|
| 585 |
+
self._protocol.datagram_received(data, addr)
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
class _ProactorDuplexPipeTransport(_ProactorReadPipeTransport,
|
| 589 |
+
_ProactorBaseWritePipeTransport,
|
| 590 |
+
transports.Transport):
|
| 591 |
+
"""Transport for duplex pipes."""
|
| 592 |
+
|
| 593 |
+
def can_write_eof(self):
|
| 594 |
+
return False
|
| 595 |
+
|
| 596 |
+
def write_eof(self):
|
| 597 |
+
raise NotImplementedError
|
| 598 |
+
|
| 599 |
+
|
| 600 |
+
class _ProactorSocketTransport(_ProactorReadPipeTransport,
|
| 601 |
+
_ProactorBaseWritePipeTransport,
|
| 602 |
+
transports.Transport):
|
| 603 |
+
"""Transport for connected sockets."""
|
| 604 |
+
|
| 605 |
+
_sendfile_compatible = constants._SendfileMode.TRY_NATIVE
|
| 606 |
+
|
| 607 |
+
def __init__(self, loop, sock, protocol, waiter=None,
|
| 608 |
+
extra=None, server=None):
|
| 609 |
+
super().__init__(loop, sock, protocol, waiter, extra, server)
|
| 610 |
+
base_events._set_nodelay(sock)
|
| 611 |
+
|
| 612 |
+
def _set_extra(self, sock):
|
| 613 |
+
_set_socket_extra(self, sock)
|
| 614 |
+
|
| 615 |
+
def can_write_eof(self):
|
| 616 |
+
return True
|
| 617 |
+
|
| 618 |
+
def write_eof(self):
|
| 619 |
+
if self._closing or self._eof_written:
|
| 620 |
+
return
|
| 621 |
+
self._eof_written = True
|
| 622 |
+
if self._write_fut is None:
|
| 623 |
+
self._sock.shutdown(socket.SHUT_WR)
|
| 624 |
+
|
| 625 |
+
|
| 626 |
+
class BaseProactorEventLoop(base_events.BaseEventLoop):
|
| 627 |
+
|
| 628 |
+
def __init__(self, proactor):
|
| 629 |
+
super().__init__()
|
| 630 |
+
logger.debug('Using proactor: %s', proactor.__class__.__name__)
|
| 631 |
+
self._proactor = proactor
|
| 632 |
+
self._selector = proactor # convenient alias
|
| 633 |
+
self._self_reading_future = None
|
| 634 |
+
self._accept_futures = {} # socket file descriptor => Future
|
| 635 |
+
proactor.set_loop(self)
|
| 636 |
+
self._make_self_pipe()
|
| 637 |
+
if threading.current_thread() is threading.main_thread():
|
| 638 |
+
# wakeup fd can only be installed to a file descriptor from the main thread
|
| 639 |
+
signal.set_wakeup_fd(self._csock.fileno())
|
| 640 |
+
|
| 641 |
+
def _make_socket_transport(self, sock, protocol, waiter=None,
|
| 642 |
+
extra=None, server=None):
|
| 643 |
+
return _ProactorSocketTransport(self, sock, protocol, waiter,
|
| 644 |
+
extra, server)
|
| 645 |
+
|
| 646 |
+
def _make_ssl_transport(
|
| 647 |
+
self, rawsock, protocol, sslcontext, waiter=None,
|
| 648 |
+
*, server_side=False, server_hostname=None,
|
| 649 |
+
extra=None, server=None,
|
| 650 |
+
ssl_handshake_timeout=None):
|
| 651 |
+
ssl_protocol = sslproto.SSLProtocol(
|
| 652 |
+
self, protocol, sslcontext, waiter,
|
| 653 |
+
server_side, server_hostname,
|
| 654 |
+
ssl_handshake_timeout=ssl_handshake_timeout)
|
| 655 |
+
_ProactorSocketTransport(self, rawsock, ssl_protocol,
|
| 656 |
+
extra=extra, server=server)
|
| 657 |
+
return ssl_protocol._app_transport
|
| 658 |
+
|
| 659 |
+
def _make_datagram_transport(self, sock, protocol,
|
| 660 |
+
address=None, waiter=None, extra=None):
|
| 661 |
+
return _ProactorDatagramTransport(self, sock, protocol, address,
|
| 662 |
+
waiter, extra)
|
| 663 |
+
|
| 664 |
+
def _make_duplex_pipe_transport(self, sock, protocol, waiter=None,
|
| 665 |
+
extra=None):
|
| 666 |
+
return _ProactorDuplexPipeTransport(self,
|
| 667 |
+
sock, protocol, waiter, extra)
|
| 668 |
+
|
| 669 |
+
def _make_read_pipe_transport(self, sock, protocol, waiter=None,
|
| 670 |
+
extra=None):
|
| 671 |
+
return _ProactorReadPipeTransport(self, sock, protocol, waiter, extra)
|
| 672 |
+
|
| 673 |
+
def _make_write_pipe_transport(self, sock, protocol, waiter=None,
|
| 674 |
+
extra=None):
|
| 675 |
+
# We want connection_lost() to be called when other end closes
|
| 676 |
+
return _ProactorWritePipeTransport(self,
|
| 677 |
+
sock, protocol, waiter, extra)
|
| 678 |
+
|
| 679 |
+
def close(self):
|
| 680 |
+
if self.is_running():
|
| 681 |
+
raise RuntimeError("Cannot close a running event loop")
|
| 682 |
+
if self.is_closed():
|
| 683 |
+
return
|
| 684 |
+
|
| 685 |
+
if threading.current_thread() is threading.main_thread():
|
| 686 |
+
signal.set_wakeup_fd(-1)
|
| 687 |
+
# Call these methods before closing the event loop (before calling
|
| 688 |
+
# BaseEventLoop.close), because they can schedule callbacks with
|
| 689 |
+
# call_soon(), which is forbidden when the event loop is closed.
|
| 690 |
+
self._stop_accept_futures()
|
| 691 |
+
self._close_self_pipe()
|
| 692 |
+
self._proactor.close()
|
| 693 |
+
self._proactor = None
|
| 694 |
+
self._selector = None
|
| 695 |
+
|
| 696 |
+
# Close the event loop
|
| 697 |
+
super().close()
|
| 698 |
+
|
| 699 |
+
async def sock_recv(self, sock, n):
|
| 700 |
+
return await self._proactor.recv(sock, n)
|
| 701 |
+
|
| 702 |
+
async def sock_recv_into(self, sock, buf):
|
| 703 |
+
return await self._proactor.recv_into(sock, buf)
|
| 704 |
+
|
| 705 |
+
async def sock_sendall(self, sock, data):
|
| 706 |
+
return await self._proactor.send(sock, data)
|
| 707 |
+
|
| 708 |
+
async def sock_connect(self, sock, address):
|
| 709 |
+
return await self._proactor.connect(sock, address)
|
| 710 |
+
|
| 711 |
+
async def sock_accept(self, sock):
|
| 712 |
+
return await self._proactor.accept(sock)
|
| 713 |
+
|
| 714 |
+
async def _sock_sendfile_native(self, sock, file, offset, count):
|
| 715 |
+
try:
|
| 716 |
+
fileno = file.fileno()
|
| 717 |
+
except (AttributeError, io.UnsupportedOperation) as err:
|
| 718 |
+
raise exceptions.SendfileNotAvailableError("not a regular file")
|
| 719 |
+
try:
|
| 720 |
+
fsize = os.fstat(fileno).st_size
|
| 721 |
+
except OSError:
|
| 722 |
+
raise exceptions.SendfileNotAvailableError("not a regular file")
|
| 723 |
+
blocksize = count if count else fsize
|
| 724 |
+
if not blocksize:
|
| 725 |
+
return 0 # empty file
|
| 726 |
+
|
| 727 |
+
blocksize = min(blocksize, 0xffff_ffff)
|
| 728 |
+
end_pos = min(offset + count, fsize) if count else fsize
|
| 729 |
+
offset = min(offset, fsize)
|
| 730 |
+
total_sent = 0
|
| 731 |
+
try:
|
| 732 |
+
while True:
|
| 733 |
+
blocksize = min(end_pos - offset, blocksize)
|
| 734 |
+
if blocksize <= 0:
|
| 735 |
+
return total_sent
|
| 736 |
+
await self._proactor.sendfile(sock, file, offset, blocksize)
|
| 737 |
+
offset += blocksize
|
| 738 |
+
total_sent += blocksize
|
| 739 |
+
finally:
|
| 740 |
+
if total_sent > 0:
|
| 741 |
+
file.seek(offset)
|
| 742 |
+
|
| 743 |
+
async def _sendfile_native(self, transp, file, offset, count):
|
| 744 |
+
resume_reading = transp.is_reading()
|
| 745 |
+
transp.pause_reading()
|
| 746 |
+
await transp._make_empty_waiter()
|
| 747 |
+
try:
|
| 748 |
+
return await self.sock_sendfile(transp._sock, file, offset, count,
|
| 749 |
+
fallback=False)
|
| 750 |
+
finally:
|
| 751 |
+
transp._reset_empty_waiter()
|
| 752 |
+
if resume_reading:
|
| 753 |
+
transp.resume_reading()
|
| 754 |
+
|
| 755 |
+
def _close_self_pipe(self):
|
| 756 |
+
if self._self_reading_future is not None:
|
| 757 |
+
self._self_reading_future.cancel()
|
| 758 |
+
self._self_reading_future = None
|
| 759 |
+
self._ssock.close()
|
| 760 |
+
self._ssock = None
|
| 761 |
+
self._csock.close()
|
| 762 |
+
self._csock = None
|
| 763 |
+
self._internal_fds -= 1
|
| 764 |
+
|
| 765 |
+
def _make_self_pipe(self):
|
| 766 |
+
# A self-socket, really. :-)
|
| 767 |
+
self._ssock, self._csock = socket.socketpair()
|
| 768 |
+
self._ssock.setblocking(False)
|
| 769 |
+
self._csock.setblocking(False)
|
| 770 |
+
self._internal_fds += 1
|
| 771 |
+
|
| 772 |
+
def _loop_self_reading(self, f=None):
|
| 773 |
+
try:
|
| 774 |
+
if f is not None:
|
| 775 |
+
f.result() # may raise
|
| 776 |
+
if self._self_reading_future is not f:
|
| 777 |
+
# When we scheduled this Future, we assigned it to
|
| 778 |
+
# _self_reading_future. If it's not there now, something has
|
| 779 |
+
# tried to cancel the loop while this callback was still in the
|
| 780 |
+
# queue (see windows_events.ProactorEventLoop.run_forever). In
|
| 781 |
+
# that case stop here instead of continuing to schedule a new
|
| 782 |
+
# iteration.
|
| 783 |
+
return
|
| 784 |
+
f = self._proactor.recv(self._ssock, 4096)
|
| 785 |
+
except exceptions.CancelledError:
|
| 786 |
+
# _close_self_pipe() has been called, stop waiting for data
|
| 787 |
+
return
|
| 788 |
+
except (SystemExit, KeyboardInterrupt):
|
| 789 |
+
raise
|
| 790 |
+
except BaseException as exc:
|
| 791 |
+
self.call_exception_handler({
|
| 792 |
+
'message': 'Error on reading from the event loop self pipe',
|
| 793 |
+
'exception': exc,
|
| 794 |
+
'loop': self,
|
| 795 |
+
})
|
| 796 |
+
else:
|
| 797 |
+
self._self_reading_future = f
|
| 798 |
+
f.add_done_callback(self._loop_self_reading)
|
| 799 |
+
|
| 800 |
+
def _write_to_self(self):
|
| 801 |
+
# This may be called from a different thread, possibly after
|
| 802 |
+
# _close_self_pipe() has been called or even while it is
|
| 803 |
+
# running. Guard for self._csock being None or closed. When
|
| 804 |
+
# a socket is closed, send() raises OSError (with errno set to
|
| 805 |
+
# EBADF, but let's not rely on the exact error code).
|
| 806 |
+
csock = self._csock
|
| 807 |
+
if csock is None:
|
| 808 |
+
return
|
| 809 |
+
|
| 810 |
+
try:
|
| 811 |
+
csock.send(b'\0')
|
| 812 |
+
except OSError:
|
| 813 |
+
if self._debug:
|
| 814 |
+
logger.debug("Fail to write a null byte into the "
|
| 815 |
+
"self-pipe socket",
|
| 816 |
+
exc_info=True)
|
| 817 |
+
|
| 818 |
+
def _start_serving(self, protocol_factory, sock,
|
| 819 |
+
sslcontext=None, server=None, backlog=100,
|
| 820 |
+
ssl_handshake_timeout=None):
|
| 821 |
+
|
| 822 |
+
def loop(f=None):
|
| 823 |
+
try:
|
| 824 |
+
if f is not None:
|
| 825 |
+
conn, addr = f.result()
|
| 826 |
+
if self._debug:
|
| 827 |
+
logger.debug("%r got a new connection from %r: %r",
|
| 828 |
+
server, addr, conn)
|
| 829 |
+
protocol = protocol_factory()
|
| 830 |
+
if sslcontext is not None:
|
| 831 |
+
self._make_ssl_transport(
|
| 832 |
+
conn, protocol, sslcontext, server_side=True,
|
| 833 |
+
extra={'peername': addr}, server=server,
|
| 834 |
+
ssl_handshake_timeout=ssl_handshake_timeout)
|
| 835 |
+
else:
|
| 836 |
+
self._make_socket_transport(
|
| 837 |
+
conn, protocol,
|
| 838 |
+
extra={'peername': addr}, server=server)
|
| 839 |
+
if self.is_closed():
|
| 840 |
+
return
|
| 841 |
+
f = self._proactor.accept(sock)
|
| 842 |
+
except OSError as exc:
|
| 843 |
+
if sock.fileno() != -1:
|
| 844 |
+
self.call_exception_handler({
|
| 845 |
+
'message': 'Accept failed on a socket',
|
| 846 |
+
'exception': exc,
|
| 847 |
+
'socket': trsock.TransportSocket(sock),
|
| 848 |
+
})
|
| 849 |
+
sock.close()
|
| 850 |
+
elif self._debug:
|
| 851 |
+
logger.debug("Accept failed on socket %r",
|
| 852 |
+
sock, exc_info=True)
|
| 853 |
+
except exceptions.CancelledError:
|
| 854 |
+
sock.close()
|
| 855 |
+
else:
|
| 856 |
+
self._accept_futures[sock.fileno()] = f
|
| 857 |
+
f.add_done_callback(loop)
|
| 858 |
+
|
| 859 |
+
self.call_soon(loop)
|
| 860 |
+
|
| 861 |
+
def _process_events(self, event_list):
|
| 862 |
+
# Events are processed in the IocpProactor._poll() method
|
| 863 |
+
pass
|
| 864 |
+
|
| 865 |
+
def _stop_accept_futures(self):
|
| 866 |
+
for future in self._accept_futures.values():
|
| 867 |
+
future.cancel()
|
| 868 |
+
self._accept_futures.clear()
|
| 869 |
+
|
| 870 |
+
def _stop_serving(self, sock):
|
| 871 |
+
future = self._accept_futures.pop(sock.fileno(), None)
|
| 872 |
+
if future:
|
| 873 |
+
future.cancel()
|
| 874 |
+
self._proactor._stop_serving(sock)
|
| 875 |
+
sock.close()
|
janus/lib/python3.10/asyncio/queues.py
ADDED
|
@@ -0,0 +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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ('Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty')
|
| 2 |
+
|
| 3 |
+
import collections
|
| 4 |
+
import heapq
|
| 5 |
+
from types import GenericAlias
|
| 6 |
+
|
| 7 |
+
from . import locks
|
| 8 |
+
from . import mixins
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class QueueEmpty(Exception):
|
| 12 |
+
"""Raised when Queue.get_nowait() is called on an empty Queue."""
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class QueueFull(Exception):
|
| 17 |
+
"""Raised when the Queue.put_nowait() method is called on a full Queue."""
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Queue(mixins._LoopBoundMixin):
|
| 22 |
+
"""A queue, useful for coordinating producer and consumer coroutines.
|
| 23 |
+
|
| 24 |
+
If maxsize is less than or equal to zero, the queue size is infinite. If it
|
| 25 |
+
is an integer greater than 0, then "await put()" will block when the
|
| 26 |
+
queue reaches maxsize, until an item is removed by get().
|
| 27 |
+
|
| 28 |
+
Unlike the standard library Queue, you can reliably know this Queue's size
|
| 29 |
+
with qsize(), since your single-threaded asyncio application won't be
|
| 30 |
+
interrupted between calling qsize() and doing an operation on the Queue.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
def __init__(self, maxsize=0, *, loop=mixins._marker):
|
| 34 |
+
super().__init__(loop=loop)
|
| 35 |
+
self._maxsize = maxsize
|
| 36 |
+
|
| 37 |
+
# Futures.
|
| 38 |
+
self._getters = collections.deque()
|
| 39 |
+
# Futures.
|
| 40 |
+
self._putters = collections.deque()
|
| 41 |
+
self._unfinished_tasks = 0
|
| 42 |
+
self._finished = locks.Event()
|
| 43 |
+
self._finished.set()
|
| 44 |
+
self._init(maxsize)
|
| 45 |
+
|
| 46 |
+
# These three are overridable in subclasses.
|
| 47 |
+
|
| 48 |
+
def _init(self, maxsize):
|
| 49 |
+
self._queue = collections.deque()
|
| 50 |
+
|
| 51 |
+
def _get(self):
|
| 52 |
+
return self._queue.popleft()
|
| 53 |
+
|
| 54 |
+
def _put(self, item):
|
| 55 |
+
self._queue.append(item)
|
| 56 |
+
|
| 57 |
+
# End of the overridable methods.
|
| 58 |
+
|
| 59 |
+
def _wakeup_next(self, waiters):
|
| 60 |
+
# Wake up the next waiter (if any) that isn't cancelled.
|
| 61 |
+
while waiters:
|
| 62 |
+
waiter = waiters.popleft()
|
| 63 |
+
if not waiter.done():
|
| 64 |
+
waiter.set_result(None)
|
| 65 |
+
break
|
| 66 |
+
|
| 67 |
+
def __repr__(self):
|
| 68 |
+
return f'<{type(self).__name__} at {id(self):#x} {self._format()}>'
|
| 69 |
+
|
| 70 |
+
def __str__(self):
|
| 71 |
+
return f'<{type(self).__name__} {self._format()}>'
|
| 72 |
+
|
| 73 |
+
__class_getitem__ = classmethod(GenericAlias)
|
| 74 |
+
|
| 75 |
+
def _format(self):
|
| 76 |
+
result = f'maxsize={self._maxsize!r}'
|
| 77 |
+
if getattr(self, '_queue', None):
|
| 78 |
+
result += f' _queue={list(self._queue)!r}'
|
| 79 |
+
if self._getters:
|
| 80 |
+
result += f' _getters[{len(self._getters)}]'
|
| 81 |
+
if self._putters:
|
| 82 |
+
result += f' _putters[{len(self._putters)}]'
|
| 83 |
+
if self._unfinished_tasks:
|
| 84 |
+
result += f' tasks={self._unfinished_tasks}'
|
| 85 |
+
return result
|
| 86 |
+
|
| 87 |
+
def qsize(self):
|
| 88 |
+
"""Number of items in the queue."""
|
| 89 |
+
return len(self._queue)
|
| 90 |
+
|
| 91 |
+
@property
|
| 92 |
+
def maxsize(self):
|
| 93 |
+
"""Number of items allowed in the queue."""
|
| 94 |
+
return self._maxsize
|
| 95 |
+
|
| 96 |
+
def empty(self):
|
| 97 |
+
"""Return True if the queue is empty, False otherwise."""
|
| 98 |
+
return not self._queue
|
| 99 |
+
|
| 100 |
+
def full(self):
|
| 101 |
+
"""Return True if there are maxsize items in the queue.
|
| 102 |
+
|
| 103 |
+
Note: if the Queue was initialized with maxsize=0 (the default),
|
| 104 |
+
then full() is never True.
|
| 105 |
+
"""
|
| 106 |
+
if self._maxsize <= 0:
|
| 107 |
+
return False
|
| 108 |
+
else:
|
| 109 |
+
return self.qsize() >= self._maxsize
|
| 110 |
+
|
| 111 |
+
async def put(self, item):
|
| 112 |
+
"""Put an item into the queue.
|
| 113 |
+
|
| 114 |
+
Put an item into the queue. If the queue is full, wait until a free
|
| 115 |
+
slot is available before adding item.
|
| 116 |
+
"""
|
| 117 |
+
while self.full():
|
| 118 |
+
putter = self._get_loop().create_future()
|
| 119 |
+
self._putters.append(putter)
|
| 120 |
+
try:
|
| 121 |
+
await putter
|
| 122 |
+
except:
|
| 123 |
+
putter.cancel() # Just in case putter is not done yet.
|
| 124 |
+
try:
|
| 125 |
+
# Clean self._putters from canceled putters.
|
| 126 |
+
self._putters.remove(putter)
|
| 127 |
+
except ValueError:
|
| 128 |
+
# The putter could be removed from self._putters by a
|
| 129 |
+
# previous get_nowait call.
|
| 130 |
+
pass
|
| 131 |
+
if not self.full() and not putter.cancelled():
|
| 132 |
+
# We were woken up by get_nowait(), but can't take
|
| 133 |
+
# the call. Wake up the next in line.
|
| 134 |
+
self._wakeup_next(self._putters)
|
| 135 |
+
raise
|
| 136 |
+
return self.put_nowait(item)
|
| 137 |
+
|
| 138 |
+
def put_nowait(self, item):
|
| 139 |
+
"""Put an item into the queue without blocking.
|
| 140 |
+
|
| 141 |
+
If no free slot is immediately available, raise QueueFull.
|
| 142 |
+
"""
|
| 143 |
+
if self.full():
|
| 144 |
+
raise QueueFull
|
| 145 |
+
self._put(item)
|
| 146 |
+
self._unfinished_tasks += 1
|
| 147 |
+
self._finished.clear()
|
| 148 |
+
self._wakeup_next(self._getters)
|
| 149 |
+
|
| 150 |
+
async def get(self):
|
| 151 |
+
"""Remove and return an item from the queue.
|
| 152 |
+
|
| 153 |
+
If queue is empty, wait until an item is available.
|
| 154 |
+
"""
|
| 155 |
+
while self.empty():
|
| 156 |
+
getter = self._get_loop().create_future()
|
| 157 |
+
self._getters.append(getter)
|
| 158 |
+
try:
|
| 159 |
+
await getter
|
| 160 |
+
except:
|
| 161 |
+
getter.cancel() # Just in case getter is not done yet.
|
| 162 |
+
try:
|
| 163 |
+
# Clean self._getters from canceled getters.
|
| 164 |
+
self._getters.remove(getter)
|
| 165 |
+
except ValueError:
|
| 166 |
+
# The getter could be removed from self._getters by a
|
| 167 |
+
# previous put_nowait call.
|
| 168 |
+
pass
|
| 169 |
+
if not self.empty() and not getter.cancelled():
|
| 170 |
+
# We were woken up by put_nowait(), but can't take
|
| 171 |
+
# the call. Wake up the next in line.
|
| 172 |
+
self._wakeup_next(self._getters)
|
| 173 |
+
raise
|
| 174 |
+
return self.get_nowait()
|
| 175 |
+
|
| 176 |
+
def get_nowait(self):
|
| 177 |
+
"""Remove and return an item from the queue.
|
| 178 |
+
|
| 179 |
+
Return an item if one is immediately available, else raise QueueEmpty.
|
| 180 |
+
"""
|
| 181 |
+
if self.empty():
|
| 182 |
+
raise QueueEmpty
|
| 183 |
+
item = self._get()
|
| 184 |
+
self._wakeup_next(self._putters)
|
| 185 |
+
return item
|
| 186 |
+
|
| 187 |
+
def task_done(self):
|
| 188 |
+
"""Indicate that a formerly enqueued task is complete.
|
| 189 |
+
|
| 190 |
+
Used by queue consumers. For each get() used to fetch a task,
|
| 191 |
+
a subsequent call to task_done() tells the queue that the processing
|
| 192 |
+
on the task is complete.
|
| 193 |
+
|
| 194 |
+
If a join() is currently blocking, it will resume when all items have
|
| 195 |
+
been processed (meaning that a task_done() call was received for every
|
| 196 |
+
item that had been put() into the queue).
|
| 197 |
+
|
| 198 |
+
Raises ValueError if called more times than there were items placed in
|
| 199 |
+
the queue.
|
| 200 |
+
"""
|
| 201 |
+
if self._unfinished_tasks <= 0:
|
| 202 |
+
raise ValueError('task_done() called too many times')
|
| 203 |
+
self._unfinished_tasks -= 1
|
| 204 |
+
if self._unfinished_tasks == 0:
|
| 205 |
+
self._finished.set()
|
| 206 |
+
|
| 207 |
+
async def join(self):
|
| 208 |
+
"""Block until all items in the queue have been gotten and processed.
|
| 209 |
+
|
| 210 |
+
The count of unfinished tasks goes up whenever an item is added to the
|
| 211 |
+
queue. The count goes down whenever a consumer calls task_done() to
|
| 212 |
+
indicate that the item was retrieved and all work on it is complete.
|
| 213 |
+
When the count of unfinished tasks drops to zero, join() unblocks.
|
| 214 |
+
"""
|
| 215 |
+
if self._unfinished_tasks > 0:
|
| 216 |
+
await self._finished.wait()
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
class PriorityQueue(Queue):
|
| 220 |
+
"""A subclass of Queue; retrieves entries in priority order (lowest first).
|
| 221 |
+
|
| 222 |
+
Entries are typically tuples of the form: (priority number, data).
|
| 223 |
+
"""
|
| 224 |
+
|
| 225 |
+
def _init(self, maxsize):
|
| 226 |
+
self._queue = []
|
| 227 |
+
|
| 228 |
+
def _put(self, item, heappush=heapq.heappush):
|
| 229 |
+
heappush(self._queue, item)
|
| 230 |
+
|
| 231 |
+
def _get(self, heappop=heapq.heappop):
|
| 232 |
+
return heappop(self._queue)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class LifoQueue(Queue):
|
| 236 |
+
"""A subclass of Queue that retrieves most recently added entries first."""
|
| 237 |
+
|
| 238 |
+
def _init(self, maxsize):
|
| 239 |
+
self._queue = []
|
| 240 |
+
|
| 241 |
+
def _put(self, item):
|
| 242 |
+
self._queue.append(item)
|
| 243 |
+
|
| 244 |
+
def _get(self):
|
| 245 |
+
return self._queue.pop()
|
janus/lib/python3.10/asyncio/runners.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = 'run',
|
| 2 |
+
|
| 3 |
+
from . import coroutines
|
| 4 |
+
from . import events
|
| 5 |
+
from . import tasks
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def run(main, *, debug=None):
|
| 9 |
+
"""Execute the coroutine and return the result.
|
| 10 |
+
|
| 11 |
+
This function runs the passed coroutine, taking care of
|
| 12 |
+
managing the asyncio event loop and finalizing asynchronous
|
| 13 |
+
generators.
|
| 14 |
+
|
| 15 |
+
This function cannot be called when another asyncio event loop is
|
| 16 |
+
running in the same thread.
|
| 17 |
+
|
| 18 |
+
If debug is True, the event loop will be run in debug mode.
|
| 19 |
+
|
| 20 |
+
This function always creates a new event loop and closes it at the end.
|
| 21 |
+
It should be used as a main entry point for asyncio programs, and should
|
| 22 |
+
ideally only be called once.
|
| 23 |
+
|
| 24 |
+
Example:
|
| 25 |
+
|
| 26 |
+
async def main():
|
| 27 |
+
await asyncio.sleep(1)
|
| 28 |
+
print('hello')
|
| 29 |
+
|
| 30 |
+
asyncio.run(main())
|
| 31 |
+
"""
|
| 32 |
+
if events._get_running_loop() is not None:
|
| 33 |
+
raise RuntimeError(
|
| 34 |
+
"asyncio.run() cannot be called from a running event loop")
|
| 35 |
+
|
| 36 |
+
if not coroutines.iscoroutine(main):
|
| 37 |
+
raise ValueError("a coroutine was expected, got {!r}".format(main))
|
| 38 |
+
|
| 39 |
+
loop = events.new_event_loop()
|
| 40 |
+
try:
|
| 41 |
+
events.set_event_loop(loop)
|
| 42 |
+
if debug is not None:
|
| 43 |
+
loop.set_debug(debug)
|
| 44 |
+
return loop.run_until_complete(main)
|
| 45 |
+
finally:
|
| 46 |
+
try:
|
| 47 |
+
_cancel_all_tasks(loop)
|
| 48 |
+
loop.run_until_complete(loop.shutdown_asyncgens())
|
| 49 |
+
loop.run_until_complete(loop.shutdown_default_executor())
|
| 50 |
+
finally:
|
| 51 |
+
events.set_event_loop(None)
|
| 52 |
+
loop.close()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _cancel_all_tasks(loop):
|
| 56 |
+
to_cancel = tasks.all_tasks(loop)
|
| 57 |
+
if not to_cancel:
|
| 58 |
+
return
|
| 59 |
+
|
| 60 |
+
for task in to_cancel:
|
| 61 |
+
task.cancel()
|
| 62 |
+
|
| 63 |
+
loop.run_until_complete(tasks.gather(*to_cancel, return_exceptions=True))
|
| 64 |
+
|
| 65 |
+
for task in to_cancel:
|
| 66 |
+
if task.cancelled():
|
| 67 |
+
continue
|
| 68 |
+
if task.exception() is not None:
|
| 69 |
+
loop.call_exception_handler({
|
| 70 |
+
'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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
import warnings
|
| 3 |
+
try:
|
| 4 |
+
import ssl
|
| 5 |
+
except ImportError: # pragma: no cover
|
| 6 |
+
ssl = None
|
| 7 |
+
|
| 8 |
+
from . import constants
|
| 9 |
+
from . import protocols
|
| 10 |
+
from . import transports
|
| 11 |
+
from .log import logger
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _create_transport_context(server_side, server_hostname):
|
| 15 |
+
if server_side:
|
| 16 |
+
raise ValueError('Server side SSL needs a valid SSLContext')
|
| 17 |
+
|
| 18 |
+
# Client side may pass ssl=True to use a default
|
| 19 |
+
# context; in that case the sslcontext passed is None.
|
| 20 |
+
# The default is secure for client connections.
|
| 21 |
+
# Python 3.4+: use up-to-date strong settings.
|
| 22 |
+
sslcontext = ssl.create_default_context()
|
| 23 |
+
if not server_hostname:
|
| 24 |
+
sslcontext.check_hostname = False
|
| 25 |
+
return sslcontext
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# States of an _SSLPipe.
|
| 29 |
+
_UNWRAPPED = "UNWRAPPED"
|
| 30 |
+
_DO_HANDSHAKE = "DO_HANDSHAKE"
|
| 31 |
+
_WRAPPED = "WRAPPED"
|
| 32 |
+
_SHUTDOWN = "SHUTDOWN"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class _SSLPipe(object):
|
| 36 |
+
"""An SSL "Pipe".
|
| 37 |
+
|
| 38 |
+
An SSL pipe allows you to communicate with an SSL/TLS protocol instance
|
| 39 |
+
through memory buffers. It can be used to implement a security layer for an
|
| 40 |
+
existing connection where you don't have access to the connection's file
|
| 41 |
+
descriptor, or for some reason you don't want to use it.
|
| 42 |
+
|
| 43 |
+
An SSL pipe can be in "wrapped" and "unwrapped" mode. In unwrapped mode,
|
| 44 |
+
data is passed through untransformed. In wrapped mode, application level
|
| 45 |
+
data is encrypted to SSL record level data and vice versa. The SSL record
|
| 46 |
+
level is the lowest level in the SSL protocol suite and is what travels
|
| 47 |
+
as-is over the wire.
|
| 48 |
+
|
| 49 |
+
An SslPipe initially is in "unwrapped" mode. To start SSL, call
|
| 50 |
+
do_handshake(). To shutdown SSL again, call unwrap().
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
max_size = 256 * 1024 # Buffer size passed to read()
|
| 54 |
+
|
| 55 |
+
def __init__(self, context, server_side, server_hostname=None):
|
| 56 |
+
"""
|
| 57 |
+
The *context* argument specifies the ssl.SSLContext to use.
|
| 58 |
+
|
| 59 |
+
The *server_side* argument indicates whether this is a server side or
|
| 60 |
+
client side transport.
|
| 61 |
+
|
| 62 |
+
The optional *server_hostname* argument can be used to specify the
|
| 63 |
+
hostname you are connecting to. You may only specify this parameter if
|
| 64 |
+
the _ssl module supports Server Name Indication (SNI).
|
| 65 |
+
"""
|
| 66 |
+
self._context = context
|
| 67 |
+
self._server_side = server_side
|
| 68 |
+
self._server_hostname = server_hostname
|
| 69 |
+
self._state = _UNWRAPPED
|
| 70 |
+
self._incoming = ssl.MemoryBIO()
|
| 71 |
+
self._outgoing = ssl.MemoryBIO()
|
| 72 |
+
self._sslobj = None
|
| 73 |
+
self._need_ssldata = False
|
| 74 |
+
self._handshake_cb = None
|
| 75 |
+
self._shutdown_cb = None
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def context(self):
|
| 79 |
+
"""The SSL context passed to the constructor."""
|
| 80 |
+
return self._context
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def ssl_object(self):
|
| 84 |
+
"""The internal ssl.SSLObject instance.
|
| 85 |
+
|
| 86 |
+
Return None if the pipe is not wrapped.
|
| 87 |
+
"""
|
| 88 |
+
return self._sslobj
|
| 89 |
+
|
| 90 |
+
@property
|
| 91 |
+
def need_ssldata(self):
|
| 92 |
+
"""Whether more record level data is needed to complete a handshake
|
| 93 |
+
that is currently in progress."""
|
| 94 |
+
return self._need_ssldata
|
| 95 |
+
|
| 96 |
+
@property
|
| 97 |
+
def wrapped(self):
|
| 98 |
+
"""
|
| 99 |
+
Whether a security layer is currently in effect.
|
| 100 |
+
|
| 101 |
+
Return False during handshake.
|
| 102 |
+
"""
|
| 103 |
+
return self._state == _WRAPPED
|
| 104 |
+
|
| 105 |
+
def do_handshake(self, callback=None):
|
| 106 |
+
"""Start the SSL handshake.
|
| 107 |
+
|
| 108 |
+
Return a list of ssldata. A ssldata element is a list of buffers
|
| 109 |
+
|
| 110 |
+
The optional *callback* argument can be used to install a callback that
|
| 111 |
+
will be called when the handshake is complete. The callback will be
|
| 112 |
+
called with None if successful, else an exception instance.
|
| 113 |
+
"""
|
| 114 |
+
if self._state != _UNWRAPPED:
|
| 115 |
+
raise RuntimeError('handshake in progress or completed')
|
| 116 |
+
self._sslobj = self._context.wrap_bio(
|
| 117 |
+
self._incoming, self._outgoing,
|
| 118 |
+
server_side=self._server_side,
|
| 119 |
+
server_hostname=self._server_hostname)
|
| 120 |
+
self._state = _DO_HANDSHAKE
|
| 121 |
+
self._handshake_cb = callback
|
| 122 |
+
ssldata, appdata = self.feed_ssldata(b'', only_handshake=True)
|
| 123 |
+
assert len(appdata) == 0
|
| 124 |
+
return ssldata
|
| 125 |
+
|
| 126 |
+
def shutdown(self, callback=None):
|
| 127 |
+
"""Start the SSL shutdown sequence.
|
| 128 |
+
|
| 129 |
+
Return a list of ssldata. A ssldata element is a list of buffers
|
| 130 |
+
|
| 131 |
+
The optional *callback* argument can be used to install a callback that
|
| 132 |
+
will be called when the shutdown is complete. The callback will be
|
| 133 |
+
called without arguments.
|
| 134 |
+
"""
|
| 135 |
+
if self._state == _UNWRAPPED:
|
| 136 |
+
raise RuntimeError('no security layer present')
|
| 137 |
+
if self._state == _SHUTDOWN:
|
| 138 |
+
raise RuntimeError('shutdown in progress')
|
| 139 |
+
assert self._state in (_WRAPPED, _DO_HANDSHAKE)
|
| 140 |
+
self._state = _SHUTDOWN
|
| 141 |
+
self._shutdown_cb = callback
|
| 142 |
+
ssldata, appdata = self.feed_ssldata(b'')
|
| 143 |
+
assert appdata == [] or appdata == [b'']
|
| 144 |
+
return ssldata
|
| 145 |
+
|
| 146 |
+
def feed_eof(self):
|
| 147 |
+
"""Send a potentially "ragged" EOF.
|
| 148 |
+
|
| 149 |
+
This method will raise an SSL_ERROR_EOF exception if the EOF is
|
| 150 |
+
unexpected.
|
| 151 |
+
"""
|
| 152 |
+
self._incoming.write_eof()
|
| 153 |
+
ssldata, appdata = self.feed_ssldata(b'')
|
| 154 |
+
assert appdata == [] or appdata == [b'']
|
| 155 |
+
|
| 156 |
+
def feed_ssldata(self, data, only_handshake=False):
|
| 157 |
+
"""Feed SSL record level data into the pipe.
|
| 158 |
+
|
| 159 |
+
The data must be a bytes instance. It is OK to send an empty bytes
|
| 160 |
+
instance. This can be used to get ssldata for a handshake initiated by
|
| 161 |
+
this endpoint.
|
| 162 |
+
|
| 163 |
+
Return a (ssldata, appdata) tuple. The ssldata element is a list of
|
| 164 |
+
buffers containing SSL data that needs to be sent to the remote SSL.
|
| 165 |
+
|
| 166 |
+
The appdata element is a list of buffers containing plaintext data that
|
| 167 |
+
needs to be forwarded to the application. The appdata list may contain
|
| 168 |
+
an empty buffer indicating an SSL "close_notify" alert. This alert must
|
| 169 |
+
be acknowledged by calling shutdown().
|
| 170 |
+
"""
|
| 171 |
+
if self._state == _UNWRAPPED:
|
| 172 |
+
# If unwrapped, pass plaintext data straight through.
|
| 173 |
+
if data:
|
| 174 |
+
appdata = [data]
|
| 175 |
+
else:
|
| 176 |
+
appdata = []
|
| 177 |
+
return ([], appdata)
|
| 178 |
+
|
| 179 |
+
self._need_ssldata = False
|
| 180 |
+
if data:
|
| 181 |
+
self._incoming.write(data)
|
| 182 |
+
|
| 183 |
+
ssldata = []
|
| 184 |
+
appdata = []
|
| 185 |
+
try:
|
| 186 |
+
if self._state == _DO_HANDSHAKE:
|
| 187 |
+
# Call do_handshake() until it doesn't raise anymore.
|
| 188 |
+
self._sslobj.do_handshake()
|
| 189 |
+
self._state = _WRAPPED
|
| 190 |
+
if self._handshake_cb:
|
| 191 |
+
self._handshake_cb(None)
|
| 192 |
+
if only_handshake:
|
| 193 |
+
return (ssldata, appdata)
|
| 194 |
+
# Handshake done: execute the wrapped block
|
| 195 |
+
|
| 196 |
+
if self._state == _WRAPPED:
|
| 197 |
+
# Main state: read data from SSL until close_notify
|
| 198 |
+
while True:
|
| 199 |
+
chunk = self._sslobj.read(self.max_size)
|
| 200 |
+
appdata.append(chunk)
|
| 201 |
+
if not chunk: # close_notify
|
| 202 |
+
break
|
| 203 |
+
|
| 204 |
+
elif self._state == _SHUTDOWN:
|
| 205 |
+
# Call shutdown() until it doesn't raise anymore.
|
| 206 |
+
self._sslobj.unwrap()
|
| 207 |
+
self._sslobj = None
|
| 208 |
+
self._state = _UNWRAPPED
|
| 209 |
+
if self._shutdown_cb:
|
| 210 |
+
self._shutdown_cb()
|
| 211 |
+
|
| 212 |
+
elif self._state == _UNWRAPPED:
|
| 213 |
+
# Drain possible plaintext data after close_notify.
|
| 214 |
+
appdata.append(self._incoming.read())
|
| 215 |
+
except (ssl.SSLError, ssl.CertificateError) as exc:
|
| 216 |
+
exc_errno = getattr(exc, 'errno', None)
|
| 217 |
+
if exc_errno not in (
|
| 218 |
+
ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE,
|
| 219 |
+
ssl.SSL_ERROR_SYSCALL):
|
| 220 |
+
if self._state == _DO_HANDSHAKE and self._handshake_cb:
|
| 221 |
+
self._handshake_cb(exc)
|
| 222 |
+
raise
|
| 223 |
+
self._need_ssldata = (exc_errno == ssl.SSL_ERROR_WANT_READ)
|
| 224 |
+
|
| 225 |
+
# Check for record level data that needs to be sent back.
|
| 226 |
+
# Happens for the initial handshake and renegotiations.
|
| 227 |
+
if self._outgoing.pending:
|
| 228 |
+
ssldata.append(self._outgoing.read())
|
| 229 |
+
return (ssldata, appdata)
|
| 230 |
+
|
| 231 |
+
def feed_appdata(self, data, offset=0):
|
| 232 |
+
"""Feed plaintext data into the pipe.
|
| 233 |
+
|
| 234 |
+
Return an (ssldata, offset) tuple. The ssldata element is a list of
|
| 235 |
+
buffers containing record level data that needs to be sent to the
|
| 236 |
+
remote SSL instance. The offset is the number of plaintext bytes that
|
| 237 |
+
were processed, which may be less than the length of data.
|
| 238 |
+
|
| 239 |
+
NOTE: In case of short writes, this call MUST be retried with the SAME
|
| 240 |
+
buffer passed into the *data* argument (i.e. the id() must be the
|
| 241 |
+
same). This is an OpenSSL requirement. A further particularity is that
|
| 242 |
+
a short write will always have offset == 0, because the _ssl module
|
| 243 |
+
does not enable partial writes. And even though the offset is zero,
|
| 244 |
+
there will still be encrypted data in ssldata.
|
| 245 |
+
"""
|
| 246 |
+
assert 0 <= offset <= len(data)
|
| 247 |
+
if self._state == _UNWRAPPED:
|
| 248 |
+
# pass through data in unwrapped mode
|
| 249 |
+
if offset < len(data):
|
| 250 |
+
ssldata = [data[offset:]]
|
| 251 |
+
else:
|
| 252 |
+
ssldata = []
|
| 253 |
+
return (ssldata, len(data))
|
| 254 |
+
|
| 255 |
+
ssldata = []
|
| 256 |
+
view = memoryview(data)
|
| 257 |
+
while True:
|
| 258 |
+
self._need_ssldata = False
|
| 259 |
+
try:
|
| 260 |
+
if offset < len(view):
|
| 261 |
+
offset += self._sslobj.write(view[offset:])
|
| 262 |
+
except ssl.SSLError as exc:
|
| 263 |
+
# It is not allowed to call write() after unwrap() until the
|
| 264 |
+
# close_notify is acknowledged. We return the condition to the
|
| 265 |
+
# caller as a short write.
|
| 266 |
+
exc_errno = getattr(exc, 'errno', None)
|
| 267 |
+
if exc.reason == 'PROTOCOL_IS_SHUTDOWN':
|
| 268 |
+
exc_errno = exc.errno = ssl.SSL_ERROR_WANT_READ
|
| 269 |
+
if exc_errno not in (ssl.SSL_ERROR_WANT_READ,
|
| 270 |
+
ssl.SSL_ERROR_WANT_WRITE,
|
| 271 |
+
ssl.SSL_ERROR_SYSCALL):
|
| 272 |
+
raise
|
| 273 |
+
self._need_ssldata = (exc_errno == ssl.SSL_ERROR_WANT_READ)
|
| 274 |
+
|
| 275 |
+
# See if there's any record level data back for us.
|
| 276 |
+
if self._outgoing.pending:
|
| 277 |
+
ssldata.append(self._outgoing.read())
|
| 278 |
+
if offset == len(view) or self._need_ssldata:
|
| 279 |
+
break
|
| 280 |
+
return (ssldata, offset)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class _SSLProtocolTransport(transports._FlowControlMixin,
|
| 284 |
+
transports.Transport):
|
| 285 |
+
|
| 286 |
+
_sendfile_compatible = constants._SendfileMode.FALLBACK
|
| 287 |
+
|
| 288 |
+
def __init__(self, loop, ssl_protocol):
|
| 289 |
+
self._loop = loop
|
| 290 |
+
# SSLProtocol instance
|
| 291 |
+
self._ssl_protocol = ssl_protocol
|
| 292 |
+
self._closed = False
|
| 293 |
+
|
| 294 |
+
def get_extra_info(self, name, default=None):
|
| 295 |
+
"""Get optional transport information."""
|
| 296 |
+
return self._ssl_protocol._get_extra_info(name, default)
|
| 297 |
+
|
| 298 |
+
def set_protocol(self, protocol):
|
| 299 |
+
self._ssl_protocol._set_app_protocol(protocol)
|
| 300 |
+
|
| 301 |
+
def get_protocol(self):
|
| 302 |
+
return self._ssl_protocol._app_protocol
|
| 303 |
+
|
| 304 |
+
def is_closing(self):
|
| 305 |
+
return self._closed
|
| 306 |
+
|
| 307 |
+
def close(self):
|
| 308 |
+
"""Close the transport.
|
| 309 |
+
|
| 310 |
+
Buffered data will be flushed asynchronously. No more data
|
| 311 |
+
will be received. After all buffered data is flushed, the
|
| 312 |
+
protocol's connection_lost() method will (eventually) called
|
| 313 |
+
with None as its argument.
|
| 314 |
+
"""
|
| 315 |
+
self._closed = True
|
| 316 |
+
self._ssl_protocol._start_shutdown()
|
| 317 |
+
|
| 318 |
+
def __del__(self, _warn=warnings.warn):
|
| 319 |
+
if not self._closed:
|
| 320 |
+
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
|
| 321 |
+
self.close()
|
| 322 |
+
|
| 323 |
+
def is_reading(self):
|
| 324 |
+
tr = self._ssl_protocol._transport
|
| 325 |
+
if tr is None:
|
| 326 |
+
raise RuntimeError('SSL transport has not been initialized yet')
|
| 327 |
+
return tr.is_reading()
|
| 328 |
+
|
| 329 |
+
def pause_reading(self):
|
| 330 |
+
"""Pause the receiving end.
|
| 331 |
+
|
| 332 |
+
No data will be passed to the protocol's data_received()
|
| 333 |
+
method until resume_reading() is called.
|
| 334 |
+
"""
|
| 335 |
+
self._ssl_protocol._transport.pause_reading()
|
| 336 |
+
|
| 337 |
+
def resume_reading(self):
|
| 338 |
+
"""Resume the receiving end.
|
| 339 |
+
|
| 340 |
+
Data received will once again be passed to the protocol's
|
| 341 |
+
data_received() method.
|
| 342 |
+
"""
|
| 343 |
+
self._ssl_protocol._transport.resume_reading()
|
| 344 |
+
|
| 345 |
+
def set_write_buffer_limits(self, high=None, low=None):
|
| 346 |
+
"""Set the high- and low-water limits for write flow control.
|
| 347 |
+
|
| 348 |
+
These two values control when to call the protocol's
|
| 349 |
+
pause_writing() and resume_writing() methods. If specified,
|
| 350 |
+
the low-water limit must be less than or equal to the
|
| 351 |
+
high-water limit. Neither value can be negative.
|
| 352 |
+
|
| 353 |
+
The defaults are implementation-specific. If only the
|
| 354 |
+
high-water limit is given, the low-water limit defaults to an
|
| 355 |
+
implementation-specific value less than or equal to the
|
| 356 |
+
high-water limit. Setting high to zero forces low to zero as
|
| 357 |
+
well, and causes pause_writing() to be called whenever the
|
| 358 |
+
buffer becomes non-empty. Setting low to zero causes
|
| 359 |
+
resume_writing() to be called only once the buffer is empty.
|
| 360 |
+
Use of zero for either limit is generally sub-optimal as it
|
| 361 |
+
reduces opportunities for doing I/O and computation
|
| 362 |
+
concurrently.
|
| 363 |
+
"""
|
| 364 |
+
self._ssl_protocol._transport.set_write_buffer_limits(high, low)
|
| 365 |
+
|
| 366 |
+
def get_write_buffer_size(self):
|
| 367 |
+
"""Return the current size of the write buffer."""
|
| 368 |
+
return self._ssl_protocol._transport.get_write_buffer_size()
|
| 369 |
+
|
| 370 |
+
def get_write_buffer_limits(self):
|
| 371 |
+
"""Get the high and low watermarks for write flow control.
|
| 372 |
+
Return a tuple (low, high) where low and high are
|
| 373 |
+
positive number of bytes."""
|
| 374 |
+
return self._ssl_protocol._transport.get_write_buffer_limits()
|
| 375 |
+
|
| 376 |
+
@property
|
| 377 |
+
def _protocol_paused(self):
|
| 378 |
+
# Required for sendfile fallback pause_writing/resume_writing logic
|
| 379 |
+
return self._ssl_protocol._transport._protocol_paused
|
| 380 |
+
|
| 381 |
+
def write(self, data):
|
| 382 |
+
"""Write some data bytes to the transport.
|
| 383 |
+
|
| 384 |
+
This does not block; it buffers the data and arranges for it
|
| 385 |
+
to be sent out asynchronously.
|
| 386 |
+
"""
|
| 387 |
+
if not isinstance(data, (bytes, bytearray, memoryview)):
|
| 388 |
+
raise TypeError(f"data: expecting a bytes-like instance, "
|
| 389 |
+
f"got {type(data).__name__}")
|
| 390 |
+
if not data:
|
| 391 |
+
return
|
| 392 |
+
self._ssl_protocol._write_appdata(data)
|
| 393 |
+
|
| 394 |
+
def can_write_eof(self):
|
| 395 |
+
"""Return True if this transport supports write_eof(), False if not."""
|
| 396 |
+
return False
|
| 397 |
+
|
| 398 |
+
def abort(self):
|
| 399 |
+
"""Close the transport immediately.
|
| 400 |
+
|
| 401 |
+
Buffered data will be lost. No more data will be received.
|
| 402 |
+
The protocol's connection_lost() method will (eventually) be
|
| 403 |
+
called with None as its argument.
|
| 404 |
+
"""
|
| 405 |
+
self._ssl_protocol._abort()
|
| 406 |
+
self._closed = True
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
class SSLProtocol(protocols.Protocol):
|
| 410 |
+
"""SSL protocol.
|
| 411 |
+
|
| 412 |
+
Implementation of SSL on top of a socket using incoming and outgoing
|
| 413 |
+
buffers which are ssl.MemoryBIO objects.
|
| 414 |
+
"""
|
| 415 |
+
|
| 416 |
+
def __init__(self, loop, app_protocol, sslcontext, waiter,
|
| 417 |
+
server_side=False, server_hostname=None,
|
| 418 |
+
call_connection_made=True,
|
| 419 |
+
ssl_handshake_timeout=None):
|
| 420 |
+
if ssl is None:
|
| 421 |
+
raise RuntimeError('stdlib ssl module not available')
|
| 422 |
+
|
| 423 |
+
if ssl_handshake_timeout is None:
|
| 424 |
+
ssl_handshake_timeout = constants.SSL_HANDSHAKE_TIMEOUT
|
| 425 |
+
elif ssl_handshake_timeout <= 0:
|
| 426 |
+
raise ValueError(
|
| 427 |
+
f"ssl_handshake_timeout should be a positive number, "
|
| 428 |
+
f"got {ssl_handshake_timeout}")
|
| 429 |
+
|
| 430 |
+
if not sslcontext:
|
| 431 |
+
sslcontext = _create_transport_context(
|
| 432 |
+
server_side, server_hostname)
|
| 433 |
+
|
| 434 |
+
self._server_side = server_side
|
| 435 |
+
if server_hostname and not server_side:
|
| 436 |
+
self._server_hostname = server_hostname
|
| 437 |
+
else:
|
| 438 |
+
self._server_hostname = None
|
| 439 |
+
self._sslcontext = sslcontext
|
| 440 |
+
# SSL-specific extra info. More info are set when the handshake
|
| 441 |
+
# completes.
|
| 442 |
+
self._extra = dict(sslcontext=sslcontext)
|
| 443 |
+
|
| 444 |
+
# App data write buffering
|
| 445 |
+
self._write_backlog = collections.deque()
|
| 446 |
+
self._write_buffer_size = 0
|
| 447 |
+
|
| 448 |
+
self._waiter = waiter
|
| 449 |
+
self._loop = loop
|
| 450 |
+
self._set_app_protocol(app_protocol)
|
| 451 |
+
self._app_transport = _SSLProtocolTransport(self._loop, self)
|
| 452 |
+
# _SSLPipe instance (None until the connection is made)
|
| 453 |
+
self._sslpipe = None
|
| 454 |
+
self._session_established = False
|
| 455 |
+
self._in_handshake = False
|
| 456 |
+
self._in_shutdown = False
|
| 457 |
+
# transport, ex: SelectorSocketTransport
|
| 458 |
+
self._transport = None
|
| 459 |
+
self._call_connection_made = call_connection_made
|
| 460 |
+
self._ssl_handshake_timeout = ssl_handshake_timeout
|
| 461 |
+
|
| 462 |
+
def _set_app_protocol(self, app_protocol):
|
| 463 |
+
self._app_protocol = app_protocol
|
| 464 |
+
self._app_protocol_is_buffer = \
|
| 465 |
+
isinstance(app_protocol, protocols.BufferedProtocol)
|
| 466 |
+
|
| 467 |
+
def _wakeup_waiter(self, exc=None):
|
| 468 |
+
if self._waiter is None:
|
| 469 |
+
return
|
| 470 |
+
if not self._waiter.cancelled():
|
| 471 |
+
if exc is not None:
|
| 472 |
+
self._waiter.set_exception(exc)
|
| 473 |
+
else:
|
| 474 |
+
self._waiter.set_result(None)
|
| 475 |
+
self._waiter = None
|
| 476 |
+
|
| 477 |
+
def connection_made(self, transport):
|
| 478 |
+
"""Called when the low-level connection is made.
|
| 479 |
+
|
| 480 |
+
Start the SSL handshake.
|
| 481 |
+
"""
|
| 482 |
+
self._transport = transport
|
| 483 |
+
self._sslpipe = _SSLPipe(self._sslcontext,
|
| 484 |
+
self._server_side,
|
| 485 |
+
self._server_hostname)
|
| 486 |
+
self._start_handshake()
|
| 487 |
+
|
| 488 |
+
def connection_lost(self, exc):
|
| 489 |
+
"""Called when the low-level connection is lost or closed.
|
| 490 |
+
|
| 491 |
+
The argument is an exception object or None (the latter
|
| 492 |
+
meaning a regular EOF is received or the connection was
|
| 493 |
+
aborted or closed).
|
| 494 |
+
"""
|
| 495 |
+
if self._session_established:
|
| 496 |
+
self._session_established = False
|
| 497 |
+
self._loop.call_soon(self._app_protocol.connection_lost, exc)
|
| 498 |
+
else:
|
| 499 |
+
# Most likely an exception occurred while in SSL handshake.
|
| 500 |
+
# Just mark the app transport as closed so that its __del__
|
| 501 |
+
# doesn't complain.
|
| 502 |
+
if self._app_transport is not None:
|
| 503 |
+
self._app_transport._closed = True
|
| 504 |
+
self._transport = None
|
| 505 |
+
self._app_transport = None
|
| 506 |
+
if getattr(self, '_handshake_timeout_handle', None):
|
| 507 |
+
self._handshake_timeout_handle.cancel()
|
| 508 |
+
self._wakeup_waiter(exc)
|
| 509 |
+
self._app_protocol = None
|
| 510 |
+
self._sslpipe = None
|
| 511 |
+
|
| 512 |
+
def pause_writing(self):
|
| 513 |
+
"""Called when the low-level transport's buffer goes over
|
| 514 |
+
the high-water mark.
|
| 515 |
+
"""
|
| 516 |
+
self._app_protocol.pause_writing()
|
| 517 |
+
|
| 518 |
+
def resume_writing(self):
|
| 519 |
+
"""Called when the low-level transport's buffer drains below
|
| 520 |
+
the low-water mark.
|
| 521 |
+
"""
|
| 522 |
+
self._app_protocol.resume_writing()
|
| 523 |
+
|
| 524 |
+
def data_received(self, data):
|
| 525 |
+
"""Called when some SSL data is received.
|
| 526 |
+
|
| 527 |
+
The argument is a bytes object.
|
| 528 |
+
"""
|
| 529 |
+
if self._sslpipe is None:
|
| 530 |
+
# transport closing, sslpipe is destroyed
|
| 531 |
+
return
|
| 532 |
+
|
| 533 |
+
try:
|
| 534 |
+
ssldata, appdata = self._sslpipe.feed_ssldata(data)
|
| 535 |
+
except (SystemExit, KeyboardInterrupt):
|
| 536 |
+
raise
|
| 537 |
+
except BaseException as e:
|
| 538 |
+
self._fatal_error(e, 'SSL error in data received')
|
| 539 |
+
return
|
| 540 |
+
|
| 541 |
+
for chunk in ssldata:
|
| 542 |
+
self._transport.write(chunk)
|
| 543 |
+
|
| 544 |
+
for chunk in appdata:
|
| 545 |
+
if chunk:
|
| 546 |
+
try:
|
| 547 |
+
if self._app_protocol_is_buffer:
|
| 548 |
+
protocols._feed_data_to_buffered_proto(
|
| 549 |
+
self._app_protocol, chunk)
|
| 550 |
+
else:
|
| 551 |
+
self._app_protocol.data_received(chunk)
|
| 552 |
+
except (SystemExit, KeyboardInterrupt):
|
| 553 |
+
raise
|
| 554 |
+
except BaseException as ex:
|
| 555 |
+
self._fatal_error(
|
| 556 |
+
ex, 'application protocol failed to receive SSL data')
|
| 557 |
+
return
|
| 558 |
+
else:
|
| 559 |
+
self._start_shutdown()
|
| 560 |
+
break
|
| 561 |
+
|
| 562 |
+
def eof_received(self):
|
| 563 |
+
"""Called when the other end of the low-level stream
|
| 564 |
+
is half-closed.
|
| 565 |
+
|
| 566 |
+
If this returns a false value (including None), the transport
|
| 567 |
+
will close itself. If it returns a true value, closing the
|
| 568 |
+
transport is up to the protocol.
|
| 569 |
+
"""
|
| 570 |
+
try:
|
| 571 |
+
if self._loop.get_debug():
|
| 572 |
+
logger.debug("%r received EOF", self)
|
| 573 |
+
|
| 574 |
+
self._wakeup_waiter(ConnectionResetError)
|
| 575 |
+
|
| 576 |
+
if not self._in_handshake:
|
| 577 |
+
keep_open = self._app_protocol.eof_received()
|
| 578 |
+
if keep_open:
|
| 579 |
+
logger.warning('returning true from eof_received() '
|
| 580 |
+
'has no effect when using ssl')
|
| 581 |
+
finally:
|
| 582 |
+
self._transport.close()
|
| 583 |
+
|
| 584 |
+
def _get_extra_info(self, name, default=None):
|
| 585 |
+
if name in self._extra:
|
| 586 |
+
return self._extra[name]
|
| 587 |
+
elif self._transport is not None:
|
| 588 |
+
return self._transport.get_extra_info(name, default)
|
| 589 |
+
else:
|
| 590 |
+
return default
|
| 591 |
+
|
| 592 |
+
def _start_shutdown(self):
|
| 593 |
+
if self._in_shutdown:
|
| 594 |
+
return
|
| 595 |
+
if self._in_handshake:
|
| 596 |
+
self._abort()
|
| 597 |
+
else:
|
| 598 |
+
self._in_shutdown = True
|
| 599 |
+
self._write_appdata(b'')
|
| 600 |
+
|
| 601 |
+
def _write_appdata(self, data):
|
| 602 |
+
self._write_backlog.append((data, 0))
|
| 603 |
+
self._write_buffer_size += len(data)
|
| 604 |
+
self._process_write_backlog()
|
| 605 |
+
|
| 606 |
+
def _start_handshake(self):
|
| 607 |
+
if self._loop.get_debug():
|
| 608 |
+
logger.debug("%r starts SSL handshake", self)
|
| 609 |
+
self._handshake_start_time = self._loop.time()
|
| 610 |
+
else:
|
| 611 |
+
self._handshake_start_time = None
|
| 612 |
+
self._in_handshake = True
|
| 613 |
+
# (b'', 1) is a special value in _process_write_backlog() to do
|
| 614 |
+
# the SSL handshake
|
| 615 |
+
self._write_backlog.append((b'', 1))
|
| 616 |
+
self._handshake_timeout_handle = \
|
| 617 |
+
self._loop.call_later(self._ssl_handshake_timeout,
|
| 618 |
+
self._check_handshake_timeout)
|
| 619 |
+
self._process_write_backlog()
|
| 620 |
+
|
| 621 |
+
def _check_handshake_timeout(self):
|
| 622 |
+
if self._in_handshake is True:
|
| 623 |
+
msg = (
|
| 624 |
+
f"SSL handshake is taking longer than "
|
| 625 |
+
f"{self._ssl_handshake_timeout} seconds: "
|
| 626 |
+
f"aborting the connection"
|
| 627 |
+
)
|
| 628 |
+
self._fatal_error(ConnectionAbortedError(msg))
|
| 629 |
+
|
| 630 |
+
def _on_handshake_complete(self, handshake_exc):
|
| 631 |
+
self._in_handshake = False
|
| 632 |
+
self._handshake_timeout_handle.cancel()
|
| 633 |
+
|
| 634 |
+
sslobj = self._sslpipe.ssl_object
|
| 635 |
+
try:
|
| 636 |
+
if handshake_exc is not None:
|
| 637 |
+
raise handshake_exc
|
| 638 |
+
|
| 639 |
+
peercert = sslobj.getpeercert()
|
| 640 |
+
except (SystemExit, KeyboardInterrupt):
|
| 641 |
+
raise
|
| 642 |
+
except BaseException as exc:
|
| 643 |
+
if isinstance(exc, ssl.CertificateError):
|
| 644 |
+
msg = 'SSL handshake failed on verifying the certificate'
|
| 645 |
+
else:
|
| 646 |
+
msg = 'SSL handshake failed'
|
| 647 |
+
self._fatal_error(exc, msg)
|
| 648 |
+
return
|
| 649 |
+
|
| 650 |
+
if self._loop.get_debug():
|
| 651 |
+
dt = self._loop.time() - self._handshake_start_time
|
| 652 |
+
logger.debug("%r: SSL handshake took %.1f ms", self, dt * 1e3)
|
| 653 |
+
|
| 654 |
+
# Add extra info that becomes available after handshake.
|
| 655 |
+
self._extra.update(peercert=peercert,
|
| 656 |
+
cipher=sslobj.cipher(),
|
| 657 |
+
compression=sslobj.compression(),
|
| 658 |
+
ssl_object=sslobj,
|
| 659 |
+
)
|
| 660 |
+
if self._call_connection_made:
|
| 661 |
+
self._app_protocol.connection_made(self._app_transport)
|
| 662 |
+
self._wakeup_waiter()
|
| 663 |
+
self._session_established = True
|
| 664 |
+
# In case transport.write() was already called. Don't call
|
| 665 |
+
# immediately _process_write_backlog(), but schedule it:
|
| 666 |
+
# _on_handshake_complete() can be called indirectly from
|
| 667 |
+
# _process_write_backlog(), and _process_write_backlog() is not
|
| 668 |
+
# reentrant.
|
| 669 |
+
self._loop.call_soon(self._process_write_backlog)
|
| 670 |
+
|
| 671 |
+
def _process_write_backlog(self):
|
| 672 |
+
# Try to make progress on the write backlog.
|
| 673 |
+
if self._transport is None or self._sslpipe is None:
|
| 674 |
+
return
|
| 675 |
+
|
| 676 |
+
try:
|
| 677 |
+
for i in range(len(self._write_backlog)):
|
| 678 |
+
data, offset = self._write_backlog[0]
|
| 679 |
+
if data:
|
| 680 |
+
ssldata, offset = self._sslpipe.feed_appdata(data, offset)
|
| 681 |
+
elif offset:
|
| 682 |
+
ssldata = self._sslpipe.do_handshake(
|
| 683 |
+
self._on_handshake_complete)
|
| 684 |
+
offset = 1
|
| 685 |
+
else:
|
| 686 |
+
ssldata = self._sslpipe.shutdown(self._finalize)
|
| 687 |
+
offset = 1
|
| 688 |
+
|
| 689 |
+
for chunk in ssldata:
|
| 690 |
+
self._transport.write(chunk)
|
| 691 |
+
|
| 692 |
+
if offset < len(data):
|
| 693 |
+
self._write_backlog[0] = (data, offset)
|
| 694 |
+
# A short write means that a write is blocked on a read
|
| 695 |
+
# We need to enable reading if it is paused!
|
| 696 |
+
assert self._sslpipe.need_ssldata
|
| 697 |
+
if self._transport._paused:
|
| 698 |
+
self._transport.resume_reading()
|
| 699 |
+
break
|
| 700 |
+
|
| 701 |
+
# An entire chunk from the backlog was processed. We can
|
| 702 |
+
# delete it and reduce the outstanding buffer size.
|
| 703 |
+
del self._write_backlog[0]
|
| 704 |
+
self._write_buffer_size -= len(data)
|
| 705 |
+
except (SystemExit, KeyboardInterrupt):
|
| 706 |
+
raise
|
| 707 |
+
except BaseException as exc:
|
| 708 |
+
if self._in_handshake:
|
| 709 |
+
# Exceptions will be re-raised in _on_handshake_complete.
|
| 710 |
+
self._on_handshake_complete(exc)
|
| 711 |
+
else:
|
| 712 |
+
self._fatal_error(exc, 'Fatal error on SSL transport')
|
| 713 |
+
|
| 714 |
+
def _fatal_error(self, exc, message='Fatal error on transport'):
|
| 715 |
+
if isinstance(exc, OSError):
|
| 716 |
+
if self._loop.get_debug():
|
| 717 |
+
logger.debug("%r: %s", self, message, exc_info=True)
|
| 718 |
+
else:
|
| 719 |
+
self._loop.call_exception_handler({
|
| 720 |
+
'message': message,
|
| 721 |
+
'exception': exc,
|
| 722 |
+
'transport': self._transport,
|
| 723 |
+
'protocol': self,
|
| 724 |
+
})
|
| 725 |
+
if self._transport:
|
| 726 |
+
self._transport._force_close(exc)
|
| 727 |
+
|
| 728 |
+
def _finalize(self):
|
| 729 |
+
self._sslpipe = None
|
| 730 |
+
|
| 731 |
+
if self._transport is not None:
|
| 732 |
+
self._transport.close()
|
| 733 |
+
|
| 734 |
+
def _abort(self):
|
| 735 |
+
try:
|
| 736 |
+
if self._transport is not None:
|
| 737 |
+
self._transport.abort()
|
| 738 |
+
finally:
|
| 739 |
+
self._finalize()
|
janus/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 |
+
import contextlib
|
| 6 |
+
import typing
|
| 7 |
+
|
| 8 |
+
from . import events
|
| 9 |
+
from . import exceptions as exceptions_mod
|
| 10 |
+
from . import locks
|
| 11 |
+
from . import tasks
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
async def staggered_race(
|
| 15 |
+
coro_fns: typing.Iterable[typing.Callable[[], typing.Awaitable]],
|
| 16 |
+
delay: typing.Optional[float],
|
| 17 |
+
*,
|
| 18 |
+
loop: events.AbstractEventLoop = None,
|
| 19 |
+
) -> typing.Tuple[
|
| 20 |
+
typing.Any,
|
| 21 |
+
typing.Optional[int],
|
| 22 |
+
typing.List[typing.Optional[Exception]]
|
| 23 |
+
]:
|
| 24 |
+
"""Run coroutines with staggered start times and take the first to finish.
|
| 25 |
+
|
| 26 |
+
This method takes an iterable of coroutine functions. The first one is
|
| 27 |
+
started immediately. From then on, whenever the immediately preceding one
|
| 28 |
+
fails (raises an exception), or when *delay* seconds has passed, the next
|
| 29 |
+
coroutine is started. This continues until one of the coroutines complete
|
| 30 |
+
successfully, in which case all others are cancelled, or until all
|
| 31 |
+
coroutines fail.
|
| 32 |
+
|
| 33 |
+
The coroutines provided should be well-behaved in the following way:
|
| 34 |
+
|
| 35 |
+
* They should only ``return`` if completed successfully.
|
| 36 |
+
|
| 37 |
+
* They should always raise an exception if they did not complete
|
| 38 |
+
successfully. In particular, if they handle cancellation, they should
|
| 39 |
+
probably reraise, like this::
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
# do work
|
| 43 |
+
except asyncio.CancelledError:
|
| 44 |
+
# undo partially completed work
|
| 45 |
+
raise
|
| 46 |
+
|
| 47 |
+
Args:
|
| 48 |
+
coro_fns: an iterable of coroutine functions, i.e. callables that
|
| 49 |
+
return a coroutine object when called. Use ``functools.partial`` or
|
| 50 |
+
lambdas to pass arguments.
|
| 51 |
+
|
| 52 |
+
delay: amount of time, in seconds, between starting coroutines. If
|
| 53 |
+
``None``, the coroutines will run sequentially.
|
| 54 |
+
|
| 55 |
+
loop: the event loop to use.
|
| 56 |
+
|
| 57 |
+
Returns:
|
| 58 |
+
tuple *(winner_result, winner_index, exceptions)* where
|
| 59 |
+
|
| 60 |
+
- *winner_result*: the result of the winning coroutine, or ``None``
|
| 61 |
+
if no coroutines won.
|
| 62 |
+
|
| 63 |
+
- *winner_index*: the index of the winning coroutine in
|
| 64 |
+
``coro_fns``, or ``None`` if no coroutines won. If the winning
|
| 65 |
+
coroutine may return None on success, *winner_index* can be used
|
| 66 |
+
to definitively determine whether any coroutine won.
|
| 67 |
+
|
| 68 |
+
- *exceptions*: list of exceptions returned by the coroutines.
|
| 69 |
+
``len(exceptions)`` is equal to the number of coroutines actually
|
| 70 |
+
started, and the order is the same as in ``coro_fns``. The winning
|
| 71 |
+
coroutine's entry is ``None``.
|
| 72 |
+
|
| 73 |
+
"""
|
| 74 |
+
# TODO: when we have aiter() and anext(), allow async iterables in coro_fns.
|
| 75 |
+
loop = loop or events.get_running_loop()
|
| 76 |
+
enum_coro_fns = enumerate(coro_fns)
|
| 77 |
+
winner_result = None
|
| 78 |
+
winner_index = None
|
| 79 |
+
exceptions = []
|
| 80 |
+
running_tasks = []
|
| 81 |
+
|
| 82 |
+
async def run_one_coro(
|
| 83 |
+
previous_failed: typing.Optional[locks.Event]) -> None:
|
| 84 |
+
# Wait for the previous task to finish, or for delay seconds
|
| 85 |
+
if previous_failed is not None:
|
| 86 |
+
with contextlib.suppress(exceptions_mod.TimeoutError):
|
| 87 |
+
# Use asyncio.wait_for() instead of asyncio.wait() here, so
|
| 88 |
+
# that if we get cancelled at this point, Event.wait() is also
|
| 89 |
+
# cancelled, otherwise there will be a "Task destroyed but it is
|
| 90 |
+
# pending" later.
|
| 91 |
+
await tasks.wait_for(previous_failed.wait(), delay)
|
| 92 |
+
# Get the next coroutine to run
|
| 93 |
+
try:
|
| 94 |
+
this_index, coro_fn = next(enum_coro_fns)
|
| 95 |
+
except StopIteration:
|
| 96 |
+
return
|
| 97 |
+
# Start task that will run the next coroutine
|
| 98 |
+
this_failed = locks.Event()
|
| 99 |
+
next_task = loop.create_task(run_one_coro(this_failed))
|
| 100 |
+
running_tasks.append(next_task)
|
| 101 |
+
assert len(running_tasks) == this_index + 2
|
| 102 |
+
# Prepare place to put this coroutine's exceptions if not won
|
| 103 |
+
exceptions.append(None)
|
| 104 |
+
assert len(exceptions) == this_index + 1
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
result = await coro_fn()
|
| 108 |
+
except (SystemExit, KeyboardInterrupt):
|
| 109 |
+
raise
|
| 110 |
+
except BaseException as e:
|
| 111 |
+
exceptions[this_index] = e
|
| 112 |
+
this_failed.set() # Kickstart the next coroutine
|
| 113 |
+
else:
|
| 114 |
+
# Store winner's results
|
| 115 |
+
nonlocal winner_index, winner_result
|
| 116 |
+
assert winner_index is None
|
| 117 |
+
winner_index = this_index
|
| 118 |
+
winner_result = result
|
| 119 |
+
# Cancel all other tasks. We take care to not cancel the current
|
| 120 |
+
# task as well. If we do so, then since there is no `await` after
|
| 121 |
+
# here and CancelledError are usually thrown at one, we will
|
| 122 |
+
# encounter a curious corner case where the current task will end
|
| 123 |
+
# up as done() == True, cancelled() == False, exception() ==
|
| 124 |
+
# asyncio.CancelledError. This behavior is specified in
|
| 125 |
+
# https://bugs.python.org/issue30048
|
| 126 |
+
for i, t in enumerate(running_tasks):
|
| 127 |
+
if i != this_index:
|
| 128 |
+
t.cancel()
|
| 129 |
+
|
| 130 |
+
first_task = loop.create_task(run_one_coro(None))
|
| 131 |
+
running_tasks.append(first_task)
|
| 132 |
+
try:
|
| 133 |
+
# Wait for a growing list of tasks to all finish: poor man's version of
|
| 134 |
+
# curio's TaskGroup or trio's nursery
|
| 135 |
+
done_count = 0
|
| 136 |
+
while done_count != len(running_tasks):
|
| 137 |
+
done, _ = await tasks.wait(running_tasks)
|
| 138 |
+
done_count = len(done)
|
| 139 |
+
# If run_one_coro raises an unhandled exception, it's probably a
|
| 140 |
+
# programming error, and I want to see it.
|
| 141 |
+
if __debug__:
|
| 142 |
+
for d in done:
|
| 143 |
+
if d.done() and not d.cancelled() and d.exception():
|
| 144 |
+
raise d.exception()
|
| 145 |
+
return winner_result, winner_index, exceptions
|
| 146 |
+
finally:
|
| 147 |
+
# Make sure no tasks are left running if we leave this function
|
| 148 |
+
for t in running_tasks:
|
| 149 |
+
t.cancel()
|
janus/lib/python3.10/asyncio/streams.py
ADDED
|
@@ -0,0 +1,726 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = (
|
| 2 |
+
'StreamReader', 'StreamWriter', 'StreamReaderProtocol',
|
| 3 |
+
'open_connection', 'start_server')
|
| 4 |
+
|
| 5 |
+
import collections
|
| 6 |
+
import socket
|
| 7 |
+
import sys
|
| 8 |
+
import warnings
|
| 9 |
+
import weakref
|
| 10 |
+
|
| 11 |
+
if hasattr(socket, 'AF_UNIX'):
|
| 12 |
+
__all__ += ('open_unix_connection', 'start_unix_server')
|
| 13 |
+
|
| 14 |
+
from . import coroutines
|
| 15 |
+
from . import events
|
| 16 |
+
from . import exceptions
|
| 17 |
+
from . import format_helpers
|
| 18 |
+
from . import protocols
|
| 19 |
+
from .log import logger
|
| 20 |
+
from .tasks import sleep
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_DEFAULT_LIMIT = 2 ** 16 # 64 KiB
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
async def open_connection(host=None, port=None, *,
|
| 27 |
+
limit=_DEFAULT_LIMIT, **kwds):
|
| 28 |
+
"""A wrapper for create_connection() returning a (reader, writer) pair.
|
| 29 |
+
|
| 30 |
+
The reader returned is a StreamReader instance; the writer is a
|
| 31 |
+
StreamWriter instance.
|
| 32 |
+
|
| 33 |
+
The arguments are all the usual arguments to create_connection()
|
| 34 |
+
except protocol_factory; most common are positional host and port,
|
| 35 |
+
with various optional keyword arguments following.
|
| 36 |
+
|
| 37 |
+
Additional optional keyword arguments are loop (to set the event loop
|
| 38 |
+
instance to use) and limit (to set the buffer limit passed to the
|
| 39 |
+
StreamReader).
|
| 40 |
+
|
| 41 |
+
(If you want to customize the StreamReader and/or
|
| 42 |
+
StreamReaderProtocol classes, just copy the code -- there's
|
| 43 |
+
really nothing special here except some convenience.)
|
| 44 |
+
"""
|
| 45 |
+
loop = events.get_running_loop()
|
| 46 |
+
reader = StreamReader(limit=limit, loop=loop)
|
| 47 |
+
protocol = StreamReaderProtocol(reader, loop=loop)
|
| 48 |
+
transport, _ = await loop.create_connection(
|
| 49 |
+
lambda: protocol, host, port, **kwds)
|
| 50 |
+
writer = StreamWriter(transport, protocol, reader, loop)
|
| 51 |
+
return reader, writer
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
async def start_server(client_connected_cb, host=None, port=None, *,
|
| 55 |
+
limit=_DEFAULT_LIMIT, **kwds):
|
| 56 |
+
"""Start a socket server, call back for each client connected.
|
| 57 |
+
|
| 58 |
+
The first parameter, `client_connected_cb`, takes two parameters:
|
| 59 |
+
client_reader, client_writer. client_reader is a StreamReader
|
| 60 |
+
object, while client_writer is a StreamWriter object. This
|
| 61 |
+
parameter can either be a plain callback function or a coroutine;
|
| 62 |
+
if it is a coroutine, it will be automatically converted into a
|
| 63 |
+
Task.
|
| 64 |
+
|
| 65 |
+
The rest of the arguments are all the usual arguments to
|
| 66 |
+
loop.create_server() except protocol_factory; most common are
|
| 67 |
+
positional host and port, with various optional keyword arguments
|
| 68 |
+
following. The return value is the same as loop.create_server().
|
| 69 |
+
|
| 70 |
+
Additional optional keyword arguments are loop (to set the event loop
|
| 71 |
+
instance to use) and limit (to set the buffer limit passed to the
|
| 72 |
+
StreamReader).
|
| 73 |
+
|
| 74 |
+
The return value is the same as loop.create_server(), i.e. a
|
| 75 |
+
Server object which can be used to stop the service.
|
| 76 |
+
"""
|
| 77 |
+
loop = events.get_running_loop()
|
| 78 |
+
|
| 79 |
+
def factory():
|
| 80 |
+
reader = StreamReader(limit=limit, loop=loop)
|
| 81 |
+
protocol = StreamReaderProtocol(reader, client_connected_cb,
|
| 82 |
+
loop=loop)
|
| 83 |
+
return protocol
|
| 84 |
+
|
| 85 |
+
return await loop.create_server(factory, host, port, **kwds)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if hasattr(socket, 'AF_UNIX'):
|
| 89 |
+
# UNIX Domain Sockets are supported on this platform
|
| 90 |
+
|
| 91 |
+
async def open_unix_connection(path=None, *,
|
| 92 |
+
limit=_DEFAULT_LIMIT, **kwds):
|
| 93 |
+
"""Similar to `open_connection` but works with UNIX Domain Sockets."""
|
| 94 |
+
loop = events.get_running_loop()
|
| 95 |
+
|
| 96 |
+
reader = StreamReader(limit=limit, loop=loop)
|
| 97 |
+
protocol = StreamReaderProtocol(reader, loop=loop)
|
| 98 |
+
transport, _ = await loop.create_unix_connection(
|
| 99 |
+
lambda: protocol, path, **kwds)
|
| 100 |
+
writer = StreamWriter(transport, protocol, reader, loop)
|
| 101 |
+
return reader, writer
|
| 102 |
+
|
| 103 |
+
async def start_unix_server(client_connected_cb, path=None, *,
|
| 104 |
+
limit=_DEFAULT_LIMIT, **kwds):
|
| 105 |
+
"""Similar to `start_server` but works with UNIX Domain Sockets."""
|
| 106 |
+
loop = events.get_running_loop()
|
| 107 |
+
|
| 108 |
+
def factory():
|
| 109 |
+
reader = StreamReader(limit=limit, loop=loop)
|
| 110 |
+
protocol = StreamReaderProtocol(reader, client_connected_cb,
|
| 111 |
+
loop=loop)
|
| 112 |
+
return protocol
|
| 113 |
+
|
| 114 |
+
return await loop.create_unix_server(factory, path, **kwds)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class FlowControlMixin(protocols.Protocol):
|
| 118 |
+
"""Reusable flow control logic for StreamWriter.drain().
|
| 119 |
+
|
| 120 |
+
This implements the protocol methods pause_writing(),
|
| 121 |
+
resume_writing() and connection_lost(). If the subclass overrides
|
| 122 |
+
these it must call the super methods.
|
| 123 |
+
|
| 124 |
+
StreamWriter.drain() must wait for _drain_helper() coroutine.
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
def __init__(self, loop=None):
|
| 128 |
+
if loop is None:
|
| 129 |
+
self._loop = events._get_event_loop(stacklevel=4)
|
| 130 |
+
else:
|
| 131 |
+
self._loop = loop
|
| 132 |
+
self._paused = False
|
| 133 |
+
self._drain_waiters = collections.deque()
|
| 134 |
+
self._connection_lost = False
|
| 135 |
+
|
| 136 |
+
def pause_writing(self):
|
| 137 |
+
assert not self._paused
|
| 138 |
+
self._paused = True
|
| 139 |
+
if self._loop.get_debug():
|
| 140 |
+
logger.debug("%r pauses writing", self)
|
| 141 |
+
|
| 142 |
+
def resume_writing(self):
|
| 143 |
+
assert self._paused
|
| 144 |
+
self._paused = False
|
| 145 |
+
if self._loop.get_debug():
|
| 146 |
+
logger.debug("%r resumes writing", self)
|
| 147 |
+
|
| 148 |
+
for waiter in self._drain_waiters:
|
| 149 |
+
if not waiter.done():
|
| 150 |
+
waiter.set_result(None)
|
| 151 |
+
|
| 152 |
+
def connection_lost(self, exc):
|
| 153 |
+
self._connection_lost = True
|
| 154 |
+
# Wake up the writer(s) if currently paused.
|
| 155 |
+
if not self._paused:
|
| 156 |
+
return
|
| 157 |
+
|
| 158 |
+
for waiter in self._drain_waiters:
|
| 159 |
+
if not waiter.done():
|
| 160 |
+
if exc is None:
|
| 161 |
+
waiter.set_result(None)
|
| 162 |
+
else:
|
| 163 |
+
waiter.set_exception(exc)
|
| 164 |
+
|
| 165 |
+
async def _drain_helper(self):
|
| 166 |
+
if self._connection_lost:
|
| 167 |
+
raise ConnectionResetError('Connection lost')
|
| 168 |
+
if not self._paused:
|
| 169 |
+
return
|
| 170 |
+
waiter = self._loop.create_future()
|
| 171 |
+
self._drain_waiters.append(waiter)
|
| 172 |
+
try:
|
| 173 |
+
await waiter
|
| 174 |
+
finally:
|
| 175 |
+
self._drain_waiters.remove(waiter)
|
| 176 |
+
|
| 177 |
+
def _get_close_waiter(self, stream):
|
| 178 |
+
raise NotImplementedError
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
|
| 182 |
+
"""Helper class to adapt between Protocol and StreamReader.
|
| 183 |
+
|
| 184 |
+
(This is a helper class instead of making StreamReader itself a
|
| 185 |
+
Protocol subclass, because the StreamReader has other potential
|
| 186 |
+
uses, and to prevent the user of the StreamReader to accidentally
|
| 187 |
+
call inappropriate methods of the protocol.)
|
| 188 |
+
"""
|
| 189 |
+
|
| 190 |
+
_source_traceback = None
|
| 191 |
+
|
| 192 |
+
def __init__(self, stream_reader, client_connected_cb=None, loop=None):
|
| 193 |
+
super().__init__(loop=loop)
|
| 194 |
+
if stream_reader is not None:
|
| 195 |
+
self._stream_reader_wr = weakref.ref(stream_reader)
|
| 196 |
+
self._source_traceback = stream_reader._source_traceback
|
| 197 |
+
else:
|
| 198 |
+
self._stream_reader_wr = None
|
| 199 |
+
if client_connected_cb is not None:
|
| 200 |
+
# This is a stream created by the `create_server()` function.
|
| 201 |
+
# Keep a strong reference to the reader until a connection
|
| 202 |
+
# is established.
|
| 203 |
+
self._strong_reader = stream_reader
|
| 204 |
+
self._reject_connection = False
|
| 205 |
+
self._stream_writer = None
|
| 206 |
+
self._task = None
|
| 207 |
+
self._transport = None
|
| 208 |
+
self._client_connected_cb = client_connected_cb
|
| 209 |
+
self._over_ssl = False
|
| 210 |
+
self._closed = self._loop.create_future()
|
| 211 |
+
|
| 212 |
+
@property
|
| 213 |
+
def _stream_reader(self):
|
| 214 |
+
if self._stream_reader_wr is None:
|
| 215 |
+
return None
|
| 216 |
+
return self._stream_reader_wr()
|
| 217 |
+
|
| 218 |
+
def connection_made(self, transport):
|
| 219 |
+
if self._reject_connection:
|
| 220 |
+
context = {
|
| 221 |
+
'message': ('An open stream was garbage collected prior to '
|
| 222 |
+
'establishing network connection; '
|
| 223 |
+
'call "stream.close()" explicitly.')
|
| 224 |
+
}
|
| 225 |
+
if self._source_traceback:
|
| 226 |
+
context['source_traceback'] = self._source_traceback
|
| 227 |
+
self._loop.call_exception_handler(context)
|
| 228 |
+
transport.abort()
|
| 229 |
+
return
|
| 230 |
+
self._transport = transport
|
| 231 |
+
reader = self._stream_reader
|
| 232 |
+
if reader is not None:
|
| 233 |
+
reader.set_transport(transport)
|
| 234 |
+
self._over_ssl = transport.get_extra_info('sslcontext') is not None
|
| 235 |
+
if self._client_connected_cb is not None:
|
| 236 |
+
self._stream_writer = StreamWriter(transport, self,
|
| 237 |
+
reader,
|
| 238 |
+
self._loop)
|
| 239 |
+
res = self._client_connected_cb(reader,
|
| 240 |
+
self._stream_writer)
|
| 241 |
+
if coroutines.iscoroutine(res):
|
| 242 |
+
self._task = self._loop.create_task(res)
|
| 243 |
+
self._strong_reader = None
|
| 244 |
+
|
| 245 |
+
def connection_lost(self, exc):
|
| 246 |
+
reader = self._stream_reader
|
| 247 |
+
if reader is not None:
|
| 248 |
+
if exc is None:
|
| 249 |
+
reader.feed_eof()
|
| 250 |
+
else:
|
| 251 |
+
reader.set_exception(exc)
|
| 252 |
+
if not self._closed.done():
|
| 253 |
+
if exc is None:
|
| 254 |
+
self._closed.set_result(None)
|
| 255 |
+
else:
|
| 256 |
+
self._closed.set_exception(exc)
|
| 257 |
+
super().connection_lost(exc)
|
| 258 |
+
self._stream_reader_wr = None
|
| 259 |
+
self._stream_writer = None
|
| 260 |
+
self._task = None
|
| 261 |
+
self._transport = None
|
| 262 |
+
|
| 263 |
+
def data_received(self, data):
|
| 264 |
+
reader = self._stream_reader
|
| 265 |
+
if reader is not None:
|
| 266 |
+
reader.feed_data(data)
|
| 267 |
+
|
| 268 |
+
def eof_received(self):
|
| 269 |
+
reader = self._stream_reader
|
| 270 |
+
if reader is not None:
|
| 271 |
+
reader.feed_eof()
|
| 272 |
+
if self._over_ssl:
|
| 273 |
+
# Prevent a warning in SSLProtocol.eof_received:
|
| 274 |
+
# "returning true from eof_received()
|
| 275 |
+
# has no effect when using ssl"
|
| 276 |
+
return False
|
| 277 |
+
return True
|
| 278 |
+
|
| 279 |
+
def _get_close_waiter(self, stream):
|
| 280 |
+
return self._closed
|
| 281 |
+
|
| 282 |
+
def __del__(self):
|
| 283 |
+
# Prevent reports about unhandled exceptions.
|
| 284 |
+
# Better than self._closed._log_traceback = False hack
|
| 285 |
+
try:
|
| 286 |
+
closed = self._closed
|
| 287 |
+
except AttributeError:
|
| 288 |
+
pass # failed constructor
|
| 289 |
+
else:
|
| 290 |
+
if closed.done() and not closed.cancelled():
|
| 291 |
+
closed.exception()
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
class StreamWriter:
|
| 295 |
+
"""Wraps a Transport.
|
| 296 |
+
|
| 297 |
+
This exposes write(), writelines(), [can_]write_eof(),
|
| 298 |
+
get_extra_info() and close(). It adds drain() which returns an
|
| 299 |
+
optional Future on which you can wait for flow control. It also
|
| 300 |
+
adds a transport property which references the Transport
|
| 301 |
+
directly.
|
| 302 |
+
"""
|
| 303 |
+
|
| 304 |
+
def __init__(self, transport, protocol, reader, loop):
|
| 305 |
+
self._transport = transport
|
| 306 |
+
self._protocol = protocol
|
| 307 |
+
# drain() expects that the reader has an exception() method
|
| 308 |
+
assert reader is None or isinstance(reader, StreamReader)
|
| 309 |
+
self._reader = reader
|
| 310 |
+
self._loop = loop
|
| 311 |
+
self._complete_fut = self._loop.create_future()
|
| 312 |
+
self._complete_fut.set_result(None)
|
| 313 |
+
|
| 314 |
+
def __repr__(self):
|
| 315 |
+
info = [self.__class__.__name__, f'transport={self._transport!r}']
|
| 316 |
+
if self._reader is not None:
|
| 317 |
+
info.append(f'reader={self._reader!r}')
|
| 318 |
+
return '<{}>'.format(' '.join(info))
|
| 319 |
+
|
| 320 |
+
@property
|
| 321 |
+
def transport(self):
|
| 322 |
+
return self._transport
|
| 323 |
+
|
| 324 |
+
def write(self, data):
|
| 325 |
+
self._transport.write(data)
|
| 326 |
+
|
| 327 |
+
def writelines(self, data):
|
| 328 |
+
self._transport.writelines(data)
|
| 329 |
+
|
| 330 |
+
def write_eof(self):
|
| 331 |
+
return self._transport.write_eof()
|
| 332 |
+
|
| 333 |
+
def can_write_eof(self):
|
| 334 |
+
return self._transport.can_write_eof()
|
| 335 |
+
|
| 336 |
+
def close(self):
|
| 337 |
+
return self._transport.close()
|
| 338 |
+
|
| 339 |
+
def is_closing(self):
|
| 340 |
+
return self._transport.is_closing()
|
| 341 |
+
|
| 342 |
+
async def wait_closed(self):
|
| 343 |
+
await self._protocol._get_close_waiter(self)
|
| 344 |
+
|
| 345 |
+
def get_extra_info(self, name, default=None):
|
| 346 |
+
return self._transport.get_extra_info(name, default)
|
| 347 |
+
|
| 348 |
+
async def drain(self):
|
| 349 |
+
"""Flush the write buffer.
|
| 350 |
+
|
| 351 |
+
The intended use is to write
|
| 352 |
+
|
| 353 |
+
w.write(data)
|
| 354 |
+
await w.drain()
|
| 355 |
+
"""
|
| 356 |
+
if self._reader is not None:
|
| 357 |
+
exc = self._reader.exception()
|
| 358 |
+
if exc is not None:
|
| 359 |
+
raise exc
|
| 360 |
+
if self._transport.is_closing():
|
| 361 |
+
# Wait for protocol.connection_lost() call
|
| 362 |
+
# Raise connection closing error if any,
|
| 363 |
+
# ConnectionResetError otherwise
|
| 364 |
+
# Yield to the event loop so connection_lost() may be
|
| 365 |
+
# called. Without this, _drain_helper() would return
|
| 366 |
+
# immediately, and code that calls
|
| 367 |
+
# write(...); await drain()
|
| 368 |
+
# in a loop would never call connection_lost(), so it
|
| 369 |
+
# would not see an error when the socket is closed.
|
| 370 |
+
await sleep(0)
|
| 371 |
+
await self._protocol._drain_helper()
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
class StreamReader:
|
| 375 |
+
|
| 376 |
+
_source_traceback = None
|
| 377 |
+
|
| 378 |
+
def __init__(self, limit=_DEFAULT_LIMIT, loop=None):
|
| 379 |
+
# The line length limit is a security feature;
|
| 380 |
+
# it also doubles as half the buffer limit.
|
| 381 |
+
|
| 382 |
+
if limit <= 0:
|
| 383 |
+
raise ValueError('Limit cannot be <= 0')
|
| 384 |
+
|
| 385 |
+
self._limit = limit
|
| 386 |
+
if loop is None:
|
| 387 |
+
self._loop = events._get_event_loop()
|
| 388 |
+
else:
|
| 389 |
+
self._loop = loop
|
| 390 |
+
self._buffer = bytearray()
|
| 391 |
+
self._eof = False # Whether we're done.
|
| 392 |
+
self._waiter = None # A future used by _wait_for_data()
|
| 393 |
+
self._exception = None
|
| 394 |
+
self._transport = None
|
| 395 |
+
self._paused = False
|
| 396 |
+
if self._loop.get_debug():
|
| 397 |
+
self._source_traceback = format_helpers.extract_stack(
|
| 398 |
+
sys._getframe(1))
|
| 399 |
+
|
| 400 |
+
def __repr__(self):
|
| 401 |
+
info = ['StreamReader']
|
| 402 |
+
if self._buffer:
|
| 403 |
+
info.append(f'{len(self._buffer)} bytes')
|
| 404 |
+
if self._eof:
|
| 405 |
+
info.append('eof')
|
| 406 |
+
if self._limit != _DEFAULT_LIMIT:
|
| 407 |
+
info.append(f'limit={self._limit}')
|
| 408 |
+
if self._waiter:
|
| 409 |
+
info.append(f'waiter={self._waiter!r}')
|
| 410 |
+
if self._exception:
|
| 411 |
+
info.append(f'exception={self._exception!r}')
|
| 412 |
+
if self._transport:
|
| 413 |
+
info.append(f'transport={self._transport!r}')
|
| 414 |
+
if self._paused:
|
| 415 |
+
info.append('paused')
|
| 416 |
+
return '<{}>'.format(' '.join(info))
|
| 417 |
+
|
| 418 |
+
def exception(self):
|
| 419 |
+
return self._exception
|
| 420 |
+
|
| 421 |
+
def set_exception(self, exc):
|
| 422 |
+
self._exception = exc
|
| 423 |
+
|
| 424 |
+
waiter = self._waiter
|
| 425 |
+
if waiter is not None:
|
| 426 |
+
self._waiter = None
|
| 427 |
+
if not waiter.cancelled():
|
| 428 |
+
waiter.set_exception(exc)
|
| 429 |
+
|
| 430 |
+
def _wakeup_waiter(self):
|
| 431 |
+
"""Wakeup read*() functions waiting for data or EOF."""
|
| 432 |
+
waiter = self._waiter
|
| 433 |
+
if waiter is not None:
|
| 434 |
+
self._waiter = None
|
| 435 |
+
if not waiter.cancelled():
|
| 436 |
+
waiter.set_result(None)
|
| 437 |
+
|
| 438 |
+
def set_transport(self, transport):
|
| 439 |
+
assert self._transport is None, 'Transport already set'
|
| 440 |
+
self._transport = transport
|
| 441 |
+
|
| 442 |
+
def _maybe_resume_transport(self):
|
| 443 |
+
if self._paused and len(self._buffer) <= self._limit:
|
| 444 |
+
self._paused = False
|
| 445 |
+
self._transport.resume_reading()
|
| 446 |
+
|
| 447 |
+
def feed_eof(self):
|
| 448 |
+
self._eof = True
|
| 449 |
+
self._wakeup_waiter()
|
| 450 |
+
|
| 451 |
+
def at_eof(self):
|
| 452 |
+
"""Return True if the buffer is empty and 'feed_eof' was called."""
|
| 453 |
+
return self._eof and not self._buffer
|
| 454 |
+
|
| 455 |
+
def feed_data(self, data):
|
| 456 |
+
assert not self._eof, 'feed_data after feed_eof'
|
| 457 |
+
|
| 458 |
+
if not data:
|
| 459 |
+
return
|
| 460 |
+
|
| 461 |
+
self._buffer.extend(data)
|
| 462 |
+
self._wakeup_waiter()
|
| 463 |
+
|
| 464 |
+
if (self._transport is not None and
|
| 465 |
+
not self._paused and
|
| 466 |
+
len(self._buffer) > 2 * self._limit):
|
| 467 |
+
try:
|
| 468 |
+
self._transport.pause_reading()
|
| 469 |
+
except NotImplementedError:
|
| 470 |
+
# The transport can't be paused.
|
| 471 |
+
# We'll just have to buffer all data.
|
| 472 |
+
# Forget the transport so we don't keep trying.
|
| 473 |
+
self._transport = None
|
| 474 |
+
else:
|
| 475 |
+
self._paused = True
|
| 476 |
+
|
| 477 |
+
async def _wait_for_data(self, func_name):
|
| 478 |
+
"""Wait until feed_data() or feed_eof() is called.
|
| 479 |
+
|
| 480 |
+
If stream was paused, automatically resume it.
|
| 481 |
+
"""
|
| 482 |
+
# StreamReader uses a future to link the protocol feed_data() method
|
| 483 |
+
# to a read coroutine. Running two read coroutines at the same time
|
| 484 |
+
# would have an unexpected behaviour. It would not possible to know
|
| 485 |
+
# which coroutine would get the next data.
|
| 486 |
+
if self._waiter is not None:
|
| 487 |
+
raise RuntimeError(
|
| 488 |
+
f'{func_name}() called while another coroutine is '
|
| 489 |
+
f'already waiting for incoming data')
|
| 490 |
+
|
| 491 |
+
assert not self._eof, '_wait_for_data after EOF'
|
| 492 |
+
|
| 493 |
+
# Waiting for data while paused will make deadlock, so prevent it.
|
| 494 |
+
# This is essential for readexactly(n) for case when n > self._limit.
|
| 495 |
+
if self._paused:
|
| 496 |
+
self._paused = False
|
| 497 |
+
self._transport.resume_reading()
|
| 498 |
+
|
| 499 |
+
self._waiter = self._loop.create_future()
|
| 500 |
+
try:
|
| 501 |
+
await self._waiter
|
| 502 |
+
finally:
|
| 503 |
+
self._waiter = None
|
| 504 |
+
|
| 505 |
+
async def readline(self):
|
| 506 |
+
"""Read chunk of data from the stream until newline (b'\n') is found.
|
| 507 |
+
|
| 508 |
+
On success, return chunk that ends with newline. If only partial
|
| 509 |
+
line can be read due to EOF, return incomplete line without
|
| 510 |
+
terminating newline. When EOF was reached while no bytes read, empty
|
| 511 |
+
bytes object is returned.
|
| 512 |
+
|
| 513 |
+
If limit is reached, ValueError will be raised. In that case, if
|
| 514 |
+
newline was found, complete line including newline will be removed
|
| 515 |
+
from internal buffer. Else, internal buffer will be cleared. Limit is
|
| 516 |
+
compared against part of the line without newline.
|
| 517 |
+
|
| 518 |
+
If stream was paused, this function will automatically resume it if
|
| 519 |
+
needed.
|
| 520 |
+
"""
|
| 521 |
+
sep = b'\n'
|
| 522 |
+
seplen = len(sep)
|
| 523 |
+
try:
|
| 524 |
+
line = await self.readuntil(sep)
|
| 525 |
+
except exceptions.IncompleteReadError as e:
|
| 526 |
+
return e.partial
|
| 527 |
+
except exceptions.LimitOverrunError as e:
|
| 528 |
+
if self._buffer.startswith(sep, e.consumed):
|
| 529 |
+
del self._buffer[:e.consumed + seplen]
|
| 530 |
+
else:
|
| 531 |
+
self._buffer.clear()
|
| 532 |
+
self._maybe_resume_transport()
|
| 533 |
+
raise ValueError(e.args[0])
|
| 534 |
+
return line
|
| 535 |
+
|
| 536 |
+
async def readuntil(self, separator=b'\n'):
|
| 537 |
+
"""Read data from the stream until ``separator`` is found.
|
| 538 |
+
|
| 539 |
+
On success, the data and separator will be removed from the
|
| 540 |
+
internal buffer (consumed). Returned data will include the
|
| 541 |
+
separator at the end.
|
| 542 |
+
|
| 543 |
+
Configured stream limit is used to check result. Limit sets the
|
| 544 |
+
maximal length of data that can be returned, not counting the
|
| 545 |
+
separator.
|
| 546 |
+
|
| 547 |
+
If an EOF occurs and the complete separator is still not found,
|
| 548 |
+
an IncompleteReadError exception will be raised, and the internal
|
| 549 |
+
buffer will be reset. The IncompleteReadError.partial attribute
|
| 550 |
+
may contain the separator partially.
|
| 551 |
+
|
| 552 |
+
If the data cannot be read because of over limit, a
|
| 553 |
+
LimitOverrunError exception will be raised, and the data
|
| 554 |
+
will be left in the internal buffer, so it can be read again.
|
| 555 |
+
"""
|
| 556 |
+
seplen = len(separator)
|
| 557 |
+
if seplen == 0:
|
| 558 |
+
raise ValueError('Separator should be at least one-byte string')
|
| 559 |
+
|
| 560 |
+
if self._exception is not None:
|
| 561 |
+
raise self._exception
|
| 562 |
+
|
| 563 |
+
# Consume whole buffer except last bytes, which length is
|
| 564 |
+
# one less than seplen. Let's check corner cases with
|
| 565 |
+
# separator='SEPARATOR':
|
| 566 |
+
# * we have received almost complete separator (without last
|
| 567 |
+
# byte). i.e buffer='some textSEPARATO'. In this case we
|
| 568 |
+
# can safely consume len(separator) - 1 bytes.
|
| 569 |
+
# * last byte of buffer is first byte of separator, i.e.
|
| 570 |
+
# buffer='abcdefghijklmnopqrS'. We may safely consume
|
| 571 |
+
# everything except that last byte, but this require to
|
| 572 |
+
# analyze bytes of buffer that match partial separator.
|
| 573 |
+
# This is slow and/or require FSM. For this case our
|
| 574 |
+
# implementation is not optimal, since require rescanning
|
| 575 |
+
# of data that is known to not belong to separator. In
|
| 576 |
+
# real world, separator will not be so long to notice
|
| 577 |
+
# performance problems. Even when reading MIME-encoded
|
| 578 |
+
# messages :)
|
| 579 |
+
|
| 580 |
+
# `offset` is the number of bytes from the beginning of the buffer
|
| 581 |
+
# where there is no occurrence of `separator`.
|
| 582 |
+
offset = 0
|
| 583 |
+
|
| 584 |
+
# Loop until we find `separator` in the buffer, exceed the buffer size,
|
| 585 |
+
# or an EOF has happened.
|
| 586 |
+
while True:
|
| 587 |
+
buflen = len(self._buffer)
|
| 588 |
+
|
| 589 |
+
# Check if we now have enough data in the buffer for `separator` to
|
| 590 |
+
# fit.
|
| 591 |
+
if buflen - offset >= seplen:
|
| 592 |
+
isep = self._buffer.find(separator, offset)
|
| 593 |
+
|
| 594 |
+
if isep != -1:
|
| 595 |
+
# `separator` is in the buffer. `isep` will be used later
|
| 596 |
+
# to retrieve the data.
|
| 597 |
+
break
|
| 598 |
+
|
| 599 |
+
# see upper comment for explanation.
|
| 600 |
+
offset = buflen + 1 - seplen
|
| 601 |
+
if offset > self._limit:
|
| 602 |
+
raise exceptions.LimitOverrunError(
|
| 603 |
+
'Separator is not found, and chunk exceed the limit',
|
| 604 |
+
offset)
|
| 605 |
+
|
| 606 |
+
# Complete message (with full separator) may be present in buffer
|
| 607 |
+
# even when EOF flag is set. This may happen when the last chunk
|
| 608 |
+
# adds data which makes separator be found. That's why we check for
|
| 609 |
+
# EOF *ater* inspecting the buffer.
|
| 610 |
+
if self._eof:
|
| 611 |
+
chunk = bytes(self._buffer)
|
| 612 |
+
self._buffer.clear()
|
| 613 |
+
raise exceptions.IncompleteReadError(chunk, None)
|
| 614 |
+
|
| 615 |
+
# _wait_for_data() will resume reading if stream was paused.
|
| 616 |
+
await self._wait_for_data('readuntil')
|
| 617 |
+
|
| 618 |
+
if isep > self._limit:
|
| 619 |
+
raise exceptions.LimitOverrunError(
|
| 620 |
+
'Separator is found, but chunk is longer than limit', isep)
|
| 621 |
+
|
| 622 |
+
chunk = self._buffer[:isep + seplen]
|
| 623 |
+
del self._buffer[:isep + seplen]
|
| 624 |
+
self._maybe_resume_transport()
|
| 625 |
+
return bytes(chunk)
|
| 626 |
+
|
| 627 |
+
async def read(self, n=-1):
|
| 628 |
+
"""Read up to `n` bytes from the stream.
|
| 629 |
+
|
| 630 |
+
If `n` is not provided or set to -1,
|
| 631 |
+
read until EOF, then return all read bytes.
|
| 632 |
+
If EOF was received and the internal buffer is empty,
|
| 633 |
+
return an empty bytes object.
|
| 634 |
+
|
| 635 |
+
If `n` is 0, return an empty bytes object immediately.
|
| 636 |
+
|
| 637 |
+
If `n` is positive, return at most `n` available bytes
|
| 638 |
+
as soon as at least 1 byte is available in the internal buffer.
|
| 639 |
+
If EOF is received before any byte is read, return an empty
|
| 640 |
+
bytes object.
|
| 641 |
+
|
| 642 |
+
Returned value is not limited with limit, configured at stream
|
| 643 |
+
creation.
|
| 644 |
+
|
| 645 |
+
If stream was paused, this function will automatically resume it if
|
| 646 |
+
needed.
|
| 647 |
+
"""
|
| 648 |
+
|
| 649 |
+
if self._exception is not None:
|
| 650 |
+
raise self._exception
|
| 651 |
+
|
| 652 |
+
if n == 0:
|
| 653 |
+
return b''
|
| 654 |
+
|
| 655 |
+
if n < 0:
|
| 656 |
+
# This used to just loop creating a new waiter hoping to
|
| 657 |
+
# collect everything in self._buffer, but that would
|
| 658 |
+
# deadlock if the subprocess sends more than self.limit
|
| 659 |
+
# bytes. So just call self.read(self._limit) until EOF.
|
| 660 |
+
blocks = []
|
| 661 |
+
while True:
|
| 662 |
+
block = await self.read(self._limit)
|
| 663 |
+
if not block:
|
| 664 |
+
break
|
| 665 |
+
blocks.append(block)
|
| 666 |
+
return b''.join(blocks)
|
| 667 |
+
|
| 668 |
+
if not self._buffer and not self._eof:
|
| 669 |
+
await self._wait_for_data('read')
|
| 670 |
+
|
| 671 |
+
# This will work right even if buffer is less than n bytes
|
| 672 |
+
data = bytes(self._buffer[:n])
|
| 673 |
+
del self._buffer[:n]
|
| 674 |
+
|
| 675 |
+
self._maybe_resume_transport()
|
| 676 |
+
return data
|
| 677 |
+
|
| 678 |
+
async def readexactly(self, n):
|
| 679 |
+
"""Read exactly `n` bytes.
|
| 680 |
+
|
| 681 |
+
Raise an IncompleteReadError if EOF is reached before `n` bytes can be
|
| 682 |
+
read. The IncompleteReadError.partial attribute of the exception will
|
| 683 |
+
contain the partial read bytes.
|
| 684 |
+
|
| 685 |
+
if n is zero, return empty bytes object.
|
| 686 |
+
|
| 687 |
+
Returned value is not limited with limit, configured at stream
|
| 688 |
+
creation.
|
| 689 |
+
|
| 690 |
+
If stream was paused, this function will automatically resume it if
|
| 691 |
+
needed.
|
| 692 |
+
"""
|
| 693 |
+
if n < 0:
|
| 694 |
+
raise ValueError('readexactly size can not be less than zero')
|
| 695 |
+
|
| 696 |
+
if self._exception is not None:
|
| 697 |
+
raise self._exception
|
| 698 |
+
|
| 699 |
+
if n == 0:
|
| 700 |
+
return b''
|
| 701 |
+
|
| 702 |
+
while len(self._buffer) < n:
|
| 703 |
+
if self._eof:
|
| 704 |
+
incomplete = bytes(self._buffer)
|
| 705 |
+
self._buffer.clear()
|
| 706 |
+
raise exceptions.IncompleteReadError(incomplete, n)
|
| 707 |
+
|
| 708 |
+
await self._wait_for_data('readexactly')
|
| 709 |
+
|
| 710 |
+
if len(self._buffer) == n:
|
| 711 |
+
data = bytes(self._buffer)
|
| 712 |
+
self._buffer.clear()
|
| 713 |
+
else:
|
| 714 |
+
data = bytes(self._buffer[:n])
|
| 715 |
+
del self._buffer[:n]
|
| 716 |
+
self._maybe_resume_transport()
|
| 717 |
+
return data
|
| 718 |
+
|
| 719 |
+
def __aiter__(self):
|
| 720 |
+
return self
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Abstract Transport class."""
|
| 2 |
+
|
| 3 |
+
__all__ = (
|
| 4 |
+
'BaseTransport', 'ReadTransport', 'WriteTransport',
|
| 5 |
+
'Transport', 'DatagramTransport', 'SubprocessTransport',
|
| 6 |
+
)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class BaseTransport:
|
| 10 |
+
"""Base class for transports."""
|
| 11 |
+
|
| 12 |
+
__slots__ = ('_extra',)
|
| 13 |
+
|
| 14 |
+
def __init__(self, extra=None):
|
| 15 |
+
if extra is None:
|
| 16 |
+
extra = {}
|
| 17 |
+
self._extra = extra
|
| 18 |
+
|
| 19 |
+
def get_extra_info(self, name, default=None):
|
| 20 |
+
"""Get optional transport information."""
|
| 21 |
+
return self._extra.get(name, default)
|
| 22 |
+
|
| 23 |
+
def is_closing(self):
|
| 24 |
+
"""Return True if the transport is closing or closed."""
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
def close(self):
|
| 28 |
+
"""Close the transport.
|
| 29 |
+
|
| 30 |
+
Buffered data will be flushed asynchronously. No more data
|
| 31 |
+
will be received. After all buffered data is flushed, the
|
| 32 |
+
protocol's connection_lost() method will (eventually) be
|
| 33 |
+
called with None as its argument.
|
| 34 |
+
"""
|
| 35 |
+
raise NotImplementedError
|
| 36 |
+
|
| 37 |
+
def set_protocol(self, protocol):
|
| 38 |
+
"""Set a new protocol."""
|
| 39 |
+
raise NotImplementedError
|
| 40 |
+
|
| 41 |
+
def get_protocol(self):
|
| 42 |
+
"""Return the current protocol."""
|
| 43 |
+
raise NotImplementedError
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class ReadTransport(BaseTransport):
|
| 47 |
+
"""Interface for read-only transports."""
|
| 48 |
+
|
| 49 |
+
__slots__ = ()
|
| 50 |
+
|
| 51 |
+
def is_reading(self):
|
| 52 |
+
"""Return True if the transport is receiving."""
|
| 53 |
+
raise NotImplementedError
|
| 54 |
+
|
| 55 |
+
def pause_reading(self):
|
| 56 |
+
"""Pause the receiving end.
|
| 57 |
+
|
| 58 |
+
No data will be passed to the protocol's data_received()
|
| 59 |
+
method until resume_reading() is called.
|
| 60 |
+
"""
|
| 61 |
+
raise NotImplementedError
|
| 62 |
+
|
| 63 |
+
def resume_reading(self):
|
| 64 |
+
"""Resume the receiving end.
|
| 65 |
+
|
| 66 |
+
Data received will once again be passed to the protocol's
|
| 67 |
+
data_received() method.
|
| 68 |
+
"""
|
| 69 |
+
raise NotImplementedError
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class WriteTransport(BaseTransport):
|
| 73 |
+
"""Interface for write-only transports."""
|
| 74 |
+
|
| 75 |
+
__slots__ = ()
|
| 76 |
+
|
| 77 |
+
def set_write_buffer_limits(self, high=None, low=None):
|
| 78 |
+
"""Set the high- and low-water limits for write flow control.
|
| 79 |
+
|
| 80 |
+
These two values control when to call the protocol's
|
| 81 |
+
pause_writing() and resume_writing() methods. If specified,
|
| 82 |
+
the low-water limit must be less than or equal to the
|
| 83 |
+
high-water limit. Neither value can be negative.
|
| 84 |
+
|
| 85 |
+
The defaults are implementation-specific. If only the
|
| 86 |
+
high-water limit is given, the low-water limit defaults to an
|
| 87 |
+
implementation-specific value less than or equal to the
|
| 88 |
+
high-water limit. Setting high to zero forces low to zero as
|
| 89 |
+
well, and causes pause_writing() to be called whenever the
|
| 90 |
+
buffer becomes non-empty. Setting low to zero causes
|
| 91 |
+
resume_writing() to be called only once the buffer is empty.
|
| 92 |
+
Use of zero for either limit is generally sub-optimal as it
|
| 93 |
+
reduces opportunities for doing I/O and computation
|
| 94 |
+
concurrently.
|
| 95 |
+
"""
|
| 96 |
+
raise NotImplementedError
|
| 97 |
+
|
| 98 |
+
def get_write_buffer_size(self):
|
| 99 |
+
"""Return the current size of the write buffer."""
|
| 100 |
+
raise NotImplementedError
|
| 101 |
+
|
| 102 |
+
def get_write_buffer_limits(self):
|
| 103 |
+
"""Get the high and low watermarks for write flow control.
|
| 104 |
+
Return a tuple (low, high) where low and high are
|
| 105 |
+
positive number of bytes."""
|
| 106 |
+
raise NotImplementedError
|
| 107 |
+
|
| 108 |
+
def write(self, data):
|
| 109 |
+
"""Write some data bytes to the transport.
|
| 110 |
+
|
| 111 |
+
This does not block; it buffers the data and arranges for it
|
| 112 |
+
to be sent out asynchronously.
|
| 113 |
+
"""
|
| 114 |
+
raise NotImplementedError
|
| 115 |
+
|
| 116 |
+
def writelines(self, list_of_data):
|
| 117 |
+
"""Write a list (or any iterable) of data bytes to the transport.
|
| 118 |
+
|
| 119 |
+
The default implementation concatenates the arguments and
|
| 120 |
+
calls write() on the result.
|
| 121 |
+
"""
|
| 122 |
+
data = b''.join(list_of_data)
|
| 123 |
+
self.write(data)
|
| 124 |
+
|
| 125 |
+
def write_eof(self):
|
| 126 |
+
"""Close the write end after flushing buffered data.
|
| 127 |
+
|
| 128 |
+
(This is like typing ^D into a UNIX program reading from stdin.)
|
| 129 |
+
|
| 130 |
+
Data may still be received.
|
| 131 |
+
"""
|
| 132 |
+
raise NotImplementedError
|
| 133 |
+
|
| 134 |
+
def can_write_eof(self):
|
| 135 |
+
"""Return True if this transport supports write_eof(), False if not."""
|
| 136 |
+
raise NotImplementedError
|
| 137 |
+
|
| 138 |
+
def abort(self):
|
| 139 |
+
"""Close the transport immediately.
|
| 140 |
+
|
| 141 |
+
Buffered data will be lost. No more data will be received.
|
| 142 |
+
The protocol's connection_lost() method will (eventually) be
|
| 143 |
+
called with None as its argument.
|
| 144 |
+
"""
|
| 145 |
+
raise NotImplementedError
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class Transport(ReadTransport, WriteTransport):
|
| 149 |
+
"""Interface representing a bidirectional transport.
|
| 150 |
+
|
| 151 |
+
There may be several implementations, but typically, the user does
|
| 152 |
+
not implement new transports; rather, the platform provides some
|
| 153 |
+
useful transports that are implemented using the platform's best
|
| 154 |
+
practices.
|
| 155 |
+
|
| 156 |
+
The user never instantiates a transport directly; they call a
|
| 157 |
+
utility function, passing it a protocol factory and other
|
| 158 |
+
information necessary to create the transport and protocol. (E.g.
|
| 159 |
+
EventLoop.create_connection() or EventLoop.create_server().)
|
| 160 |
+
|
| 161 |
+
The utility function will asynchronously create a transport and a
|
| 162 |
+
protocol and hook them up by calling the protocol's
|
| 163 |
+
connection_made() method, passing it the transport.
|
| 164 |
+
|
| 165 |
+
The implementation here raises NotImplemented for every method
|
| 166 |
+
except writelines(), which calls write() in a loop.
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
__slots__ = ()
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
class DatagramTransport(BaseTransport):
|
| 173 |
+
"""Interface for datagram (UDP) transports."""
|
| 174 |
+
|
| 175 |
+
__slots__ = ()
|
| 176 |
+
|
| 177 |
+
def sendto(self, data, addr=None):
|
| 178 |
+
"""Send data to the transport.
|
| 179 |
+
|
| 180 |
+
This does not block; it buffers the data and arranges for it
|
| 181 |
+
to be sent out asynchronously.
|
| 182 |
+
addr is target socket address.
|
| 183 |
+
If addr is None use target address pointed on transport creation.
|
| 184 |
+
"""
|
| 185 |
+
raise NotImplementedError
|
| 186 |
+
|
| 187 |
+
def abort(self):
|
| 188 |
+
"""Close the transport immediately.
|
| 189 |
+
|
| 190 |
+
Buffered data will be lost. No more data will be received.
|
| 191 |
+
The protocol's connection_lost() method will (eventually) be
|
| 192 |
+
called with None as its argument.
|
| 193 |
+
"""
|
| 194 |
+
raise NotImplementedError
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
class SubprocessTransport(BaseTransport):
|
| 198 |
+
|
| 199 |
+
__slots__ = ()
|
| 200 |
+
|
| 201 |
+
def get_pid(self):
|
| 202 |
+
"""Get subprocess id."""
|
| 203 |
+
raise NotImplementedError
|
| 204 |
+
|
| 205 |
+
def get_returncode(self):
|
| 206 |
+
"""Get subprocess returncode.
|
| 207 |
+
|
| 208 |
+
See also
|
| 209 |
+
http://docs.python.org/3/library/subprocess#subprocess.Popen.returncode
|
| 210 |
+
"""
|
| 211 |
+
raise NotImplementedError
|
| 212 |
+
|
| 213 |
+
def get_pipe_transport(self, fd):
|
| 214 |
+
"""Get transport for pipe with number fd."""
|
| 215 |
+
raise NotImplementedError
|
| 216 |
+
|
| 217 |
+
def send_signal(self, signal):
|
| 218 |
+
"""Send signal to subprocess.
|
| 219 |
+
|
| 220 |
+
See also:
|
| 221 |
+
docs.python.org/3/library/subprocess#subprocess.Popen.send_signal
|
| 222 |
+
"""
|
| 223 |
+
raise NotImplementedError
|
| 224 |
+
|
| 225 |
+
def terminate(self):
|
| 226 |
+
"""Stop the subprocess.
|
| 227 |
+
|
| 228 |
+
Alias for close() method.
|
| 229 |
+
|
| 230 |
+
On Posix OSs the method sends SIGTERM to the subprocess.
|
| 231 |
+
On Windows the Win32 API function TerminateProcess()
|
| 232 |
+
is called to stop the subprocess.
|
| 233 |
+
|
| 234 |
+
See also:
|
| 235 |
+
http://docs.python.org/3/library/subprocess#subprocess.Popen.terminate
|
| 236 |
+
"""
|
| 237 |
+
raise NotImplementedError
|
| 238 |
+
|
| 239 |
+
def kill(self):
|
| 240 |
+
"""Kill the subprocess.
|
| 241 |
+
|
| 242 |
+
On Posix OSs the function sends SIGKILL to the subprocess.
|
| 243 |
+
On Windows kill() is an alias for terminate().
|
| 244 |
+
|
| 245 |
+
See also:
|
| 246 |
+
http://docs.python.org/3/library/subprocess#subprocess.Popen.kill
|
| 247 |
+
"""
|
| 248 |
+
raise NotImplementedError
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
class _FlowControlMixin(Transport):
|
| 252 |
+
"""All the logic for (write) flow control in a mix-in base class.
|
| 253 |
+
|
| 254 |
+
The subclass must implement get_write_buffer_size(). It must call
|
| 255 |
+
_maybe_pause_protocol() whenever the write buffer size increases,
|
| 256 |
+
and _maybe_resume_protocol() whenever it decreases. It may also
|
| 257 |
+
override set_write_buffer_limits() (e.g. to specify different
|
| 258 |
+
defaults).
|
| 259 |
+
|
| 260 |
+
The subclass constructor must call super().__init__(extra). This
|
| 261 |
+
will call set_write_buffer_limits().
|
| 262 |
+
|
| 263 |
+
The user may call set_write_buffer_limits() and
|
| 264 |
+
get_write_buffer_size(), and their protocol's pause_writing() and
|
| 265 |
+
resume_writing() may be called.
|
| 266 |
+
"""
|
| 267 |
+
|
| 268 |
+
__slots__ = ('_loop', '_protocol_paused', '_high_water', '_low_water')
|
| 269 |
+
|
| 270 |
+
def __init__(self, extra=None, loop=None):
|
| 271 |
+
super().__init__(extra)
|
| 272 |
+
assert loop is not None
|
| 273 |
+
self._loop = loop
|
| 274 |
+
self._protocol_paused = False
|
| 275 |
+
self._set_write_buffer_limits()
|
| 276 |
+
|
| 277 |
+
def _maybe_pause_protocol(self):
|
| 278 |
+
size = self.get_write_buffer_size()
|
| 279 |
+
if size <= self._high_water:
|
| 280 |
+
return
|
| 281 |
+
if not self._protocol_paused:
|
| 282 |
+
self._protocol_paused = True
|
| 283 |
+
try:
|
| 284 |
+
self._protocol.pause_writing()
|
| 285 |
+
except (SystemExit, KeyboardInterrupt):
|
| 286 |
+
raise
|
| 287 |
+
except BaseException as exc:
|
| 288 |
+
self._loop.call_exception_handler({
|
| 289 |
+
'message': 'protocol.pause_writing() failed',
|
| 290 |
+
'exception': exc,
|
| 291 |
+
'transport': self,
|
| 292 |
+
'protocol': self._protocol,
|
| 293 |
+
})
|
| 294 |
+
|
| 295 |
+
def _maybe_resume_protocol(self):
|
| 296 |
+
if (self._protocol_paused and
|
| 297 |
+
self.get_write_buffer_size() <= self._low_water):
|
| 298 |
+
self._protocol_paused = False
|
| 299 |
+
try:
|
| 300 |
+
self._protocol.resume_writing()
|
| 301 |
+
except (SystemExit, KeyboardInterrupt):
|
| 302 |
+
raise
|
| 303 |
+
except BaseException as exc:
|
| 304 |
+
self._loop.call_exception_handler({
|
| 305 |
+
'message': 'protocol.resume_writing() failed',
|
| 306 |
+
'exception': exc,
|
| 307 |
+
'transport': self,
|
| 308 |
+
'protocol': self._protocol,
|
| 309 |
+
})
|
| 310 |
+
|
| 311 |
+
def get_write_buffer_limits(self):
|
| 312 |
+
return (self._low_water, self._high_water)
|
| 313 |
+
|
| 314 |
+
def _set_write_buffer_limits(self, high=None, low=None):
|
| 315 |
+
if high is None:
|
| 316 |
+
if low is None:
|
| 317 |
+
high = 64 * 1024
|
| 318 |
+
else:
|
| 319 |
+
high = 4 * low
|
| 320 |
+
if low is None:
|
| 321 |
+
low = high // 4
|
| 322 |
+
|
| 323 |
+
if not high >= low >= 0:
|
| 324 |
+
raise ValueError(
|
| 325 |
+
f'high ({high!r}) must be >= low ({low!r}) must be >= 0')
|
| 326 |
+
|
| 327 |
+
self._high_water = high
|
| 328 |
+
self._low_water = low
|
| 329 |
+
|
| 330 |
+
def set_write_buffer_limits(self, high=None, low=None):
|
| 331 |
+
self._set_write_buffer_limits(high=high, low=low)
|
| 332 |
+
self._maybe_pause_protocol()
|
| 333 |
+
|
| 334 |
+
def get_write_buffer_size(self):
|
| 335 |
+
raise NotImplementedError
|
janus/lib/python3.10/asyncio/trsock.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import socket
|
| 2 |
+
import warnings
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class TransportSocket:
|
| 6 |
+
|
| 7 |
+
"""A socket-like wrapper for exposing real transport sockets.
|
| 8 |
+
|
| 9 |
+
These objects can be safely returned by APIs like
|
| 10 |
+
`transport.get_extra_info('socket')`. All potentially disruptive
|
| 11 |
+
operations (like "socket.close()") are banned.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
__slots__ = ('_sock',)
|
| 15 |
+
|
| 16 |
+
def __init__(self, sock: socket.socket):
|
| 17 |
+
self._sock = sock
|
| 18 |
+
|
| 19 |
+
def _na(self, what):
|
| 20 |
+
warnings.warn(
|
| 21 |
+
f"Using {what} on sockets returned from get_extra_info('socket') "
|
| 22 |
+
f"will be prohibited in asyncio 3.9. Please report your use case "
|
| 23 |
+
f"to bugs.python.org.",
|
| 24 |
+
DeprecationWarning, source=self)
|
| 25 |
+
|
| 26 |
+
@property
|
| 27 |
+
def family(self):
|
| 28 |
+
return self._sock.family
|
| 29 |
+
|
| 30 |
+
@property
|
| 31 |
+
def type(self):
|
| 32 |
+
return self._sock.type
|
| 33 |
+
|
| 34 |
+
@property
|
| 35 |
+
def proto(self):
|
| 36 |
+
return self._sock.proto
|
| 37 |
+
|
| 38 |
+
def __repr__(self):
|
| 39 |
+
s = (
|
| 40 |
+
f"<asyncio.TransportSocket fd={self.fileno()}, "
|
| 41 |
+
f"family={self.family!s}, type={self.type!s}, "
|
| 42 |
+
f"proto={self.proto}"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
if self.fileno() != -1:
|
| 46 |
+
try:
|
| 47 |
+
laddr = self.getsockname()
|
| 48 |
+
if laddr:
|
| 49 |
+
s = f"{s}, laddr={laddr}"
|
| 50 |
+
except socket.error:
|
| 51 |
+
pass
|
| 52 |
+
try:
|
| 53 |
+
raddr = self.getpeername()
|
| 54 |
+
if raddr:
|
| 55 |
+
s = f"{s}, raddr={raddr}"
|
| 56 |
+
except socket.error:
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
return f"{s}>"
|
| 60 |
+
|
| 61 |
+
def __getstate__(self):
|
| 62 |
+
raise TypeError("Cannot serialize asyncio.TransportSocket object")
|
| 63 |
+
|
| 64 |
+
def fileno(self):
|
| 65 |
+
return self._sock.fileno()
|
| 66 |
+
|
| 67 |
+
def dup(self):
|
| 68 |
+
return self._sock.dup()
|
| 69 |
+
|
| 70 |
+
def get_inheritable(self):
|
| 71 |
+
return self._sock.get_inheritable()
|
| 72 |
+
|
| 73 |
+
def shutdown(self, how):
|
| 74 |
+
# asyncio doesn't currently provide a high-level transport API
|
| 75 |
+
# to shutdown the connection.
|
| 76 |
+
self._sock.shutdown(how)
|
| 77 |
+
|
| 78 |
+
def getsockopt(self, *args, **kwargs):
|
| 79 |
+
return self._sock.getsockopt(*args, **kwargs)
|
| 80 |
+
|
| 81 |
+
def setsockopt(self, *args, **kwargs):
|
| 82 |
+
self._sock.setsockopt(*args, **kwargs)
|
| 83 |
+
|
| 84 |
+
def getpeername(self):
|
| 85 |
+
return self._sock.getpeername()
|
| 86 |
+
|
| 87 |
+
def getsockname(self):
|
| 88 |
+
return self._sock.getsockname()
|
| 89 |
+
|
| 90 |
+
def getsockbyname(self):
|
| 91 |
+
return self._sock.getsockbyname()
|
| 92 |
+
|
| 93 |
+
def accept(self):
|
| 94 |
+
self._na('accept() method')
|
| 95 |
+
return self._sock.accept()
|
| 96 |
+
|
| 97 |
+
def connect(self, *args, **kwargs):
|
| 98 |
+
self._na('connect() method')
|
| 99 |
+
return self._sock.connect(*args, **kwargs)
|
| 100 |
+
|
| 101 |
+
def connect_ex(self, *args, **kwargs):
|
| 102 |
+
self._na('connect_ex() method')
|
| 103 |
+
return self._sock.connect_ex(*args, **kwargs)
|
| 104 |
+
|
| 105 |
+
def bind(self, *args, **kwargs):
|
| 106 |
+
self._na('bind() method')
|
| 107 |
+
return self._sock.bind(*args, **kwargs)
|
| 108 |
+
|
| 109 |
+
def ioctl(self, *args, **kwargs):
|
| 110 |
+
self._na('ioctl() method')
|
| 111 |
+
return self._sock.ioctl(*args, **kwargs)
|
| 112 |
+
|
| 113 |
+
def listen(self, *args, **kwargs):
|
| 114 |
+
self._na('listen() method')
|
| 115 |
+
return self._sock.listen(*args, **kwargs)
|
| 116 |
+
|
| 117 |
+
def makefile(self):
|
| 118 |
+
self._na('makefile() method')
|
| 119 |
+
return self._sock.makefile()
|
| 120 |
+
|
| 121 |
+
def sendfile(self, *args, **kwargs):
|
| 122 |
+
self._na('sendfile() method')
|
| 123 |
+
return self._sock.sendfile(*args, **kwargs)
|
| 124 |
+
|
| 125 |
+
def close(self):
|
| 126 |
+
self._na('close() method')
|
| 127 |
+
return self._sock.close()
|
| 128 |
+
|
| 129 |
+
def detach(self):
|
| 130 |
+
self._na('detach() method')
|
| 131 |
+
return self._sock.detach()
|
| 132 |
+
|
| 133 |
+
def sendmsg_afalg(self, *args, **kwargs):
|
| 134 |
+
self._na('sendmsg_afalg() method')
|
| 135 |
+
return self._sock.sendmsg_afalg(*args, **kwargs)
|
| 136 |
+
|
| 137 |
+
def sendmsg(self, *args, **kwargs):
|
| 138 |
+
self._na('sendmsg() method')
|
| 139 |
+
return self._sock.sendmsg(*args, **kwargs)
|
| 140 |
+
|
| 141 |
+
def sendto(self, *args, **kwargs):
|
| 142 |
+
self._na('sendto() method')
|
| 143 |
+
return self._sock.sendto(*args, **kwargs)
|
| 144 |
+
|
| 145 |
+
def send(self, *args, **kwargs):
|
| 146 |
+
self._na('send() method')
|
| 147 |
+
return self._sock.send(*args, **kwargs)
|
| 148 |
+
|
| 149 |
+
def sendall(self, *args, **kwargs):
|
| 150 |
+
self._na('sendall() method')
|
| 151 |
+
return self._sock.sendall(*args, **kwargs)
|
| 152 |
+
|
| 153 |
+
def set_inheritable(self, *args, **kwargs):
|
| 154 |
+
self._na('set_inheritable() method')
|
| 155 |
+
return self._sock.set_inheritable(*args, **kwargs)
|
| 156 |
+
|
| 157 |
+
def share(self, process_id):
|
| 158 |
+
self._na('share() method')
|
| 159 |
+
return self._sock.share(process_id)
|
| 160 |
+
|
| 161 |
+
def recv_into(self, *args, **kwargs):
|
| 162 |
+
self._na('recv_into() method')
|
| 163 |
+
return self._sock.recv_into(*args, **kwargs)
|
| 164 |
+
|
| 165 |
+
def recvfrom_into(self, *args, **kwargs):
|
| 166 |
+
self._na('recvfrom_into() method')
|
| 167 |
+
return self._sock.recvfrom_into(*args, **kwargs)
|
| 168 |
+
|
| 169 |
+
def recvmsg_into(self, *args, **kwargs):
|
| 170 |
+
self._na('recvmsg_into() method')
|
| 171 |
+
return self._sock.recvmsg_into(*args, **kwargs)
|
| 172 |
+
|
| 173 |
+
def recvmsg(self, *args, **kwargs):
|
| 174 |
+
self._na('recvmsg() method')
|
| 175 |
+
return self._sock.recvmsg(*args, **kwargs)
|
| 176 |
+
|
| 177 |
+
def recvfrom(self, *args, **kwargs):
|
| 178 |
+
self._na('recvfrom() method')
|
| 179 |
+
return self._sock.recvfrom(*args, **kwargs)
|
| 180 |
+
|
| 181 |
+
def recv(self, *args, **kwargs):
|
| 182 |
+
self._na('recv() method')
|
| 183 |
+
return self._sock.recv(*args, **kwargs)
|
| 184 |
+
|
| 185 |
+
def settimeout(self, value):
|
| 186 |
+
if value == 0:
|
| 187 |
+
return
|
| 188 |
+
raise ValueError(
|
| 189 |
+
'settimeout(): only 0 timeout is allowed on transport sockets')
|
| 190 |
+
|
| 191 |
+
def gettimeout(self):
|
| 192 |
+
return 0
|
| 193 |
+
|
| 194 |
+
def setblocking(self, flag):
|
| 195 |
+
if not flag:
|
| 196 |
+
return
|
| 197 |
+
raise ValueError(
|
| 198 |
+
'setblocking(): transport sockets cannot be blocking')
|
| 199 |
+
|
| 200 |
+
def __enter__(self):
|
| 201 |
+
self._na('context manager protocol')
|
| 202 |
+
return self._sock.__enter__()
|
| 203 |
+
|
| 204 |
+
def __exit__(self, *err):
|
| 205 |
+
self._na('context manager protocol')
|
| 206 |
+
return self._sock.__exit__(*err)
|
janus/lib/python3.10/asyncio/unix_events.py
ADDED
|
@@ -0,0 +1,1466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Selector event loop for Unix with signal handling."""
|
| 2 |
+
|
| 3 |
+
import errno
|
| 4 |
+
import io
|
| 5 |
+
import itertools
|
| 6 |
+
import os
|
| 7 |
+
import selectors
|
| 8 |
+
import signal
|
| 9 |
+
import socket
|
| 10 |
+
import stat
|
| 11 |
+
import subprocess
|
| 12 |
+
import sys
|
| 13 |
+
import threading
|
| 14 |
+
import warnings
|
| 15 |
+
|
| 16 |
+
from . import base_events
|
| 17 |
+
from . import base_subprocess
|
| 18 |
+
from . import constants
|
| 19 |
+
from . import coroutines
|
| 20 |
+
from . import events
|
| 21 |
+
from . import exceptions
|
| 22 |
+
from . import futures
|
| 23 |
+
from . import selector_events
|
| 24 |
+
from . import tasks
|
| 25 |
+
from . import transports
|
| 26 |
+
from .log import logger
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__all__ = (
|
| 30 |
+
'SelectorEventLoop',
|
| 31 |
+
'AbstractChildWatcher', 'SafeChildWatcher',
|
| 32 |
+
'FastChildWatcher', 'PidfdChildWatcher',
|
| 33 |
+
'MultiLoopChildWatcher', 'ThreadedChildWatcher',
|
| 34 |
+
'DefaultEventLoopPolicy',
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
if sys.platform == 'win32': # pragma: no cover
|
| 39 |
+
raise ImportError('Signals are not really supported on Windows')
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _sighandler_noop(signum, frame):
|
| 43 |
+
"""Dummy signal handler."""
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def waitstatus_to_exitcode(status):
|
| 48 |
+
try:
|
| 49 |
+
return os.waitstatus_to_exitcode(status)
|
| 50 |
+
except ValueError:
|
| 51 |
+
# The child exited, but we don't understand its status.
|
| 52 |
+
# This shouldn't happen, but if it does, let's just
|
| 53 |
+
# return that status; perhaps that helps debug it.
|
| 54 |
+
return status
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
|
| 58 |
+
"""Unix event loop.
|
| 59 |
+
|
| 60 |
+
Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
|
| 61 |
+
"""
|
| 62 |
+
|
| 63 |
+
def __init__(self, selector=None):
|
| 64 |
+
super().__init__(selector)
|
| 65 |
+
self._signal_handlers = {}
|
| 66 |
+
|
| 67 |
+
def close(self):
|
| 68 |
+
super().close()
|
| 69 |
+
if not sys.is_finalizing():
|
| 70 |
+
for sig in list(self._signal_handlers):
|
| 71 |
+
self.remove_signal_handler(sig)
|
| 72 |
+
else:
|
| 73 |
+
if self._signal_handlers:
|
| 74 |
+
warnings.warn(f"Closing the loop {self!r} "
|
| 75 |
+
f"on interpreter shutdown "
|
| 76 |
+
f"stage, skipping signal handlers removal",
|
| 77 |
+
ResourceWarning,
|
| 78 |
+
source=self)
|
| 79 |
+
self._signal_handlers.clear()
|
| 80 |
+
|
| 81 |
+
def _process_self_data(self, data):
|
| 82 |
+
for signum in data:
|
| 83 |
+
if not signum:
|
| 84 |
+
# ignore null bytes written by _write_to_self()
|
| 85 |
+
continue
|
| 86 |
+
self._handle_signal(signum)
|
| 87 |
+
|
| 88 |
+
def add_signal_handler(self, sig, callback, *args):
|
| 89 |
+
"""Add a handler for a signal. UNIX only.
|
| 90 |
+
|
| 91 |
+
Raise ValueError if the signal number is invalid or uncatchable.
|
| 92 |
+
Raise RuntimeError if there is a problem setting up the handler.
|
| 93 |
+
"""
|
| 94 |
+
if (coroutines.iscoroutine(callback) or
|
| 95 |
+
coroutines.iscoroutinefunction(callback)):
|
| 96 |
+
raise TypeError("coroutines cannot be used "
|
| 97 |
+
"with add_signal_handler()")
|
| 98 |
+
self._check_signal(sig)
|
| 99 |
+
self._check_closed()
|
| 100 |
+
try:
|
| 101 |
+
# set_wakeup_fd() raises ValueError if this is not the
|
| 102 |
+
# main thread. By calling it early we ensure that an
|
| 103 |
+
# event loop running in another thread cannot add a signal
|
| 104 |
+
# handler.
|
| 105 |
+
signal.set_wakeup_fd(self._csock.fileno())
|
| 106 |
+
except (ValueError, OSError) as exc:
|
| 107 |
+
raise RuntimeError(str(exc))
|
| 108 |
+
|
| 109 |
+
handle = events.Handle(callback, args, self, None)
|
| 110 |
+
self._signal_handlers[sig] = handle
|
| 111 |
+
|
| 112 |
+
try:
|
| 113 |
+
# Register a dummy signal handler to ask Python to write the signal
|
| 114 |
+
# number in the wakeup file descriptor. _process_self_data() will
|
| 115 |
+
# read signal numbers from this file descriptor to handle signals.
|
| 116 |
+
signal.signal(sig, _sighandler_noop)
|
| 117 |
+
|
| 118 |
+
# Set SA_RESTART to limit EINTR occurrences.
|
| 119 |
+
signal.siginterrupt(sig, False)
|
| 120 |
+
except OSError as exc:
|
| 121 |
+
del self._signal_handlers[sig]
|
| 122 |
+
if not self._signal_handlers:
|
| 123 |
+
try:
|
| 124 |
+
signal.set_wakeup_fd(-1)
|
| 125 |
+
except (ValueError, OSError) as nexc:
|
| 126 |
+
logger.info('set_wakeup_fd(-1) failed: %s', nexc)
|
| 127 |
+
|
| 128 |
+
if exc.errno == errno.EINVAL:
|
| 129 |
+
raise RuntimeError(f'sig {sig} cannot be caught')
|
| 130 |
+
else:
|
| 131 |
+
raise
|
| 132 |
+
|
| 133 |
+
def _handle_signal(self, sig):
|
| 134 |
+
"""Internal helper that is the actual signal handler."""
|
| 135 |
+
handle = self._signal_handlers.get(sig)
|
| 136 |
+
if handle is None:
|
| 137 |
+
return # Assume it's some race condition.
|
| 138 |
+
if handle._cancelled:
|
| 139 |
+
self.remove_signal_handler(sig) # Remove it properly.
|
| 140 |
+
else:
|
| 141 |
+
self._add_callback_signalsafe(handle)
|
| 142 |
+
|
| 143 |
+
def remove_signal_handler(self, sig):
|
| 144 |
+
"""Remove a handler for a signal. UNIX only.
|
| 145 |
+
|
| 146 |
+
Return True if a signal handler was removed, False if not.
|
| 147 |
+
"""
|
| 148 |
+
self._check_signal(sig)
|
| 149 |
+
try:
|
| 150 |
+
del self._signal_handlers[sig]
|
| 151 |
+
except KeyError:
|
| 152 |
+
return False
|
| 153 |
+
|
| 154 |
+
if sig == signal.SIGINT:
|
| 155 |
+
handler = signal.default_int_handler
|
| 156 |
+
else:
|
| 157 |
+
handler = signal.SIG_DFL
|
| 158 |
+
|
| 159 |
+
try:
|
| 160 |
+
signal.signal(sig, handler)
|
| 161 |
+
except OSError as exc:
|
| 162 |
+
if exc.errno == errno.EINVAL:
|
| 163 |
+
raise RuntimeError(f'sig {sig} cannot be caught')
|
| 164 |
+
else:
|
| 165 |
+
raise
|
| 166 |
+
|
| 167 |
+
if not self._signal_handlers:
|
| 168 |
+
try:
|
| 169 |
+
signal.set_wakeup_fd(-1)
|
| 170 |
+
except (ValueError, OSError) as exc:
|
| 171 |
+
logger.info('set_wakeup_fd(-1) failed: %s', exc)
|
| 172 |
+
|
| 173 |
+
return True
|
| 174 |
+
|
| 175 |
+
def _check_signal(self, sig):
|
| 176 |
+
"""Internal helper to validate a signal.
|
| 177 |
+
|
| 178 |
+
Raise ValueError if the signal number is invalid or uncatchable.
|
| 179 |
+
Raise RuntimeError if there is a problem setting up the handler.
|
| 180 |
+
"""
|
| 181 |
+
if not isinstance(sig, int):
|
| 182 |
+
raise TypeError(f'sig must be an int, not {sig!r}')
|
| 183 |
+
|
| 184 |
+
if sig not in signal.valid_signals():
|
| 185 |
+
raise ValueError(f'invalid signal number {sig}')
|
| 186 |
+
|
| 187 |
+
def _make_read_pipe_transport(self, pipe, protocol, waiter=None,
|
| 188 |
+
extra=None):
|
| 189 |
+
return _UnixReadPipeTransport(self, pipe, protocol, waiter, extra)
|
| 190 |
+
|
| 191 |
+
def _make_write_pipe_transport(self, pipe, protocol, waiter=None,
|
| 192 |
+
extra=None):
|
| 193 |
+
return _UnixWritePipeTransport(self, pipe, protocol, waiter, extra)
|
| 194 |
+
|
| 195 |
+
async def _make_subprocess_transport(self, protocol, args, shell,
|
| 196 |
+
stdin, stdout, stderr, bufsize,
|
| 197 |
+
extra=None, **kwargs):
|
| 198 |
+
with events.get_child_watcher() as watcher:
|
| 199 |
+
if not watcher.is_active():
|
| 200 |
+
# Check early.
|
| 201 |
+
# Raising exception before process creation
|
| 202 |
+
# prevents subprocess execution if the watcher
|
| 203 |
+
# is not ready to handle it.
|
| 204 |
+
raise RuntimeError("asyncio.get_child_watcher() is not activated, "
|
| 205 |
+
"subprocess support is not installed.")
|
| 206 |
+
waiter = self.create_future()
|
| 207 |
+
transp = _UnixSubprocessTransport(self, protocol, args, shell,
|
| 208 |
+
stdin, stdout, stderr, bufsize,
|
| 209 |
+
waiter=waiter, extra=extra,
|
| 210 |
+
**kwargs)
|
| 211 |
+
|
| 212 |
+
watcher.add_child_handler(transp.get_pid(),
|
| 213 |
+
self._child_watcher_callback, transp)
|
| 214 |
+
try:
|
| 215 |
+
await waiter
|
| 216 |
+
except (SystemExit, KeyboardInterrupt):
|
| 217 |
+
raise
|
| 218 |
+
except BaseException:
|
| 219 |
+
transp.close()
|
| 220 |
+
await transp._wait()
|
| 221 |
+
raise
|
| 222 |
+
|
| 223 |
+
return transp
|
| 224 |
+
|
| 225 |
+
def _child_watcher_callback(self, pid, returncode, transp):
|
| 226 |
+
# Skip one iteration for callbacks to be executed
|
| 227 |
+
self.call_soon_threadsafe(self.call_soon, transp._process_exited, returncode)
|
| 228 |
+
|
| 229 |
+
async def create_unix_connection(
|
| 230 |
+
self, protocol_factory, path=None, *,
|
| 231 |
+
ssl=None, sock=None,
|
| 232 |
+
server_hostname=None,
|
| 233 |
+
ssl_handshake_timeout=None):
|
| 234 |
+
assert server_hostname is None or isinstance(server_hostname, str)
|
| 235 |
+
if ssl:
|
| 236 |
+
if server_hostname is None:
|
| 237 |
+
raise ValueError(
|
| 238 |
+
'you have to pass server_hostname when using ssl')
|
| 239 |
+
else:
|
| 240 |
+
if server_hostname is not None:
|
| 241 |
+
raise ValueError('server_hostname is only meaningful with ssl')
|
| 242 |
+
if ssl_handshake_timeout is not None:
|
| 243 |
+
raise ValueError(
|
| 244 |
+
'ssl_handshake_timeout is only meaningful with ssl')
|
| 245 |
+
|
| 246 |
+
if path is not None:
|
| 247 |
+
if sock is not None:
|
| 248 |
+
raise ValueError(
|
| 249 |
+
'path and sock can not be specified at the same time')
|
| 250 |
+
|
| 251 |
+
path = os.fspath(path)
|
| 252 |
+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0)
|
| 253 |
+
try:
|
| 254 |
+
sock.setblocking(False)
|
| 255 |
+
await self.sock_connect(sock, path)
|
| 256 |
+
except:
|
| 257 |
+
sock.close()
|
| 258 |
+
raise
|
| 259 |
+
|
| 260 |
+
else:
|
| 261 |
+
if sock is None:
|
| 262 |
+
raise ValueError('no path and sock were specified')
|
| 263 |
+
if (sock.family != socket.AF_UNIX or
|
| 264 |
+
sock.type != socket.SOCK_STREAM):
|
| 265 |
+
raise ValueError(
|
| 266 |
+
f'A UNIX Domain Stream Socket was expected, got {sock!r}')
|
| 267 |
+
sock.setblocking(False)
|
| 268 |
+
|
| 269 |
+
transport, protocol = await self._create_connection_transport(
|
| 270 |
+
sock, protocol_factory, ssl, server_hostname,
|
| 271 |
+
ssl_handshake_timeout=ssl_handshake_timeout)
|
| 272 |
+
return transport, protocol
|
| 273 |
+
|
| 274 |
+
async def create_unix_server(
|
| 275 |
+
self, protocol_factory, path=None, *,
|
| 276 |
+
sock=None, backlog=100, ssl=None,
|
| 277 |
+
ssl_handshake_timeout=None,
|
| 278 |
+
start_serving=True):
|
| 279 |
+
if isinstance(ssl, bool):
|
| 280 |
+
raise TypeError('ssl argument must be an SSLContext or None')
|
| 281 |
+
|
| 282 |
+
if ssl_handshake_timeout is not None and not ssl:
|
| 283 |
+
raise ValueError(
|
| 284 |
+
'ssl_handshake_timeout is only meaningful with ssl')
|
| 285 |
+
|
| 286 |
+
if path is not None:
|
| 287 |
+
if sock is not None:
|
| 288 |
+
raise ValueError(
|
| 289 |
+
'path and sock can not be specified at the same time')
|
| 290 |
+
|
| 291 |
+
path = os.fspath(path)
|
| 292 |
+
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
| 293 |
+
|
| 294 |
+
# Check for abstract socket. `str` and `bytes` paths are supported.
|
| 295 |
+
if path[0] not in (0, '\x00'):
|
| 296 |
+
try:
|
| 297 |
+
if stat.S_ISSOCK(os.stat(path).st_mode):
|
| 298 |
+
os.remove(path)
|
| 299 |
+
except FileNotFoundError:
|
| 300 |
+
pass
|
| 301 |
+
except OSError as err:
|
| 302 |
+
# Directory may have permissions only to create socket.
|
| 303 |
+
logger.error('Unable to check or remove stale UNIX socket '
|
| 304 |
+
'%r: %r', path, err)
|
| 305 |
+
|
| 306 |
+
try:
|
| 307 |
+
sock.bind(path)
|
| 308 |
+
except OSError as exc:
|
| 309 |
+
sock.close()
|
| 310 |
+
if exc.errno == errno.EADDRINUSE:
|
| 311 |
+
# Let's improve the error message by adding
|
| 312 |
+
# with what exact address it occurs.
|
| 313 |
+
msg = f'Address {path!r} is already in use'
|
| 314 |
+
raise OSError(errno.EADDRINUSE, msg) from None
|
| 315 |
+
else:
|
| 316 |
+
raise
|
| 317 |
+
except:
|
| 318 |
+
sock.close()
|
| 319 |
+
raise
|
| 320 |
+
else:
|
| 321 |
+
if sock is None:
|
| 322 |
+
raise ValueError(
|
| 323 |
+
'path was not specified, and no sock specified')
|
| 324 |
+
|
| 325 |
+
if (sock.family != socket.AF_UNIX or
|
| 326 |
+
sock.type != socket.SOCK_STREAM):
|
| 327 |
+
raise ValueError(
|
| 328 |
+
f'A UNIX Domain Stream Socket was expected, got {sock!r}')
|
| 329 |
+
|
| 330 |
+
sock.setblocking(False)
|
| 331 |
+
server = base_events.Server(self, [sock], protocol_factory,
|
| 332 |
+
ssl, backlog, ssl_handshake_timeout)
|
| 333 |
+
if start_serving:
|
| 334 |
+
server._start_serving()
|
| 335 |
+
# Skip one loop iteration so that all 'loop.add_reader'
|
| 336 |
+
# go through.
|
| 337 |
+
await tasks.sleep(0)
|
| 338 |
+
|
| 339 |
+
return server
|
| 340 |
+
|
| 341 |
+
async def _sock_sendfile_native(self, sock, file, offset, count):
|
| 342 |
+
try:
|
| 343 |
+
os.sendfile
|
| 344 |
+
except AttributeError:
|
| 345 |
+
raise exceptions.SendfileNotAvailableError(
|
| 346 |
+
"os.sendfile() is not available")
|
| 347 |
+
try:
|
| 348 |
+
fileno = file.fileno()
|
| 349 |
+
except (AttributeError, io.UnsupportedOperation) as err:
|
| 350 |
+
raise exceptions.SendfileNotAvailableError("not a regular file")
|
| 351 |
+
try:
|
| 352 |
+
fsize = os.fstat(fileno).st_size
|
| 353 |
+
except OSError:
|
| 354 |
+
raise exceptions.SendfileNotAvailableError("not a regular file")
|
| 355 |
+
blocksize = count if count else fsize
|
| 356 |
+
if not blocksize:
|
| 357 |
+
return 0 # empty file
|
| 358 |
+
|
| 359 |
+
fut = self.create_future()
|
| 360 |
+
self._sock_sendfile_native_impl(fut, None, sock, fileno,
|
| 361 |
+
offset, count, blocksize, 0)
|
| 362 |
+
return await fut
|
| 363 |
+
|
| 364 |
+
def _sock_sendfile_native_impl(self, fut, registered_fd, sock, fileno,
|
| 365 |
+
offset, count, blocksize, total_sent):
|
| 366 |
+
fd = sock.fileno()
|
| 367 |
+
if registered_fd is not None:
|
| 368 |
+
# Remove the callback early. It should be rare that the
|
| 369 |
+
# selector says the fd is ready but the call still returns
|
| 370 |
+
# EAGAIN, and I am willing to take a hit in that case in
|
| 371 |
+
# order to simplify the common case.
|
| 372 |
+
self.remove_writer(registered_fd)
|
| 373 |
+
if fut.cancelled():
|
| 374 |
+
self._sock_sendfile_update_filepos(fileno, offset, total_sent)
|
| 375 |
+
return
|
| 376 |
+
if count:
|
| 377 |
+
blocksize = count - total_sent
|
| 378 |
+
if blocksize <= 0:
|
| 379 |
+
self._sock_sendfile_update_filepos(fileno, offset, total_sent)
|
| 380 |
+
fut.set_result(total_sent)
|
| 381 |
+
return
|
| 382 |
+
|
| 383 |
+
try:
|
| 384 |
+
sent = os.sendfile(fd, fileno, offset, blocksize)
|
| 385 |
+
except (BlockingIOError, InterruptedError):
|
| 386 |
+
if registered_fd is None:
|
| 387 |
+
self._sock_add_cancellation_callback(fut, sock)
|
| 388 |
+
self.add_writer(fd, self._sock_sendfile_native_impl, fut,
|
| 389 |
+
fd, sock, fileno,
|
| 390 |
+
offset, count, blocksize, total_sent)
|
| 391 |
+
except OSError as exc:
|
| 392 |
+
if (registered_fd is not None and
|
| 393 |
+
exc.errno == errno.ENOTCONN and
|
| 394 |
+
type(exc) is not ConnectionError):
|
| 395 |
+
# If we have an ENOTCONN and this isn't a first call to
|
| 396 |
+
# sendfile(), i.e. the connection was closed in the middle
|
| 397 |
+
# of the operation, normalize the error to ConnectionError
|
| 398 |
+
# to make it consistent across all Posix systems.
|
| 399 |
+
new_exc = ConnectionError(
|
| 400 |
+
"socket is not connected", errno.ENOTCONN)
|
| 401 |
+
new_exc.__cause__ = exc
|
| 402 |
+
exc = new_exc
|
| 403 |
+
if total_sent == 0:
|
| 404 |
+
# We can get here for different reasons, the main
|
| 405 |
+
# one being 'file' is not a regular mmap(2)-like
|
| 406 |
+
# file, in which case we'll fall back on using
|
| 407 |
+
# plain send().
|
| 408 |
+
err = exceptions.SendfileNotAvailableError(
|
| 409 |
+
"os.sendfile call failed")
|
| 410 |
+
self._sock_sendfile_update_filepos(fileno, offset, total_sent)
|
| 411 |
+
fut.set_exception(err)
|
| 412 |
+
else:
|
| 413 |
+
self._sock_sendfile_update_filepos(fileno, offset, total_sent)
|
| 414 |
+
fut.set_exception(exc)
|
| 415 |
+
except (SystemExit, KeyboardInterrupt):
|
| 416 |
+
raise
|
| 417 |
+
except BaseException as exc:
|
| 418 |
+
self._sock_sendfile_update_filepos(fileno, offset, total_sent)
|
| 419 |
+
fut.set_exception(exc)
|
| 420 |
+
else:
|
| 421 |
+
if sent == 0:
|
| 422 |
+
# EOF
|
| 423 |
+
self._sock_sendfile_update_filepos(fileno, offset, total_sent)
|
| 424 |
+
fut.set_result(total_sent)
|
| 425 |
+
else:
|
| 426 |
+
offset += sent
|
| 427 |
+
total_sent += sent
|
| 428 |
+
if registered_fd is None:
|
| 429 |
+
self._sock_add_cancellation_callback(fut, sock)
|
| 430 |
+
self.add_writer(fd, self._sock_sendfile_native_impl, fut,
|
| 431 |
+
fd, sock, fileno,
|
| 432 |
+
offset, count, blocksize, total_sent)
|
| 433 |
+
|
| 434 |
+
def _sock_sendfile_update_filepos(self, fileno, offset, total_sent):
|
| 435 |
+
if total_sent > 0:
|
| 436 |
+
os.lseek(fileno, offset, os.SEEK_SET)
|
| 437 |
+
|
| 438 |
+
def _sock_add_cancellation_callback(self, fut, sock):
|
| 439 |
+
def cb(fut):
|
| 440 |
+
if fut.cancelled():
|
| 441 |
+
fd = sock.fileno()
|
| 442 |
+
if fd != -1:
|
| 443 |
+
self.remove_writer(fd)
|
| 444 |
+
fut.add_done_callback(cb)
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
class _UnixReadPipeTransport(transports.ReadTransport):
|
| 448 |
+
|
| 449 |
+
max_size = 256 * 1024 # max bytes we read in one event loop iteration
|
| 450 |
+
|
| 451 |
+
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
|
| 452 |
+
super().__init__(extra)
|
| 453 |
+
self._extra['pipe'] = pipe
|
| 454 |
+
self._loop = loop
|
| 455 |
+
self._pipe = pipe
|
| 456 |
+
self._fileno = pipe.fileno()
|
| 457 |
+
self._protocol = protocol
|
| 458 |
+
self._closing = False
|
| 459 |
+
self._paused = False
|
| 460 |
+
|
| 461 |
+
mode = os.fstat(self._fileno).st_mode
|
| 462 |
+
if not (stat.S_ISFIFO(mode) or
|
| 463 |
+
stat.S_ISSOCK(mode) or
|
| 464 |
+
stat.S_ISCHR(mode)):
|
| 465 |
+
self._pipe = None
|
| 466 |
+
self._fileno = None
|
| 467 |
+
self._protocol = None
|
| 468 |
+
raise ValueError("Pipe transport is for pipes/sockets only.")
|
| 469 |
+
|
| 470 |
+
os.set_blocking(self._fileno, False)
|
| 471 |
+
|
| 472 |
+
self._loop.call_soon(self._protocol.connection_made, self)
|
| 473 |
+
# only start reading when connection_made() has been called
|
| 474 |
+
self._loop.call_soon(self._loop._add_reader,
|
| 475 |
+
self._fileno, self._read_ready)
|
| 476 |
+
if waiter is not None:
|
| 477 |
+
# only wake up the waiter when connection_made() has been called
|
| 478 |
+
self._loop.call_soon(futures._set_result_unless_cancelled,
|
| 479 |
+
waiter, None)
|
| 480 |
+
|
| 481 |
+
def __repr__(self):
|
| 482 |
+
info = [self.__class__.__name__]
|
| 483 |
+
if self._pipe is None:
|
| 484 |
+
info.append('closed')
|
| 485 |
+
elif self._closing:
|
| 486 |
+
info.append('closing')
|
| 487 |
+
info.append(f'fd={self._fileno}')
|
| 488 |
+
selector = getattr(self._loop, '_selector', None)
|
| 489 |
+
if self._pipe is not None and selector is not None:
|
| 490 |
+
polling = selector_events._test_selector_event(
|
| 491 |
+
selector, self._fileno, selectors.EVENT_READ)
|
| 492 |
+
if polling:
|
| 493 |
+
info.append('polling')
|
| 494 |
+
else:
|
| 495 |
+
info.append('idle')
|
| 496 |
+
elif self._pipe is not None:
|
| 497 |
+
info.append('open')
|
| 498 |
+
else:
|
| 499 |
+
info.append('closed')
|
| 500 |
+
return '<{}>'.format(' '.join(info))
|
| 501 |
+
|
| 502 |
+
def _read_ready(self):
|
| 503 |
+
try:
|
| 504 |
+
data = os.read(self._fileno, self.max_size)
|
| 505 |
+
except (BlockingIOError, InterruptedError):
|
| 506 |
+
pass
|
| 507 |
+
except OSError as exc:
|
| 508 |
+
self._fatal_error(exc, 'Fatal read error on pipe transport')
|
| 509 |
+
else:
|
| 510 |
+
if data:
|
| 511 |
+
self._protocol.data_received(data)
|
| 512 |
+
else:
|
| 513 |
+
if self._loop.get_debug():
|
| 514 |
+
logger.info("%r was closed by peer", self)
|
| 515 |
+
self._closing = True
|
| 516 |
+
self._loop._remove_reader(self._fileno)
|
| 517 |
+
self._loop.call_soon(self._protocol.eof_received)
|
| 518 |
+
self._loop.call_soon(self._call_connection_lost, None)
|
| 519 |
+
|
| 520 |
+
def pause_reading(self):
|
| 521 |
+
if self._closing or self._paused:
|
| 522 |
+
return
|
| 523 |
+
self._paused = True
|
| 524 |
+
self._loop._remove_reader(self._fileno)
|
| 525 |
+
if self._loop.get_debug():
|
| 526 |
+
logger.debug("%r pauses reading", self)
|
| 527 |
+
|
| 528 |
+
def resume_reading(self):
|
| 529 |
+
if self._closing or not self._paused:
|
| 530 |
+
return
|
| 531 |
+
self._paused = False
|
| 532 |
+
self._loop._add_reader(self._fileno, self._read_ready)
|
| 533 |
+
if self._loop.get_debug():
|
| 534 |
+
logger.debug("%r resumes reading", self)
|
| 535 |
+
|
| 536 |
+
def set_protocol(self, protocol):
|
| 537 |
+
self._protocol = protocol
|
| 538 |
+
|
| 539 |
+
def get_protocol(self):
|
| 540 |
+
return self._protocol
|
| 541 |
+
|
| 542 |
+
def is_closing(self):
|
| 543 |
+
return self._closing
|
| 544 |
+
|
| 545 |
+
def close(self):
|
| 546 |
+
if not self._closing:
|
| 547 |
+
self._close(None)
|
| 548 |
+
|
| 549 |
+
def __del__(self, _warn=warnings.warn):
|
| 550 |
+
if self._pipe is not None:
|
| 551 |
+
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
|
| 552 |
+
self._pipe.close()
|
| 553 |
+
|
| 554 |
+
def _fatal_error(self, exc, message='Fatal error on pipe transport'):
|
| 555 |
+
# should be called by exception handler only
|
| 556 |
+
if (isinstance(exc, OSError) and exc.errno == errno.EIO):
|
| 557 |
+
if self._loop.get_debug():
|
| 558 |
+
logger.debug("%r: %s", self, message, exc_info=True)
|
| 559 |
+
else:
|
| 560 |
+
self._loop.call_exception_handler({
|
| 561 |
+
'message': message,
|
| 562 |
+
'exception': exc,
|
| 563 |
+
'transport': self,
|
| 564 |
+
'protocol': self._protocol,
|
| 565 |
+
})
|
| 566 |
+
self._close(exc)
|
| 567 |
+
|
| 568 |
+
def _close(self, exc):
|
| 569 |
+
self._closing = True
|
| 570 |
+
self._loop._remove_reader(self._fileno)
|
| 571 |
+
self._loop.call_soon(self._call_connection_lost, exc)
|
| 572 |
+
|
| 573 |
+
def _call_connection_lost(self, exc):
|
| 574 |
+
try:
|
| 575 |
+
self._protocol.connection_lost(exc)
|
| 576 |
+
finally:
|
| 577 |
+
self._pipe.close()
|
| 578 |
+
self._pipe = None
|
| 579 |
+
self._protocol = None
|
| 580 |
+
self._loop = None
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
class _UnixWritePipeTransport(transports._FlowControlMixin,
|
| 584 |
+
transports.WriteTransport):
|
| 585 |
+
|
| 586 |
+
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
|
| 587 |
+
super().__init__(extra, loop)
|
| 588 |
+
self._extra['pipe'] = pipe
|
| 589 |
+
self._pipe = pipe
|
| 590 |
+
self._fileno = pipe.fileno()
|
| 591 |
+
self._protocol = protocol
|
| 592 |
+
self._buffer = bytearray()
|
| 593 |
+
self._conn_lost = 0
|
| 594 |
+
self._closing = False # Set when close() or write_eof() called.
|
| 595 |
+
|
| 596 |
+
mode = os.fstat(self._fileno).st_mode
|
| 597 |
+
is_char = stat.S_ISCHR(mode)
|
| 598 |
+
is_fifo = stat.S_ISFIFO(mode)
|
| 599 |
+
is_socket = stat.S_ISSOCK(mode)
|
| 600 |
+
if not (is_char or is_fifo or is_socket):
|
| 601 |
+
self._pipe = None
|
| 602 |
+
self._fileno = None
|
| 603 |
+
self._protocol = None
|
| 604 |
+
raise ValueError("Pipe transport is only for "
|
| 605 |
+
"pipes, sockets and character devices")
|
| 606 |
+
|
| 607 |
+
os.set_blocking(self._fileno, False)
|
| 608 |
+
self._loop.call_soon(self._protocol.connection_made, self)
|
| 609 |
+
|
| 610 |
+
# On AIX, the reader trick (to be notified when the read end of the
|
| 611 |
+
# socket is closed) only works for sockets. On other platforms it
|
| 612 |
+
# works for pipes and sockets. (Exception: OS X 10.4? Issue #19294.)
|
| 613 |
+
if is_socket or (is_fifo and not sys.platform.startswith("aix")):
|
| 614 |
+
# only start reading when connection_made() has been called
|
| 615 |
+
self._loop.call_soon(self._loop._add_reader,
|
| 616 |
+
self._fileno, self._read_ready)
|
| 617 |
+
|
| 618 |
+
if waiter is not None:
|
| 619 |
+
# only wake up the waiter when connection_made() has been called
|
| 620 |
+
self._loop.call_soon(futures._set_result_unless_cancelled,
|
| 621 |
+
waiter, None)
|
| 622 |
+
|
| 623 |
+
def __repr__(self):
|
| 624 |
+
info = [self.__class__.__name__]
|
| 625 |
+
if self._pipe is None:
|
| 626 |
+
info.append('closed')
|
| 627 |
+
elif self._closing:
|
| 628 |
+
info.append('closing')
|
| 629 |
+
info.append(f'fd={self._fileno}')
|
| 630 |
+
selector = getattr(self._loop, '_selector', None)
|
| 631 |
+
if self._pipe is not None and selector is not None:
|
| 632 |
+
polling = selector_events._test_selector_event(
|
| 633 |
+
selector, self._fileno, selectors.EVENT_WRITE)
|
| 634 |
+
if polling:
|
| 635 |
+
info.append('polling')
|
| 636 |
+
else:
|
| 637 |
+
info.append('idle')
|
| 638 |
+
|
| 639 |
+
bufsize = self.get_write_buffer_size()
|
| 640 |
+
info.append(f'bufsize={bufsize}')
|
| 641 |
+
elif self._pipe is not None:
|
| 642 |
+
info.append('open')
|
| 643 |
+
else:
|
| 644 |
+
info.append('closed')
|
| 645 |
+
return '<{}>'.format(' '.join(info))
|
| 646 |
+
|
| 647 |
+
def get_write_buffer_size(self):
|
| 648 |
+
return len(self._buffer)
|
| 649 |
+
|
| 650 |
+
def _read_ready(self):
|
| 651 |
+
# Pipe was closed by peer.
|
| 652 |
+
if self._loop.get_debug():
|
| 653 |
+
logger.info("%r was closed by peer", self)
|
| 654 |
+
if self._buffer:
|
| 655 |
+
self._close(BrokenPipeError())
|
| 656 |
+
else:
|
| 657 |
+
self._close()
|
| 658 |
+
|
| 659 |
+
def write(self, data):
|
| 660 |
+
assert isinstance(data, (bytes, bytearray, memoryview)), repr(data)
|
| 661 |
+
if isinstance(data, bytearray):
|
| 662 |
+
data = memoryview(data)
|
| 663 |
+
if not data:
|
| 664 |
+
return
|
| 665 |
+
|
| 666 |
+
if self._conn_lost or self._closing:
|
| 667 |
+
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
|
| 668 |
+
logger.warning('pipe closed by peer or '
|
| 669 |
+
'os.write(pipe, data) raised exception.')
|
| 670 |
+
self._conn_lost += 1
|
| 671 |
+
return
|
| 672 |
+
|
| 673 |
+
if not self._buffer:
|
| 674 |
+
# Attempt to send it right away first.
|
| 675 |
+
try:
|
| 676 |
+
n = os.write(self._fileno, data)
|
| 677 |
+
except (BlockingIOError, InterruptedError):
|
| 678 |
+
n = 0
|
| 679 |
+
except (SystemExit, KeyboardInterrupt):
|
| 680 |
+
raise
|
| 681 |
+
except BaseException as exc:
|
| 682 |
+
self._conn_lost += 1
|
| 683 |
+
self._fatal_error(exc, 'Fatal write error on pipe transport')
|
| 684 |
+
return
|
| 685 |
+
if n == len(data):
|
| 686 |
+
return
|
| 687 |
+
elif n > 0:
|
| 688 |
+
data = memoryview(data)[n:]
|
| 689 |
+
self._loop._add_writer(self._fileno, self._write_ready)
|
| 690 |
+
|
| 691 |
+
self._buffer += data
|
| 692 |
+
self._maybe_pause_protocol()
|
| 693 |
+
|
| 694 |
+
def _write_ready(self):
|
| 695 |
+
assert self._buffer, 'Data should not be empty'
|
| 696 |
+
|
| 697 |
+
try:
|
| 698 |
+
n = os.write(self._fileno, self._buffer)
|
| 699 |
+
except (BlockingIOError, InterruptedError):
|
| 700 |
+
pass
|
| 701 |
+
except (SystemExit, KeyboardInterrupt):
|
| 702 |
+
raise
|
| 703 |
+
except BaseException as exc:
|
| 704 |
+
self._buffer.clear()
|
| 705 |
+
self._conn_lost += 1
|
| 706 |
+
# Remove writer here, _fatal_error() doesn't it
|
| 707 |
+
# because _buffer is empty.
|
| 708 |
+
self._loop._remove_writer(self._fileno)
|
| 709 |
+
self._fatal_error(exc, 'Fatal write error on pipe transport')
|
| 710 |
+
else:
|
| 711 |
+
if n == len(self._buffer):
|
| 712 |
+
self._buffer.clear()
|
| 713 |
+
self._loop._remove_writer(self._fileno)
|
| 714 |
+
self._maybe_resume_protocol() # May append to buffer.
|
| 715 |
+
if self._closing:
|
| 716 |
+
self._loop._remove_reader(self._fileno)
|
| 717 |
+
self._call_connection_lost(None)
|
| 718 |
+
return
|
| 719 |
+
elif n > 0:
|
| 720 |
+
del self._buffer[:n]
|
| 721 |
+
|
| 722 |
+
def can_write_eof(self):
|
| 723 |
+
return True
|
| 724 |
+
|
| 725 |
+
def write_eof(self):
|
| 726 |
+
if self._closing:
|
| 727 |
+
return
|
| 728 |
+
assert self._pipe
|
| 729 |
+
self._closing = True
|
| 730 |
+
if not self._buffer:
|
| 731 |
+
self._loop._remove_reader(self._fileno)
|
| 732 |
+
self._loop.call_soon(self._call_connection_lost, None)
|
| 733 |
+
|
| 734 |
+
def set_protocol(self, protocol):
|
| 735 |
+
self._protocol = protocol
|
| 736 |
+
|
| 737 |
+
def get_protocol(self):
|
| 738 |
+
return self._protocol
|
| 739 |
+
|
| 740 |
+
def is_closing(self):
|
| 741 |
+
return self._closing
|
| 742 |
+
|
| 743 |
+
def close(self):
|
| 744 |
+
if self._pipe is not None and not self._closing:
|
| 745 |
+
# write_eof is all what we needed to close the write pipe
|
| 746 |
+
self.write_eof()
|
| 747 |
+
|
| 748 |
+
def __del__(self, _warn=warnings.warn):
|
| 749 |
+
if self._pipe is not None:
|
| 750 |
+
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
|
| 751 |
+
self._pipe.close()
|
| 752 |
+
|
| 753 |
+
def abort(self):
|
| 754 |
+
self._close(None)
|
| 755 |
+
|
| 756 |
+
def _fatal_error(self, exc, message='Fatal error on pipe transport'):
|
| 757 |
+
# should be called by exception handler only
|
| 758 |
+
if isinstance(exc, OSError):
|
| 759 |
+
if self._loop.get_debug():
|
| 760 |
+
logger.debug("%r: %s", self, message, exc_info=True)
|
| 761 |
+
else:
|
| 762 |
+
self._loop.call_exception_handler({
|
| 763 |
+
'message': message,
|
| 764 |
+
'exception': exc,
|
| 765 |
+
'transport': self,
|
| 766 |
+
'protocol': self._protocol,
|
| 767 |
+
})
|
| 768 |
+
self._close(exc)
|
| 769 |
+
|
| 770 |
+
def _close(self, exc=None):
|
| 771 |
+
self._closing = True
|
| 772 |
+
if self._buffer:
|
| 773 |
+
self._loop._remove_writer(self._fileno)
|
| 774 |
+
self._buffer.clear()
|
| 775 |
+
self._loop._remove_reader(self._fileno)
|
| 776 |
+
self._loop.call_soon(self._call_connection_lost, exc)
|
| 777 |
+
|
| 778 |
+
def _call_connection_lost(self, exc):
|
| 779 |
+
try:
|
| 780 |
+
self._protocol.connection_lost(exc)
|
| 781 |
+
finally:
|
| 782 |
+
self._pipe.close()
|
| 783 |
+
self._pipe = None
|
| 784 |
+
self._protocol = None
|
| 785 |
+
self._loop = None
|
| 786 |
+
|
| 787 |
+
|
| 788 |
+
class _UnixSubprocessTransport(base_subprocess.BaseSubprocessTransport):
|
| 789 |
+
|
| 790 |
+
def _start(self, args, shell, stdin, stdout, stderr, bufsize, **kwargs):
|
| 791 |
+
stdin_w = None
|
| 792 |
+
if stdin == subprocess.PIPE and sys.platform.startswith('aix'):
|
| 793 |
+
# Use a socket pair for stdin on AIX, since it does not
|
| 794 |
+
# support selecting read events on the write end of a
|
| 795 |
+
# socket (which we use in order to detect closing of the
|
| 796 |
+
# other end).
|
| 797 |
+
stdin, stdin_w = socket.socketpair()
|
| 798 |
+
try:
|
| 799 |
+
self._proc = subprocess.Popen(
|
| 800 |
+
args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr,
|
| 801 |
+
universal_newlines=False, bufsize=bufsize, **kwargs)
|
| 802 |
+
if stdin_w is not None:
|
| 803 |
+
stdin.close()
|
| 804 |
+
self._proc.stdin = open(stdin_w.detach(), 'wb', buffering=bufsize)
|
| 805 |
+
stdin_w = None
|
| 806 |
+
finally:
|
| 807 |
+
if stdin_w is not None:
|
| 808 |
+
stdin.close()
|
| 809 |
+
stdin_w.close()
|
| 810 |
+
|
| 811 |
+
|
| 812 |
+
class AbstractChildWatcher:
|
| 813 |
+
"""Abstract base class for monitoring child processes.
|
| 814 |
+
|
| 815 |
+
Objects derived from this class monitor a collection of subprocesses and
|
| 816 |
+
report their termination or interruption by a signal.
|
| 817 |
+
|
| 818 |
+
New callbacks are registered with .add_child_handler(). Starting a new
|
| 819 |
+
process must be done within a 'with' block to allow the watcher to suspend
|
| 820 |
+
its activity until the new process if fully registered (this is needed to
|
| 821 |
+
prevent a race condition in some implementations).
|
| 822 |
+
|
| 823 |
+
Example:
|
| 824 |
+
with watcher:
|
| 825 |
+
proc = subprocess.Popen("sleep 1")
|
| 826 |
+
watcher.add_child_handler(proc.pid, callback)
|
| 827 |
+
|
| 828 |
+
Notes:
|
| 829 |
+
Implementations of this class must be thread-safe.
|
| 830 |
+
|
| 831 |
+
Since child watcher objects may catch the SIGCHLD signal and call
|
| 832 |
+
waitpid(-1), there should be only one active object per process.
|
| 833 |
+
"""
|
| 834 |
+
|
| 835 |
+
def add_child_handler(self, pid, callback, *args):
|
| 836 |
+
"""Register a new child handler.
|
| 837 |
+
|
| 838 |
+
Arrange for callback(pid, returncode, *args) to be called when
|
| 839 |
+
process 'pid' terminates. Specifying another callback for the same
|
| 840 |
+
process replaces the previous handler.
|
| 841 |
+
|
| 842 |
+
Note: callback() must be thread-safe.
|
| 843 |
+
"""
|
| 844 |
+
raise NotImplementedError()
|
| 845 |
+
|
| 846 |
+
def remove_child_handler(self, pid):
|
| 847 |
+
"""Removes the handler for process 'pid'.
|
| 848 |
+
|
| 849 |
+
The function returns True if the handler was successfully removed,
|
| 850 |
+
False if there was nothing to remove."""
|
| 851 |
+
|
| 852 |
+
raise NotImplementedError()
|
| 853 |
+
|
| 854 |
+
def attach_loop(self, loop):
|
| 855 |
+
"""Attach the watcher to an event loop.
|
| 856 |
+
|
| 857 |
+
If the watcher was previously attached to an event loop, then it is
|
| 858 |
+
first detached before attaching to the new loop.
|
| 859 |
+
|
| 860 |
+
Note: loop may be None.
|
| 861 |
+
"""
|
| 862 |
+
raise NotImplementedError()
|
| 863 |
+
|
| 864 |
+
def close(self):
|
| 865 |
+
"""Close the watcher.
|
| 866 |
+
|
| 867 |
+
This must be called to make sure that any underlying resource is freed.
|
| 868 |
+
"""
|
| 869 |
+
raise NotImplementedError()
|
| 870 |
+
|
| 871 |
+
def is_active(self):
|
| 872 |
+
"""Return ``True`` if the watcher is active and is used by the event loop.
|
| 873 |
+
|
| 874 |
+
Return True if the watcher is installed and ready to handle process exit
|
| 875 |
+
notifications.
|
| 876 |
+
|
| 877 |
+
"""
|
| 878 |
+
raise NotImplementedError()
|
| 879 |
+
|
| 880 |
+
def __enter__(self):
|
| 881 |
+
"""Enter the watcher's context and allow starting new processes
|
| 882 |
+
|
| 883 |
+
This function must return self"""
|
| 884 |
+
raise NotImplementedError()
|
| 885 |
+
|
| 886 |
+
def __exit__(self, a, b, c):
|
| 887 |
+
"""Exit the watcher's context"""
|
| 888 |
+
raise NotImplementedError()
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
class PidfdChildWatcher(AbstractChildWatcher):
|
| 892 |
+
"""Child watcher implementation using Linux's pid file descriptors.
|
| 893 |
+
|
| 894 |
+
This child watcher polls process file descriptors (pidfds) to await child
|
| 895 |
+
process termination. In some respects, PidfdChildWatcher is a "Goldilocks"
|
| 896 |
+
child watcher implementation. It doesn't require signals or threads, doesn't
|
| 897 |
+
interfere with any processes launched outside the event loop, and scales
|
| 898 |
+
linearly with the number of subprocesses launched by the event loop. The
|
| 899 |
+
main disadvantage is that pidfds are specific to Linux, and only work on
|
| 900 |
+
recent (5.3+) kernels.
|
| 901 |
+
"""
|
| 902 |
+
|
| 903 |
+
def __init__(self):
|
| 904 |
+
self._loop = None
|
| 905 |
+
self._callbacks = {}
|
| 906 |
+
|
| 907 |
+
def __enter__(self):
|
| 908 |
+
return self
|
| 909 |
+
|
| 910 |
+
def __exit__(self, exc_type, exc_value, exc_traceback):
|
| 911 |
+
pass
|
| 912 |
+
|
| 913 |
+
def is_active(self):
|
| 914 |
+
return self._loop is not None and self._loop.is_running()
|
| 915 |
+
|
| 916 |
+
def close(self):
|
| 917 |
+
self.attach_loop(None)
|
| 918 |
+
|
| 919 |
+
def attach_loop(self, loop):
|
| 920 |
+
if self._loop is not None and loop is None and self._callbacks:
|
| 921 |
+
warnings.warn(
|
| 922 |
+
'A loop is being detached '
|
| 923 |
+
'from a child watcher with pending handlers',
|
| 924 |
+
RuntimeWarning)
|
| 925 |
+
for pidfd, _, _ in self._callbacks.values():
|
| 926 |
+
self._loop._remove_reader(pidfd)
|
| 927 |
+
os.close(pidfd)
|
| 928 |
+
self._callbacks.clear()
|
| 929 |
+
self._loop = loop
|
| 930 |
+
|
| 931 |
+
def add_child_handler(self, pid, callback, *args):
|
| 932 |
+
existing = self._callbacks.get(pid)
|
| 933 |
+
if existing is not None:
|
| 934 |
+
self._callbacks[pid] = existing[0], callback, args
|
| 935 |
+
else:
|
| 936 |
+
pidfd = os.pidfd_open(pid)
|
| 937 |
+
self._loop._add_reader(pidfd, self._do_wait, pid)
|
| 938 |
+
self._callbacks[pid] = pidfd, callback, args
|
| 939 |
+
|
| 940 |
+
def _do_wait(self, pid):
|
| 941 |
+
pidfd, callback, args = self._callbacks.pop(pid)
|
| 942 |
+
self._loop._remove_reader(pidfd)
|
| 943 |
+
try:
|
| 944 |
+
_, status = os.waitpid(pid, 0)
|
| 945 |
+
except ChildProcessError:
|
| 946 |
+
# The child process is already reaped
|
| 947 |
+
# (may happen if waitpid() is called elsewhere).
|
| 948 |
+
returncode = 255
|
| 949 |
+
logger.warning(
|
| 950 |
+
"child process pid %d exit status already read: "
|
| 951 |
+
" will report returncode 255",
|
| 952 |
+
pid)
|
| 953 |
+
else:
|
| 954 |
+
returncode = waitstatus_to_exitcode(status)
|
| 955 |
+
|
| 956 |
+
os.close(pidfd)
|
| 957 |
+
callback(pid, returncode, *args)
|
| 958 |
+
|
| 959 |
+
def remove_child_handler(self, pid):
|
| 960 |
+
try:
|
| 961 |
+
pidfd, _, _ = self._callbacks.pop(pid)
|
| 962 |
+
except KeyError:
|
| 963 |
+
return False
|
| 964 |
+
self._loop._remove_reader(pidfd)
|
| 965 |
+
os.close(pidfd)
|
| 966 |
+
return True
|
| 967 |
+
|
| 968 |
+
|
| 969 |
+
class BaseChildWatcher(AbstractChildWatcher):
|
| 970 |
+
|
| 971 |
+
def __init__(self):
|
| 972 |
+
self._loop = None
|
| 973 |
+
self._callbacks = {}
|
| 974 |
+
|
| 975 |
+
def close(self):
|
| 976 |
+
self.attach_loop(None)
|
| 977 |
+
|
| 978 |
+
def is_active(self):
|
| 979 |
+
return self._loop is not None and self._loop.is_running()
|
| 980 |
+
|
| 981 |
+
def _do_waitpid(self, expected_pid):
|
| 982 |
+
raise NotImplementedError()
|
| 983 |
+
|
| 984 |
+
def _do_waitpid_all(self):
|
| 985 |
+
raise NotImplementedError()
|
| 986 |
+
|
| 987 |
+
def attach_loop(self, loop):
|
| 988 |
+
assert loop is None or isinstance(loop, events.AbstractEventLoop)
|
| 989 |
+
|
| 990 |
+
if self._loop is not None and loop is None and self._callbacks:
|
| 991 |
+
warnings.warn(
|
| 992 |
+
'A loop is being detached '
|
| 993 |
+
'from a child watcher with pending handlers',
|
| 994 |
+
RuntimeWarning)
|
| 995 |
+
|
| 996 |
+
if self._loop is not None:
|
| 997 |
+
self._loop.remove_signal_handler(signal.SIGCHLD)
|
| 998 |
+
|
| 999 |
+
self._loop = loop
|
| 1000 |
+
if loop is not None:
|
| 1001 |
+
loop.add_signal_handler(signal.SIGCHLD, self._sig_chld)
|
| 1002 |
+
|
| 1003 |
+
# Prevent a race condition in case a child terminated
|
| 1004 |
+
# during the switch.
|
| 1005 |
+
self._do_waitpid_all()
|
| 1006 |
+
|
| 1007 |
+
def _sig_chld(self):
|
| 1008 |
+
try:
|
| 1009 |
+
self._do_waitpid_all()
|
| 1010 |
+
except (SystemExit, KeyboardInterrupt):
|
| 1011 |
+
raise
|
| 1012 |
+
except BaseException as exc:
|
| 1013 |
+
# self._loop should always be available here
|
| 1014 |
+
# as '_sig_chld' is added as a signal handler
|
| 1015 |
+
# in 'attach_loop'
|
| 1016 |
+
self._loop.call_exception_handler({
|
| 1017 |
+
'message': 'Unknown exception in SIGCHLD handler',
|
| 1018 |
+
'exception': exc,
|
| 1019 |
+
})
|
| 1020 |
+
|
| 1021 |
+
|
| 1022 |
+
class SafeChildWatcher(BaseChildWatcher):
|
| 1023 |
+
"""'Safe' child watcher implementation.
|
| 1024 |
+
|
| 1025 |
+
This implementation avoids disrupting other code spawning processes by
|
| 1026 |
+
polling explicitly each process in the SIGCHLD handler instead of calling
|
| 1027 |
+
os.waitpid(-1).
|
| 1028 |
+
|
| 1029 |
+
This is a safe solution but it has a significant overhead when handling a
|
| 1030 |
+
big number of children (O(n) each time SIGCHLD is raised)
|
| 1031 |
+
"""
|
| 1032 |
+
|
| 1033 |
+
def close(self):
|
| 1034 |
+
self._callbacks.clear()
|
| 1035 |
+
super().close()
|
| 1036 |
+
|
| 1037 |
+
def __enter__(self):
|
| 1038 |
+
return self
|
| 1039 |
+
|
| 1040 |
+
def __exit__(self, a, b, c):
|
| 1041 |
+
pass
|
| 1042 |
+
|
| 1043 |
+
def add_child_handler(self, pid, callback, *args):
|
| 1044 |
+
self._callbacks[pid] = (callback, args)
|
| 1045 |
+
|
| 1046 |
+
# Prevent a race condition in case the child is already terminated.
|
| 1047 |
+
self._do_waitpid(pid)
|
| 1048 |
+
|
| 1049 |
+
def remove_child_handler(self, pid):
|
| 1050 |
+
try:
|
| 1051 |
+
del self._callbacks[pid]
|
| 1052 |
+
return True
|
| 1053 |
+
except KeyError:
|
| 1054 |
+
return False
|
| 1055 |
+
|
| 1056 |
+
def _do_waitpid_all(self):
|
| 1057 |
+
|
| 1058 |
+
for pid in list(self._callbacks):
|
| 1059 |
+
self._do_waitpid(pid)
|
| 1060 |
+
|
| 1061 |
+
def _do_waitpid(self, expected_pid):
|
| 1062 |
+
assert expected_pid > 0
|
| 1063 |
+
|
| 1064 |
+
try:
|
| 1065 |
+
pid, status = os.waitpid(expected_pid, os.WNOHANG)
|
| 1066 |
+
except ChildProcessError:
|
| 1067 |
+
# The child process is already reaped
|
| 1068 |
+
# (may happen if waitpid() is called elsewhere).
|
| 1069 |
+
pid = expected_pid
|
| 1070 |
+
returncode = 255
|
| 1071 |
+
logger.warning(
|
| 1072 |
+
"Unknown child process pid %d, will report returncode 255",
|
| 1073 |
+
pid)
|
| 1074 |
+
else:
|
| 1075 |
+
if pid == 0:
|
| 1076 |
+
# The child process is still alive.
|
| 1077 |
+
return
|
| 1078 |
+
|
| 1079 |
+
returncode = waitstatus_to_exitcode(status)
|
| 1080 |
+
if self._loop.get_debug():
|
| 1081 |
+
logger.debug('process %s exited with returncode %s',
|
| 1082 |
+
expected_pid, returncode)
|
| 1083 |
+
|
| 1084 |
+
try:
|
| 1085 |
+
callback, args = self._callbacks.pop(pid)
|
| 1086 |
+
except KeyError: # pragma: no cover
|
| 1087 |
+
# May happen if .remove_child_handler() is called
|
| 1088 |
+
# after os.waitpid() returns.
|
| 1089 |
+
if self._loop.get_debug():
|
| 1090 |
+
logger.warning("Child watcher got an unexpected pid: %r",
|
| 1091 |
+
pid, exc_info=True)
|
| 1092 |
+
else:
|
| 1093 |
+
callback(pid, returncode, *args)
|
| 1094 |
+
|
| 1095 |
+
|
| 1096 |
+
class FastChildWatcher(BaseChildWatcher):
|
| 1097 |
+
"""'Fast' child watcher implementation.
|
| 1098 |
+
|
| 1099 |
+
This implementation reaps every terminated processes by calling
|
| 1100 |
+
os.waitpid(-1) directly, possibly breaking other code spawning processes
|
| 1101 |
+
and waiting for their termination.
|
| 1102 |
+
|
| 1103 |
+
There is no noticeable overhead when handling a big number of children
|
| 1104 |
+
(O(1) each time a child terminates).
|
| 1105 |
+
"""
|
| 1106 |
+
def __init__(self):
|
| 1107 |
+
super().__init__()
|
| 1108 |
+
self._lock = threading.Lock()
|
| 1109 |
+
self._zombies = {}
|
| 1110 |
+
self._forks = 0
|
| 1111 |
+
|
| 1112 |
+
def close(self):
|
| 1113 |
+
self._callbacks.clear()
|
| 1114 |
+
self._zombies.clear()
|
| 1115 |
+
super().close()
|
| 1116 |
+
|
| 1117 |
+
def __enter__(self):
|
| 1118 |
+
with self._lock:
|
| 1119 |
+
self._forks += 1
|
| 1120 |
+
|
| 1121 |
+
return self
|
| 1122 |
+
|
| 1123 |
+
def __exit__(self, a, b, c):
|
| 1124 |
+
with self._lock:
|
| 1125 |
+
self._forks -= 1
|
| 1126 |
+
|
| 1127 |
+
if self._forks or not self._zombies:
|
| 1128 |
+
return
|
| 1129 |
+
|
| 1130 |
+
collateral_victims = str(self._zombies)
|
| 1131 |
+
self._zombies.clear()
|
| 1132 |
+
|
| 1133 |
+
logger.warning(
|
| 1134 |
+
"Caught subprocesses termination from unknown pids: %s",
|
| 1135 |
+
collateral_victims)
|
| 1136 |
+
|
| 1137 |
+
def add_child_handler(self, pid, callback, *args):
|
| 1138 |
+
assert self._forks, "Must use the context manager"
|
| 1139 |
+
|
| 1140 |
+
with self._lock:
|
| 1141 |
+
try:
|
| 1142 |
+
returncode = self._zombies.pop(pid)
|
| 1143 |
+
except KeyError:
|
| 1144 |
+
# The child is running.
|
| 1145 |
+
self._callbacks[pid] = callback, args
|
| 1146 |
+
return
|
| 1147 |
+
|
| 1148 |
+
# The child is dead already. We can fire the callback.
|
| 1149 |
+
callback(pid, returncode, *args)
|
| 1150 |
+
|
| 1151 |
+
def remove_child_handler(self, pid):
|
| 1152 |
+
try:
|
| 1153 |
+
del self._callbacks[pid]
|
| 1154 |
+
return True
|
| 1155 |
+
except KeyError:
|
| 1156 |
+
return False
|
| 1157 |
+
|
| 1158 |
+
def _do_waitpid_all(self):
|
| 1159 |
+
# Because of signal coalescing, we must keep calling waitpid() as
|
| 1160 |
+
# long as we're able to reap a child.
|
| 1161 |
+
while True:
|
| 1162 |
+
try:
|
| 1163 |
+
pid, status = os.waitpid(-1, os.WNOHANG)
|
| 1164 |
+
except ChildProcessError:
|
| 1165 |
+
# No more child processes exist.
|
| 1166 |
+
return
|
| 1167 |
+
else:
|
| 1168 |
+
if pid == 0:
|
| 1169 |
+
# A child process is still alive.
|
| 1170 |
+
return
|
| 1171 |
+
|
| 1172 |
+
returncode = waitstatus_to_exitcode(status)
|
| 1173 |
+
|
| 1174 |
+
with self._lock:
|
| 1175 |
+
try:
|
| 1176 |
+
callback, args = self._callbacks.pop(pid)
|
| 1177 |
+
except KeyError:
|
| 1178 |
+
# unknown child
|
| 1179 |
+
if self._forks:
|
| 1180 |
+
# It may not be registered yet.
|
| 1181 |
+
self._zombies[pid] = returncode
|
| 1182 |
+
if self._loop.get_debug():
|
| 1183 |
+
logger.debug('unknown process %s exited '
|
| 1184 |
+
'with returncode %s',
|
| 1185 |
+
pid, returncode)
|
| 1186 |
+
continue
|
| 1187 |
+
callback = None
|
| 1188 |
+
else:
|
| 1189 |
+
if self._loop.get_debug():
|
| 1190 |
+
logger.debug('process %s exited with returncode %s',
|
| 1191 |
+
pid, returncode)
|
| 1192 |
+
|
| 1193 |
+
if callback is None:
|
| 1194 |
+
logger.warning(
|
| 1195 |
+
"Caught subprocess termination from unknown pid: "
|
| 1196 |
+
"%d -> %d", pid, returncode)
|
| 1197 |
+
else:
|
| 1198 |
+
callback(pid, returncode, *args)
|
| 1199 |
+
|
| 1200 |
+
|
| 1201 |
+
class MultiLoopChildWatcher(AbstractChildWatcher):
|
| 1202 |
+
"""A watcher that doesn't require running loop in the main thread.
|
| 1203 |
+
|
| 1204 |
+
This implementation registers a SIGCHLD signal handler on
|
| 1205 |
+
instantiation (which may conflict with other code that
|
| 1206 |
+
install own handler for this signal).
|
| 1207 |
+
|
| 1208 |
+
The solution is safe but it has a significant overhead when
|
| 1209 |
+
handling a big number of processes (*O(n)* each time a
|
| 1210 |
+
SIGCHLD is received).
|
| 1211 |
+
"""
|
| 1212 |
+
|
| 1213 |
+
# Implementation note:
|
| 1214 |
+
# The class keeps compatibility with AbstractChildWatcher ABC
|
| 1215 |
+
# To achieve this it has empty attach_loop() method
|
| 1216 |
+
# and doesn't accept explicit loop argument
|
| 1217 |
+
# for add_child_handler()/remove_child_handler()
|
| 1218 |
+
# but retrieves the current loop by get_running_loop()
|
| 1219 |
+
|
| 1220 |
+
def __init__(self):
|
| 1221 |
+
self._callbacks = {}
|
| 1222 |
+
self._saved_sighandler = None
|
| 1223 |
+
|
| 1224 |
+
def is_active(self):
|
| 1225 |
+
return self._saved_sighandler is not None
|
| 1226 |
+
|
| 1227 |
+
def close(self):
|
| 1228 |
+
self._callbacks.clear()
|
| 1229 |
+
if self._saved_sighandler is None:
|
| 1230 |
+
return
|
| 1231 |
+
|
| 1232 |
+
handler = signal.getsignal(signal.SIGCHLD)
|
| 1233 |
+
if handler != self._sig_chld:
|
| 1234 |
+
logger.warning("SIGCHLD handler was changed by outside code")
|
| 1235 |
+
else:
|
| 1236 |
+
signal.signal(signal.SIGCHLD, self._saved_sighandler)
|
| 1237 |
+
self._saved_sighandler = None
|
| 1238 |
+
|
| 1239 |
+
def __enter__(self):
|
| 1240 |
+
return self
|
| 1241 |
+
|
| 1242 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 1243 |
+
pass
|
| 1244 |
+
|
| 1245 |
+
def add_child_handler(self, pid, callback, *args):
|
| 1246 |
+
loop = events.get_running_loop()
|
| 1247 |
+
self._callbacks[pid] = (loop, callback, args)
|
| 1248 |
+
|
| 1249 |
+
# Prevent a race condition in case the child is already terminated.
|
| 1250 |
+
self._do_waitpid(pid)
|
| 1251 |
+
|
| 1252 |
+
def remove_child_handler(self, pid):
|
| 1253 |
+
try:
|
| 1254 |
+
del self._callbacks[pid]
|
| 1255 |
+
return True
|
| 1256 |
+
except KeyError:
|
| 1257 |
+
return False
|
| 1258 |
+
|
| 1259 |
+
def attach_loop(self, loop):
|
| 1260 |
+
# Don't save the loop but initialize itself if called first time
|
| 1261 |
+
# The reason to do it here is that attach_loop() is called from
|
| 1262 |
+
# unix policy only for the main thread.
|
| 1263 |
+
# Main thread is required for subscription on SIGCHLD signal
|
| 1264 |
+
if self._saved_sighandler is not None:
|
| 1265 |
+
return
|
| 1266 |
+
|
| 1267 |
+
self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld)
|
| 1268 |
+
if self._saved_sighandler is None:
|
| 1269 |
+
logger.warning("Previous SIGCHLD handler was set by non-Python code, "
|
| 1270 |
+
"restore to default handler on watcher close.")
|
| 1271 |
+
self._saved_sighandler = signal.SIG_DFL
|
| 1272 |
+
|
| 1273 |
+
# Set SA_RESTART to limit EINTR occurrences.
|
| 1274 |
+
signal.siginterrupt(signal.SIGCHLD, False)
|
| 1275 |
+
|
| 1276 |
+
def _do_waitpid_all(self):
|
| 1277 |
+
for pid in list(self._callbacks):
|
| 1278 |
+
self._do_waitpid(pid)
|
| 1279 |
+
|
| 1280 |
+
def _do_waitpid(self, expected_pid):
|
| 1281 |
+
assert expected_pid > 0
|
| 1282 |
+
|
| 1283 |
+
try:
|
| 1284 |
+
pid, status = os.waitpid(expected_pid, os.WNOHANG)
|
| 1285 |
+
except ChildProcessError:
|
| 1286 |
+
# The child process is already reaped
|
| 1287 |
+
# (may happen if waitpid() is called elsewhere).
|
| 1288 |
+
pid = expected_pid
|
| 1289 |
+
returncode = 255
|
| 1290 |
+
logger.warning(
|
| 1291 |
+
"Unknown child process pid %d, will report returncode 255",
|
| 1292 |
+
pid)
|
| 1293 |
+
debug_log = False
|
| 1294 |
+
else:
|
| 1295 |
+
if pid == 0:
|
| 1296 |
+
# The child process is still alive.
|
| 1297 |
+
return
|
| 1298 |
+
|
| 1299 |
+
returncode = waitstatus_to_exitcode(status)
|
| 1300 |
+
debug_log = True
|
| 1301 |
+
try:
|
| 1302 |
+
loop, callback, args = self._callbacks.pop(pid)
|
| 1303 |
+
except KeyError: # pragma: no cover
|
| 1304 |
+
# May happen if .remove_child_handler() is called
|
| 1305 |
+
# after os.waitpid() returns.
|
| 1306 |
+
logger.warning("Child watcher got an unexpected pid: %r",
|
| 1307 |
+
pid, exc_info=True)
|
| 1308 |
+
else:
|
| 1309 |
+
if loop.is_closed():
|
| 1310 |
+
logger.warning("Loop %r that handles pid %r is closed", loop, pid)
|
| 1311 |
+
else:
|
| 1312 |
+
if debug_log and loop.get_debug():
|
| 1313 |
+
logger.debug('process %s exited with returncode %s',
|
| 1314 |
+
expected_pid, returncode)
|
| 1315 |
+
loop.call_soon_threadsafe(callback, pid, returncode, *args)
|
| 1316 |
+
|
| 1317 |
+
def _sig_chld(self, signum, frame):
|
| 1318 |
+
try:
|
| 1319 |
+
self._do_waitpid_all()
|
| 1320 |
+
except (SystemExit, KeyboardInterrupt):
|
| 1321 |
+
raise
|
| 1322 |
+
except BaseException:
|
| 1323 |
+
logger.warning('Unknown exception in SIGCHLD handler', exc_info=True)
|
| 1324 |
+
|
| 1325 |
+
|
| 1326 |
+
class ThreadedChildWatcher(AbstractChildWatcher):
|
| 1327 |
+
"""Threaded child watcher implementation.
|
| 1328 |
+
|
| 1329 |
+
The watcher uses a thread per process
|
| 1330 |
+
for waiting for the process finish.
|
| 1331 |
+
|
| 1332 |
+
It doesn't require subscription on POSIX signal
|
| 1333 |
+
but a thread creation is not free.
|
| 1334 |
+
|
| 1335 |
+
The watcher has O(1) complexity, its performance doesn't depend
|
| 1336 |
+
on amount of spawn processes.
|
| 1337 |
+
"""
|
| 1338 |
+
|
| 1339 |
+
def __init__(self):
|
| 1340 |
+
self._pid_counter = itertools.count(0)
|
| 1341 |
+
self._threads = {}
|
| 1342 |
+
|
| 1343 |
+
def is_active(self):
|
| 1344 |
+
return True
|
| 1345 |
+
|
| 1346 |
+
def close(self):
|
| 1347 |
+
self._join_threads()
|
| 1348 |
+
|
| 1349 |
+
def _join_threads(self):
|
| 1350 |
+
"""Internal: Join all non-daemon threads"""
|
| 1351 |
+
threads = [thread for thread in list(self._threads.values())
|
| 1352 |
+
if thread.is_alive() and not thread.daemon]
|
| 1353 |
+
for thread in threads:
|
| 1354 |
+
thread.join()
|
| 1355 |
+
|
| 1356 |
+
def __enter__(self):
|
| 1357 |
+
return self
|
| 1358 |
+
|
| 1359 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 1360 |
+
pass
|
| 1361 |
+
|
| 1362 |
+
def __del__(self, _warn=warnings.warn):
|
| 1363 |
+
threads = [thread for thread in list(self._threads.values())
|
| 1364 |
+
if thread.is_alive()]
|
| 1365 |
+
if threads:
|
| 1366 |
+
_warn(f"{self.__class__} has registered but not finished child processes",
|
| 1367 |
+
ResourceWarning,
|
| 1368 |
+
source=self)
|
| 1369 |
+
|
| 1370 |
+
def add_child_handler(self, pid, callback, *args):
|
| 1371 |
+
loop = events.get_running_loop()
|
| 1372 |
+
thread = threading.Thread(target=self._do_waitpid,
|
| 1373 |
+
name=f"waitpid-{next(self._pid_counter)}",
|
| 1374 |
+
args=(loop, pid, callback, args),
|
| 1375 |
+
daemon=True)
|
| 1376 |
+
self._threads[pid] = thread
|
| 1377 |
+
thread.start()
|
| 1378 |
+
|
| 1379 |
+
def remove_child_handler(self, pid):
|
| 1380 |
+
# asyncio never calls remove_child_handler() !!!
|
| 1381 |
+
# The method is no-op but is implemented because
|
| 1382 |
+
# abstract base classes require it.
|
| 1383 |
+
return True
|
| 1384 |
+
|
| 1385 |
+
def attach_loop(self, loop):
|
| 1386 |
+
pass
|
| 1387 |
+
|
| 1388 |
+
def _do_waitpid(self, loop, expected_pid, callback, args):
|
| 1389 |
+
assert expected_pid > 0
|
| 1390 |
+
|
| 1391 |
+
try:
|
| 1392 |
+
pid, status = os.waitpid(expected_pid, 0)
|
| 1393 |
+
except ChildProcessError:
|
| 1394 |
+
# The child process is already reaped
|
| 1395 |
+
# (may happen if waitpid() is called elsewhere).
|
| 1396 |
+
pid = expected_pid
|
| 1397 |
+
returncode = 255
|
| 1398 |
+
logger.warning(
|
| 1399 |
+
"Unknown child process pid %d, will report returncode 255",
|
| 1400 |
+
pid)
|
| 1401 |
+
else:
|
| 1402 |
+
returncode = waitstatus_to_exitcode(status)
|
| 1403 |
+
if loop.get_debug():
|
| 1404 |
+
logger.debug('process %s exited with returncode %s',
|
| 1405 |
+
expected_pid, returncode)
|
| 1406 |
+
|
| 1407 |
+
if loop.is_closed():
|
| 1408 |
+
logger.warning("Loop %r that handles pid %r is closed", loop, pid)
|
| 1409 |
+
else:
|
| 1410 |
+
loop.call_soon_threadsafe(callback, pid, returncode, *args)
|
| 1411 |
+
|
| 1412 |
+
self._threads.pop(expected_pid)
|
| 1413 |
+
|
| 1414 |
+
|
| 1415 |
+
class _UnixDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
| 1416 |
+
"""UNIX event loop policy with a watcher for child processes."""
|
| 1417 |
+
_loop_factory = _UnixSelectorEventLoop
|
| 1418 |
+
|
| 1419 |
+
def __init__(self):
|
| 1420 |
+
super().__init__()
|
| 1421 |
+
self._watcher = None
|
| 1422 |
+
|
| 1423 |
+
def _init_watcher(self):
|
| 1424 |
+
with events._lock:
|
| 1425 |
+
if self._watcher is None: # pragma: no branch
|
| 1426 |
+
self._watcher = ThreadedChildWatcher()
|
| 1427 |
+
if threading.current_thread() is threading.main_thread():
|
| 1428 |
+
self._watcher.attach_loop(self._local._loop)
|
| 1429 |
+
|
| 1430 |
+
def set_event_loop(self, loop):
|
| 1431 |
+
"""Set the event loop.
|
| 1432 |
+
|
| 1433 |
+
As a side effect, if a child watcher was set before, then calling
|
| 1434 |
+
.set_event_loop() from the main thread will call .attach_loop(loop) on
|
| 1435 |
+
the child watcher.
|
| 1436 |
+
"""
|
| 1437 |
+
|
| 1438 |
+
super().set_event_loop(loop)
|
| 1439 |
+
|
| 1440 |
+
if (self._watcher is not None and
|
| 1441 |
+
threading.current_thread() is threading.main_thread()):
|
| 1442 |
+
self._watcher.attach_loop(loop)
|
| 1443 |
+
|
| 1444 |
+
def get_child_watcher(self):
|
| 1445 |
+
"""Get the watcher for child processes.
|
| 1446 |
+
|
| 1447 |
+
If not yet set, a ThreadedChildWatcher object is automatically created.
|
| 1448 |
+
"""
|
| 1449 |
+
if self._watcher is None:
|
| 1450 |
+
self._init_watcher()
|
| 1451 |
+
|
| 1452 |
+
return self._watcher
|
| 1453 |
+
|
| 1454 |
+
def set_child_watcher(self, watcher):
|
| 1455 |
+
"""Set the watcher for child processes."""
|
| 1456 |
+
|
| 1457 |
+
assert watcher is None or isinstance(watcher, AbstractChildWatcher)
|
| 1458 |
+
|
| 1459 |
+
if self._watcher is not None:
|
| 1460 |
+
self._watcher.close()
|
| 1461 |
+
|
| 1462 |
+
self._watcher = watcher
|
| 1463 |
+
|
| 1464 |
+
|
| 1465 |
+
SelectorEventLoop = _UnixSelectorEventLoop
|
| 1466 |
+
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
|
janus/lib/python3.10/html/__init__.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
General functions for HTML manipulation.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import re as _re
|
| 6 |
+
from html.entities import html5 as _html5
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
__all__ = ['escape', 'unescape']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def escape(s, quote=True):
|
| 13 |
+
"""
|
| 14 |
+
Replace special characters "&", "<" and ">" to HTML-safe sequences.
|
| 15 |
+
If the optional flag quote is true (the default), the quotation mark
|
| 16 |
+
characters, both double quote (") and single quote (') characters are also
|
| 17 |
+
translated.
|
| 18 |
+
"""
|
| 19 |
+
s = s.replace("&", "&") # Must be done first!
|
| 20 |
+
s = s.replace("<", "<")
|
| 21 |
+
s = s.replace(">", ">")
|
| 22 |
+
if quote:
|
| 23 |
+
s = s.replace('"', """)
|
| 24 |
+
s = s.replace('\'', "'")
|
| 25 |
+
return s
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# see https://html.spec.whatwg.org/multipage/parsing.html#numeric-character-reference-end-state
|
| 29 |
+
|
| 30 |
+
_invalid_charrefs = {
|
| 31 |
+
0x00: '\ufffd', # REPLACEMENT CHARACTER
|
| 32 |
+
0x0d: '\r', # CARRIAGE RETURN
|
| 33 |
+
0x80: '\u20ac', # EURO SIGN
|
| 34 |
+
0x81: '\x81', # <control>
|
| 35 |
+
0x82: '\u201a', # SINGLE LOW-9 QUOTATION MARK
|
| 36 |
+
0x83: '\u0192', # LATIN SMALL LETTER F WITH HOOK
|
| 37 |
+
0x84: '\u201e', # DOUBLE LOW-9 QUOTATION MARK
|
| 38 |
+
0x85: '\u2026', # HORIZONTAL ELLIPSIS
|
| 39 |
+
0x86: '\u2020', # DAGGER
|
| 40 |
+
0x87: '\u2021', # DOUBLE DAGGER
|
| 41 |
+
0x88: '\u02c6', # MODIFIER LETTER CIRCUMFLEX ACCENT
|
| 42 |
+
0x89: '\u2030', # PER MILLE SIGN
|
| 43 |
+
0x8a: '\u0160', # LATIN CAPITAL LETTER S WITH CARON
|
| 44 |
+
0x8b: '\u2039', # SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
| 45 |
+
0x8c: '\u0152', # LATIN CAPITAL LIGATURE OE
|
| 46 |
+
0x8d: '\x8d', # <control>
|
| 47 |
+
0x8e: '\u017d', # LATIN CAPITAL LETTER Z WITH CARON
|
| 48 |
+
0x8f: '\x8f', # <control>
|
| 49 |
+
0x90: '\x90', # <control>
|
| 50 |
+
0x91: '\u2018', # LEFT SINGLE QUOTATION MARK
|
| 51 |
+
0x92: '\u2019', # RIGHT SINGLE QUOTATION MARK
|
| 52 |
+
0x93: '\u201c', # LEFT DOUBLE QUOTATION MARK
|
| 53 |
+
0x94: '\u201d', # RIGHT DOUBLE QUOTATION MARK
|
| 54 |
+
0x95: '\u2022', # BULLET
|
| 55 |
+
0x96: '\u2013', # EN DASH
|
| 56 |
+
0x97: '\u2014', # EM DASH
|
| 57 |
+
0x98: '\u02dc', # SMALL TILDE
|
| 58 |
+
0x99: '\u2122', # TRADE MARK SIGN
|
| 59 |
+
0x9a: '\u0161', # LATIN SMALL LETTER S WITH CARON
|
| 60 |
+
0x9b: '\u203a', # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
| 61 |
+
0x9c: '\u0153', # LATIN SMALL LIGATURE OE
|
| 62 |
+
0x9d: '\x9d', # <control>
|
| 63 |
+
0x9e: '\u017e', # LATIN SMALL LETTER Z WITH CARON
|
| 64 |
+
0x9f: '\u0178', # LATIN CAPITAL LETTER Y WITH DIAERESIS
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
_invalid_codepoints = {
|
| 68 |
+
# 0x0001 to 0x0008
|
| 69 |
+
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
|
| 70 |
+
# 0x000E to 0x001F
|
| 71 |
+
0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
|
| 72 |
+
0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
| 73 |
+
# 0x007F to 0x009F
|
| 74 |
+
0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a,
|
| 75 |
+
0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
| 76 |
+
0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
| 77 |
+
# 0xFDD0 to 0xFDEF
|
| 78 |
+
0xfdd0, 0xfdd1, 0xfdd2, 0xfdd3, 0xfdd4, 0xfdd5, 0xfdd6, 0xfdd7, 0xfdd8,
|
| 79 |
+
0xfdd9, 0xfdda, 0xfddb, 0xfddc, 0xfddd, 0xfdde, 0xfddf, 0xfde0, 0xfde1,
|
| 80 |
+
0xfde2, 0xfde3, 0xfde4, 0xfde5, 0xfde6, 0xfde7, 0xfde8, 0xfde9, 0xfdea,
|
| 81 |
+
0xfdeb, 0xfdec, 0xfded, 0xfdee, 0xfdef,
|
| 82 |
+
# others
|
| 83 |
+
0xb, 0xfffe, 0xffff, 0x1fffe, 0x1ffff, 0x2fffe, 0x2ffff, 0x3fffe, 0x3ffff,
|
| 84 |
+
0x4fffe, 0x4ffff, 0x5fffe, 0x5ffff, 0x6fffe, 0x6ffff, 0x7fffe, 0x7ffff,
|
| 85 |
+
0x8fffe, 0x8ffff, 0x9fffe, 0x9ffff, 0xafffe, 0xaffff, 0xbfffe, 0xbffff,
|
| 86 |
+
0xcfffe, 0xcffff, 0xdfffe, 0xdffff, 0xefffe, 0xeffff, 0xffffe, 0xfffff,
|
| 87 |
+
0x10fffe, 0x10ffff
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def _replace_charref(s):
|
| 92 |
+
s = s.group(1)
|
| 93 |
+
if s[0] == '#':
|
| 94 |
+
# numeric charref
|
| 95 |
+
if s[1] in 'xX':
|
| 96 |
+
num = int(s[2:].rstrip(';'), 16)
|
| 97 |
+
else:
|
| 98 |
+
num = int(s[1:].rstrip(';'))
|
| 99 |
+
if num in _invalid_charrefs:
|
| 100 |
+
return _invalid_charrefs[num]
|
| 101 |
+
if 0xD800 <= num <= 0xDFFF or num > 0x10FFFF:
|
| 102 |
+
return '\uFFFD'
|
| 103 |
+
if num in _invalid_codepoints:
|
| 104 |
+
return ''
|
| 105 |
+
return chr(num)
|
| 106 |
+
else:
|
| 107 |
+
# named charref
|
| 108 |
+
if s in _html5:
|
| 109 |
+
return _html5[s]
|
| 110 |
+
# find the longest matching name (as defined by the standard)
|
| 111 |
+
for x in range(len(s)-1, 1, -1):
|
| 112 |
+
if s[:x] in _html5:
|
| 113 |
+
return _html5[s[:x]] + s[x:]
|
| 114 |
+
else:
|
| 115 |
+
return '&' + s
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
_charref = _re.compile(r'&(#[0-9]+;?'
|
| 119 |
+
r'|#[xX][0-9a-fA-F]+;?'
|
| 120 |
+
r'|[^\t\n\f <&#;]{1,32};?)')
|
| 121 |
+
|
| 122 |
+
def unescape(s):
|
| 123 |
+
"""
|
| 124 |
+
Convert all named and numeric character references (e.g. >, >,
|
| 125 |
+
&x3e;) in the string s to the corresponding unicode characters.
|
| 126 |
+
This function uses the rules defined by the HTML 5 standard
|
| 127 |
+
for both valid and invalid character references, and the list of
|
| 128 |
+
HTML 5 named character references defined in html.entities.html5.
|
| 129 |
+
"""
|
| 130 |
+
if '&' not in s:
|
| 131 |
+
return s
|
| 132 |
+
return _charref.sub(_replace_charref, s)
|
janus/lib/python3.10/html/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (3.32 kB). View file
|
|
|
janus/lib/python3.10/html/__pycache__/parser.cpython-310.pyc
ADDED
|
Binary file (11 kB). View file
|
|
|
janus/lib/python3.10/html/entities.py
ADDED
|
@@ -0,0 +1,2510 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HTML character entity references."""
|
| 2 |
+
|
| 3 |
+
__all__ = ['html5', 'name2codepoint', 'codepoint2name', 'entitydefs']
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# maps the HTML entity name to the Unicode code point
|
| 7 |
+
# from https://html.spec.whatwg.org/multipage/named-characters.html
|
| 8 |
+
name2codepoint = {
|
| 9 |
+
'AElig': 0x00c6, # latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1
|
| 10 |
+
'Aacute': 0x00c1, # latin capital letter A with acute, U+00C1 ISOlat1
|
| 11 |
+
'Acirc': 0x00c2, # latin capital letter A with circumflex, U+00C2 ISOlat1
|
| 12 |
+
'Agrave': 0x00c0, # latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1
|
| 13 |
+
'Alpha': 0x0391, # greek capital letter alpha, U+0391
|
| 14 |
+
'Aring': 0x00c5, # latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1
|
| 15 |
+
'Atilde': 0x00c3, # latin capital letter A with tilde, U+00C3 ISOlat1
|
| 16 |
+
'Auml': 0x00c4, # latin capital letter A with diaeresis, U+00C4 ISOlat1
|
| 17 |
+
'Beta': 0x0392, # greek capital letter beta, U+0392
|
| 18 |
+
'Ccedil': 0x00c7, # latin capital letter C with cedilla, U+00C7 ISOlat1
|
| 19 |
+
'Chi': 0x03a7, # greek capital letter chi, U+03A7
|
| 20 |
+
'Dagger': 0x2021, # double dagger, U+2021 ISOpub
|
| 21 |
+
'Delta': 0x0394, # greek capital letter delta, U+0394 ISOgrk3
|
| 22 |
+
'ETH': 0x00d0, # latin capital letter ETH, U+00D0 ISOlat1
|
| 23 |
+
'Eacute': 0x00c9, # latin capital letter E with acute, U+00C9 ISOlat1
|
| 24 |
+
'Ecirc': 0x00ca, # latin capital letter E with circumflex, U+00CA ISOlat1
|
| 25 |
+
'Egrave': 0x00c8, # latin capital letter E with grave, U+00C8 ISOlat1
|
| 26 |
+
'Epsilon': 0x0395, # greek capital letter epsilon, U+0395
|
| 27 |
+
'Eta': 0x0397, # greek capital letter eta, U+0397
|
| 28 |
+
'Euml': 0x00cb, # latin capital letter E with diaeresis, U+00CB ISOlat1
|
| 29 |
+
'Gamma': 0x0393, # greek capital letter gamma, U+0393 ISOgrk3
|
| 30 |
+
'Iacute': 0x00cd, # latin capital letter I with acute, U+00CD ISOlat1
|
| 31 |
+
'Icirc': 0x00ce, # latin capital letter I with circumflex, U+00CE ISOlat1
|
| 32 |
+
'Igrave': 0x00cc, # latin capital letter I with grave, U+00CC ISOlat1
|
| 33 |
+
'Iota': 0x0399, # greek capital letter iota, U+0399
|
| 34 |
+
'Iuml': 0x00cf, # latin capital letter I with diaeresis, U+00CF ISOlat1
|
| 35 |
+
'Kappa': 0x039a, # greek capital letter kappa, U+039A
|
| 36 |
+
'Lambda': 0x039b, # greek capital letter lambda, U+039B ISOgrk3
|
| 37 |
+
'Mu': 0x039c, # greek capital letter mu, U+039C
|
| 38 |
+
'Ntilde': 0x00d1, # latin capital letter N with tilde, U+00D1 ISOlat1
|
| 39 |
+
'Nu': 0x039d, # greek capital letter nu, U+039D
|
| 40 |
+
'OElig': 0x0152, # latin capital ligature OE, U+0152 ISOlat2
|
| 41 |
+
'Oacute': 0x00d3, # latin capital letter O with acute, U+00D3 ISOlat1
|
| 42 |
+
'Ocirc': 0x00d4, # latin capital letter O with circumflex, U+00D4 ISOlat1
|
| 43 |
+
'Ograve': 0x00d2, # latin capital letter O with grave, U+00D2 ISOlat1
|
| 44 |
+
'Omega': 0x03a9, # greek capital letter omega, U+03A9 ISOgrk3
|
| 45 |
+
'Omicron': 0x039f, # greek capital letter omicron, U+039F
|
| 46 |
+
'Oslash': 0x00d8, # latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1
|
| 47 |
+
'Otilde': 0x00d5, # latin capital letter O with tilde, U+00D5 ISOlat1
|
| 48 |
+
'Ouml': 0x00d6, # latin capital letter O with diaeresis, U+00D6 ISOlat1
|
| 49 |
+
'Phi': 0x03a6, # greek capital letter phi, U+03A6 ISOgrk3
|
| 50 |
+
'Pi': 0x03a0, # greek capital letter pi, U+03A0 ISOgrk3
|
| 51 |
+
'Prime': 0x2033, # double prime = seconds = inches, U+2033 ISOtech
|
| 52 |
+
'Psi': 0x03a8, # greek capital letter psi, U+03A8 ISOgrk3
|
| 53 |
+
'Rho': 0x03a1, # greek capital letter rho, U+03A1
|
| 54 |
+
'Scaron': 0x0160, # latin capital letter S with caron, U+0160 ISOlat2
|
| 55 |
+
'Sigma': 0x03a3, # greek capital letter sigma, U+03A3 ISOgrk3
|
| 56 |
+
'THORN': 0x00de, # latin capital letter THORN, U+00DE ISOlat1
|
| 57 |
+
'Tau': 0x03a4, # greek capital letter tau, U+03A4
|
| 58 |
+
'Theta': 0x0398, # greek capital letter theta, U+0398 ISOgrk3
|
| 59 |
+
'Uacute': 0x00da, # latin capital letter U with acute, U+00DA ISOlat1
|
| 60 |
+
'Ucirc': 0x00db, # latin capital letter U with circumflex, U+00DB ISOlat1
|
| 61 |
+
'Ugrave': 0x00d9, # latin capital letter U with grave, U+00D9 ISOlat1
|
| 62 |
+
'Upsilon': 0x03a5, # greek capital letter upsilon, U+03A5 ISOgrk3
|
| 63 |
+
'Uuml': 0x00dc, # latin capital letter U with diaeresis, U+00DC ISOlat1
|
| 64 |
+
'Xi': 0x039e, # greek capital letter xi, U+039E ISOgrk3
|
| 65 |
+
'Yacute': 0x00dd, # latin capital letter Y with acute, U+00DD ISOlat1
|
| 66 |
+
'Yuml': 0x0178, # latin capital letter Y with diaeresis, U+0178 ISOlat2
|
| 67 |
+
'Zeta': 0x0396, # greek capital letter zeta, U+0396
|
| 68 |
+
'aacute': 0x00e1, # latin small letter a with acute, U+00E1 ISOlat1
|
| 69 |
+
'acirc': 0x00e2, # latin small letter a with circumflex, U+00E2 ISOlat1
|
| 70 |
+
'acute': 0x00b4, # acute accent = spacing acute, U+00B4 ISOdia
|
| 71 |
+
'aelig': 0x00e6, # latin small letter ae = latin small ligature ae, U+00E6 ISOlat1
|
| 72 |
+
'agrave': 0x00e0, # latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1
|
| 73 |
+
'alefsym': 0x2135, # alef symbol = first transfinite cardinal, U+2135 NEW
|
| 74 |
+
'alpha': 0x03b1, # greek small letter alpha, U+03B1 ISOgrk3
|
| 75 |
+
'amp': 0x0026, # ampersand, U+0026 ISOnum
|
| 76 |
+
'and': 0x2227, # logical and = wedge, U+2227 ISOtech
|
| 77 |
+
'ang': 0x2220, # angle, U+2220 ISOamso
|
| 78 |
+
'aring': 0x00e5, # latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1
|
| 79 |
+
'asymp': 0x2248, # almost equal to = asymptotic to, U+2248 ISOamsr
|
| 80 |
+
'atilde': 0x00e3, # latin small letter a with tilde, U+00E3 ISOlat1
|
| 81 |
+
'auml': 0x00e4, # latin small letter a with diaeresis, U+00E4 ISOlat1
|
| 82 |
+
'bdquo': 0x201e, # double low-9 quotation mark, U+201E NEW
|
| 83 |
+
'beta': 0x03b2, # greek small letter beta, U+03B2 ISOgrk3
|
| 84 |
+
'brvbar': 0x00a6, # broken bar = broken vertical bar, U+00A6 ISOnum
|
| 85 |
+
'bull': 0x2022, # bullet = black small circle, U+2022 ISOpub
|
| 86 |
+
'cap': 0x2229, # intersection = cap, U+2229 ISOtech
|
| 87 |
+
'ccedil': 0x00e7, # latin small letter c with cedilla, U+00E7 ISOlat1
|
| 88 |
+
'cedil': 0x00b8, # cedilla = spacing cedilla, U+00B8 ISOdia
|
| 89 |
+
'cent': 0x00a2, # cent sign, U+00A2 ISOnum
|
| 90 |
+
'chi': 0x03c7, # greek small letter chi, U+03C7 ISOgrk3
|
| 91 |
+
'circ': 0x02c6, # modifier letter circumflex accent, U+02C6 ISOpub
|
| 92 |
+
'clubs': 0x2663, # black club suit = shamrock, U+2663 ISOpub
|
| 93 |
+
'cong': 0x2245, # approximately equal to, U+2245 ISOtech
|
| 94 |
+
'copy': 0x00a9, # copyright sign, U+00A9 ISOnum
|
| 95 |
+
'crarr': 0x21b5, # downwards arrow with corner leftwards = carriage return, U+21B5 NEW
|
| 96 |
+
'cup': 0x222a, # union = cup, U+222A ISOtech
|
| 97 |
+
'curren': 0x00a4, # currency sign, U+00A4 ISOnum
|
| 98 |
+
'dArr': 0x21d3, # downwards double arrow, U+21D3 ISOamsa
|
| 99 |
+
'dagger': 0x2020, # dagger, U+2020 ISOpub
|
| 100 |
+
'darr': 0x2193, # downwards arrow, U+2193 ISOnum
|
| 101 |
+
'deg': 0x00b0, # degree sign, U+00B0 ISOnum
|
| 102 |
+
'delta': 0x03b4, # greek small letter delta, U+03B4 ISOgrk3
|
| 103 |
+
'diams': 0x2666, # black diamond suit, U+2666 ISOpub
|
| 104 |
+
'divide': 0x00f7, # division sign, U+00F7 ISOnum
|
| 105 |
+
'eacute': 0x00e9, # latin small letter e with acute, U+00E9 ISOlat1
|
| 106 |
+
'ecirc': 0x00ea, # latin small letter e with circumflex, U+00EA ISOlat1
|
| 107 |
+
'egrave': 0x00e8, # latin small letter e with grave, U+00E8 ISOlat1
|
| 108 |
+
'empty': 0x2205, # empty set = null set = diameter, U+2205 ISOamso
|
| 109 |
+
'emsp': 0x2003, # em space, U+2003 ISOpub
|
| 110 |
+
'ensp': 0x2002, # en space, U+2002 ISOpub
|
| 111 |
+
'epsilon': 0x03b5, # greek small letter epsilon, U+03B5 ISOgrk3
|
| 112 |
+
'equiv': 0x2261, # identical to, U+2261 ISOtech
|
| 113 |
+
'eta': 0x03b7, # greek small letter eta, U+03B7 ISOgrk3
|
| 114 |
+
'eth': 0x00f0, # latin small letter eth, U+00F0 ISOlat1
|
| 115 |
+
'euml': 0x00eb, # latin small letter e with diaeresis, U+00EB ISOlat1
|
| 116 |
+
'euro': 0x20ac, # euro sign, U+20AC NEW
|
| 117 |
+
'exist': 0x2203, # there exists, U+2203 ISOtech
|
| 118 |
+
'fnof': 0x0192, # latin small f with hook = function = florin, U+0192 ISOtech
|
| 119 |
+
'forall': 0x2200, # for all, U+2200 ISOtech
|
| 120 |
+
'frac12': 0x00bd, # vulgar fraction one half = fraction one half, U+00BD ISOnum
|
| 121 |
+
'frac14': 0x00bc, # vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum
|
| 122 |
+
'frac34': 0x00be, # vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum
|
| 123 |
+
'frasl': 0x2044, # fraction slash, U+2044 NEW
|
| 124 |
+
'gamma': 0x03b3, # greek small letter gamma, U+03B3 ISOgrk3
|
| 125 |
+
'ge': 0x2265, # greater-than or equal to, U+2265 ISOtech
|
| 126 |
+
'gt': 0x003e, # greater-than sign, U+003E ISOnum
|
| 127 |
+
'hArr': 0x21d4, # left right double arrow, U+21D4 ISOamsa
|
| 128 |
+
'harr': 0x2194, # left right arrow, U+2194 ISOamsa
|
| 129 |
+
'hearts': 0x2665, # black heart suit = valentine, U+2665 ISOpub
|
| 130 |
+
'hellip': 0x2026, # horizontal ellipsis = three dot leader, U+2026 ISOpub
|
| 131 |
+
'iacute': 0x00ed, # latin small letter i with acute, U+00ED ISOlat1
|
| 132 |
+
'icirc': 0x00ee, # latin small letter i with circumflex, U+00EE ISOlat1
|
| 133 |
+
'iexcl': 0x00a1, # inverted exclamation mark, U+00A1 ISOnum
|
| 134 |
+
'igrave': 0x00ec, # latin small letter i with grave, U+00EC ISOlat1
|
| 135 |
+
'image': 0x2111, # blackletter capital I = imaginary part, U+2111 ISOamso
|
| 136 |
+
'infin': 0x221e, # infinity, U+221E ISOtech
|
| 137 |
+
'int': 0x222b, # integral, U+222B ISOtech
|
| 138 |
+
'iota': 0x03b9, # greek small letter iota, U+03B9 ISOgrk3
|
| 139 |
+
'iquest': 0x00bf, # inverted question mark = turned question mark, U+00BF ISOnum
|
| 140 |
+
'isin': 0x2208, # element of, U+2208 ISOtech
|
| 141 |
+
'iuml': 0x00ef, # latin small letter i with diaeresis, U+00EF ISOlat1
|
| 142 |
+
'kappa': 0x03ba, # greek small letter kappa, U+03BA ISOgrk3
|
| 143 |
+
'lArr': 0x21d0, # leftwards double arrow, U+21D0 ISOtech
|
| 144 |
+
'lambda': 0x03bb, # greek small letter lambda, U+03BB ISOgrk3
|
| 145 |
+
'lang': 0x2329, # left-pointing angle bracket = bra, U+2329 ISOtech
|
| 146 |
+
'laquo': 0x00ab, # left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum
|
| 147 |
+
'larr': 0x2190, # leftwards arrow, U+2190 ISOnum
|
| 148 |
+
'lceil': 0x2308, # left ceiling = apl upstile, U+2308 ISOamsc
|
| 149 |
+
'ldquo': 0x201c, # left double quotation mark, U+201C ISOnum
|
| 150 |
+
'le': 0x2264, # less-than or equal to, U+2264 ISOtech
|
| 151 |
+
'lfloor': 0x230a, # left floor = apl downstile, U+230A ISOamsc
|
| 152 |
+
'lowast': 0x2217, # asterisk operator, U+2217 ISOtech
|
| 153 |
+
'loz': 0x25ca, # lozenge, U+25CA ISOpub
|
| 154 |
+
'lrm': 0x200e, # left-to-right mark, U+200E NEW RFC 2070
|
| 155 |
+
'lsaquo': 0x2039, # single left-pointing angle quotation mark, U+2039 ISO proposed
|
| 156 |
+
'lsquo': 0x2018, # left single quotation mark, U+2018 ISOnum
|
| 157 |
+
'lt': 0x003c, # less-than sign, U+003C ISOnum
|
| 158 |
+
'macr': 0x00af, # macron = spacing macron = overline = APL overbar, U+00AF ISOdia
|
| 159 |
+
'mdash': 0x2014, # em dash, U+2014 ISOpub
|
| 160 |
+
'micro': 0x00b5, # micro sign, U+00B5 ISOnum
|
| 161 |
+
'middot': 0x00b7, # middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum
|
| 162 |
+
'minus': 0x2212, # minus sign, U+2212 ISOtech
|
| 163 |
+
'mu': 0x03bc, # greek small letter mu, U+03BC ISOgrk3
|
| 164 |
+
'nabla': 0x2207, # nabla = backward difference, U+2207 ISOtech
|
| 165 |
+
'nbsp': 0x00a0, # no-break space = non-breaking space, U+00A0 ISOnum
|
| 166 |
+
'ndash': 0x2013, # en dash, U+2013 ISOpub
|
| 167 |
+
'ne': 0x2260, # not equal to, U+2260 ISOtech
|
| 168 |
+
'ni': 0x220b, # contains as member, U+220B ISOtech
|
| 169 |
+
'not': 0x00ac, # not sign, U+00AC ISOnum
|
| 170 |
+
'notin': 0x2209, # not an element of, U+2209 ISOtech
|
| 171 |
+
'nsub': 0x2284, # not a subset of, U+2284 ISOamsn
|
| 172 |
+
'ntilde': 0x00f1, # latin small letter n with tilde, U+00F1 ISOlat1
|
| 173 |
+
'nu': 0x03bd, # greek small letter nu, U+03BD ISOgrk3
|
| 174 |
+
'oacute': 0x00f3, # latin small letter o with acute, U+00F3 ISOlat1
|
| 175 |
+
'ocirc': 0x00f4, # latin small letter o with circumflex, U+00F4 ISOlat1
|
| 176 |
+
'oelig': 0x0153, # latin small ligature oe, U+0153 ISOlat2
|
| 177 |
+
'ograve': 0x00f2, # latin small letter o with grave, U+00F2 ISOlat1
|
| 178 |
+
'oline': 0x203e, # overline = spacing overscore, U+203E NEW
|
| 179 |
+
'omega': 0x03c9, # greek small letter omega, U+03C9 ISOgrk3
|
| 180 |
+
'omicron': 0x03bf, # greek small letter omicron, U+03BF NEW
|
| 181 |
+
'oplus': 0x2295, # circled plus = direct sum, U+2295 ISOamsb
|
| 182 |
+
'or': 0x2228, # logical or = vee, U+2228 ISOtech
|
| 183 |
+
'ordf': 0x00aa, # feminine ordinal indicator, U+00AA ISOnum
|
| 184 |
+
'ordm': 0x00ba, # masculine ordinal indicator, U+00BA ISOnum
|
| 185 |
+
'oslash': 0x00f8, # latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1
|
| 186 |
+
'otilde': 0x00f5, # latin small letter o with tilde, U+00F5 ISOlat1
|
| 187 |
+
'otimes': 0x2297, # circled times = vector product, U+2297 ISOamsb
|
| 188 |
+
'ouml': 0x00f6, # latin small letter o with diaeresis, U+00F6 ISOlat1
|
| 189 |
+
'para': 0x00b6, # pilcrow sign = paragraph sign, U+00B6 ISOnum
|
| 190 |
+
'part': 0x2202, # partial differential, U+2202 ISOtech
|
| 191 |
+
'permil': 0x2030, # per mille sign, U+2030 ISOtech
|
| 192 |
+
'perp': 0x22a5, # up tack = orthogonal to = perpendicular, U+22A5 ISOtech
|
| 193 |
+
'phi': 0x03c6, # greek small letter phi, U+03C6 ISOgrk3
|
| 194 |
+
'pi': 0x03c0, # greek small letter pi, U+03C0 ISOgrk3
|
| 195 |
+
'piv': 0x03d6, # greek pi symbol, U+03D6 ISOgrk3
|
| 196 |
+
'plusmn': 0x00b1, # plus-minus sign = plus-or-minus sign, U+00B1 ISOnum
|
| 197 |
+
'pound': 0x00a3, # pound sign, U+00A3 ISOnum
|
| 198 |
+
'prime': 0x2032, # prime = minutes = feet, U+2032 ISOtech
|
| 199 |
+
'prod': 0x220f, # n-ary product = product sign, U+220F ISOamsb
|
| 200 |
+
'prop': 0x221d, # proportional to, U+221D ISOtech
|
| 201 |
+
'psi': 0x03c8, # greek small letter psi, U+03C8 ISOgrk3
|
| 202 |
+
'quot': 0x0022, # quotation mark = APL quote, U+0022 ISOnum
|
| 203 |
+
'rArr': 0x21d2, # rightwards double arrow, U+21D2 ISOtech
|
| 204 |
+
'radic': 0x221a, # square root = radical sign, U+221A ISOtech
|
| 205 |
+
'rang': 0x232a, # right-pointing angle bracket = ket, U+232A ISOtech
|
| 206 |
+
'raquo': 0x00bb, # right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum
|
| 207 |
+
'rarr': 0x2192, # rightwards arrow, U+2192 ISOnum
|
| 208 |
+
'rceil': 0x2309, # right ceiling, U+2309 ISOamsc
|
| 209 |
+
'rdquo': 0x201d, # right double quotation mark, U+201D ISOnum
|
| 210 |
+
'real': 0x211c, # blackletter capital R = real part symbol, U+211C ISOamso
|
| 211 |
+
'reg': 0x00ae, # registered sign = registered trade mark sign, U+00AE ISOnum
|
| 212 |
+
'rfloor': 0x230b, # right floor, U+230B ISOamsc
|
| 213 |
+
'rho': 0x03c1, # greek small letter rho, U+03C1 ISOgrk3
|
| 214 |
+
'rlm': 0x200f, # right-to-left mark, U+200F NEW RFC 2070
|
| 215 |
+
'rsaquo': 0x203a, # single right-pointing angle quotation mark, U+203A ISO proposed
|
| 216 |
+
'rsquo': 0x2019, # right single quotation mark, U+2019 ISOnum
|
| 217 |
+
'sbquo': 0x201a, # single low-9 quotation mark, U+201A NEW
|
| 218 |
+
'scaron': 0x0161, # latin small letter s with caron, U+0161 ISOlat2
|
| 219 |
+
'sdot': 0x22c5, # dot operator, U+22C5 ISOamsb
|
| 220 |
+
'sect': 0x00a7, # section sign, U+00A7 ISOnum
|
| 221 |
+
'shy': 0x00ad, # soft hyphen = discretionary hyphen, U+00AD ISOnum
|
| 222 |
+
'sigma': 0x03c3, # greek small letter sigma, U+03C3 ISOgrk3
|
| 223 |
+
'sigmaf': 0x03c2, # greek small letter final sigma, U+03C2 ISOgrk3
|
| 224 |
+
'sim': 0x223c, # tilde operator = varies with = similar to, U+223C ISOtech
|
| 225 |
+
'spades': 0x2660, # black spade suit, U+2660 ISOpub
|
| 226 |
+
'sub': 0x2282, # subset of, U+2282 ISOtech
|
| 227 |
+
'sube': 0x2286, # subset of or equal to, U+2286 ISOtech
|
| 228 |
+
'sum': 0x2211, # n-ary summation, U+2211 ISOamsb
|
| 229 |
+
'sup': 0x2283, # superset of, U+2283 ISOtech
|
| 230 |
+
'sup1': 0x00b9, # superscript one = superscript digit one, U+00B9 ISOnum
|
| 231 |
+
'sup2': 0x00b2, # superscript two = superscript digit two = squared, U+00B2 ISOnum
|
| 232 |
+
'sup3': 0x00b3, # superscript three = superscript digit three = cubed, U+00B3 ISOnum
|
| 233 |
+
'supe': 0x2287, # superset of or equal to, U+2287 ISOtech
|
| 234 |
+
'szlig': 0x00df, # latin small letter sharp s = ess-zed, U+00DF ISOlat1
|
| 235 |
+
'tau': 0x03c4, # greek small letter tau, U+03C4 ISOgrk3
|
| 236 |
+
'there4': 0x2234, # therefore, U+2234 ISOtech
|
| 237 |
+
'theta': 0x03b8, # greek small letter theta, U+03B8 ISOgrk3
|
| 238 |
+
'thetasym': 0x03d1, # greek small letter theta symbol, U+03D1 NEW
|
| 239 |
+
'thinsp': 0x2009, # thin space, U+2009 ISOpub
|
| 240 |
+
'thorn': 0x00fe, # latin small letter thorn with, U+00FE ISOlat1
|
| 241 |
+
'tilde': 0x02dc, # small tilde, U+02DC ISOdia
|
| 242 |
+
'times': 0x00d7, # multiplication sign, U+00D7 ISOnum
|
| 243 |
+
'trade': 0x2122, # trade mark sign, U+2122 ISOnum
|
| 244 |
+
'uArr': 0x21d1, # upwards double arrow, U+21D1 ISOamsa
|
| 245 |
+
'uacute': 0x00fa, # latin small letter u with acute, U+00FA ISOlat1
|
| 246 |
+
'uarr': 0x2191, # upwards arrow, U+2191 ISOnum
|
| 247 |
+
'ucirc': 0x00fb, # latin small letter u with circumflex, U+00FB ISOlat1
|
| 248 |
+
'ugrave': 0x00f9, # latin small letter u with grave, U+00F9 ISOlat1
|
| 249 |
+
'uml': 0x00a8, # diaeresis = spacing diaeresis, U+00A8 ISOdia
|
| 250 |
+
'upsih': 0x03d2, # greek upsilon with hook symbol, U+03D2 NEW
|
| 251 |
+
'upsilon': 0x03c5, # greek small letter upsilon, U+03C5 ISOgrk3
|
| 252 |
+
'uuml': 0x00fc, # latin small letter u with diaeresis, U+00FC ISOlat1
|
| 253 |
+
'weierp': 0x2118, # script capital P = power set = Weierstrass p, U+2118 ISOamso
|
| 254 |
+
'xi': 0x03be, # greek small letter xi, U+03BE ISOgrk3
|
| 255 |
+
'yacute': 0x00fd, # latin small letter y with acute, U+00FD ISOlat1
|
| 256 |
+
'yen': 0x00a5, # yen sign = yuan sign, U+00A5 ISOnum
|
| 257 |
+
'yuml': 0x00ff, # latin small letter y with diaeresis, U+00FF ISOlat1
|
| 258 |
+
'zeta': 0x03b6, # greek small letter zeta, U+03B6 ISOgrk3
|
| 259 |
+
'zwj': 0x200d, # zero width joiner, U+200D NEW RFC 2070
|
| 260 |
+
'zwnj': 0x200c, # zero width non-joiner, U+200C NEW RFC 2070
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
# maps the HTML5 named character references to the equivalent Unicode character(s)
|
| 265 |
+
html5 = {
|
| 266 |
+
'Aacute': '\xc1',
|
| 267 |
+
'aacute': '\xe1',
|
| 268 |
+
'Aacute;': '\xc1',
|
| 269 |
+
'aacute;': '\xe1',
|
| 270 |
+
'Abreve;': '\u0102',
|
| 271 |
+
'abreve;': '\u0103',
|
| 272 |
+
'ac;': '\u223e',
|
| 273 |
+
'acd;': '\u223f',
|
| 274 |
+
'acE;': '\u223e\u0333',
|
| 275 |
+
'Acirc': '\xc2',
|
| 276 |
+
'acirc': '\xe2',
|
| 277 |
+
'Acirc;': '\xc2',
|
| 278 |
+
'acirc;': '\xe2',
|
| 279 |
+
'acute': '\xb4',
|
| 280 |
+
'acute;': '\xb4',
|
| 281 |
+
'Acy;': '\u0410',
|
| 282 |
+
'acy;': '\u0430',
|
| 283 |
+
'AElig': '\xc6',
|
| 284 |
+
'aelig': '\xe6',
|
| 285 |
+
'AElig;': '\xc6',
|
| 286 |
+
'aelig;': '\xe6',
|
| 287 |
+
'af;': '\u2061',
|
| 288 |
+
'Afr;': '\U0001d504',
|
| 289 |
+
'afr;': '\U0001d51e',
|
| 290 |
+
'Agrave': '\xc0',
|
| 291 |
+
'agrave': '\xe0',
|
| 292 |
+
'Agrave;': '\xc0',
|
| 293 |
+
'agrave;': '\xe0',
|
| 294 |
+
'alefsym;': '\u2135',
|
| 295 |
+
'aleph;': '\u2135',
|
| 296 |
+
'Alpha;': '\u0391',
|
| 297 |
+
'alpha;': '\u03b1',
|
| 298 |
+
'Amacr;': '\u0100',
|
| 299 |
+
'amacr;': '\u0101',
|
| 300 |
+
'amalg;': '\u2a3f',
|
| 301 |
+
'AMP': '&',
|
| 302 |
+
'amp': '&',
|
| 303 |
+
'AMP;': '&',
|
| 304 |
+
'amp;': '&',
|
| 305 |
+
'And;': '\u2a53',
|
| 306 |
+
'and;': '\u2227',
|
| 307 |
+
'andand;': '\u2a55',
|
| 308 |
+
'andd;': '\u2a5c',
|
| 309 |
+
'andslope;': '\u2a58',
|
| 310 |
+
'andv;': '\u2a5a',
|
| 311 |
+
'ang;': '\u2220',
|
| 312 |
+
'ange;': '\u29a4',
|
| 313 |
+
'angle;': '\u2220',
|
| 314 |
+
'angmsd;': '\u2221',
|
| 315 |
+
'angmsdaa;': '\u29a8',
|
| 316 |
+
'angmsdab;': '\u29a9',
|
| 317 |
+
'angmsdac;': '\u29aa',
|
| 318 |
+
'angmsdad;': '\u29ab',
|
| 319 |
+
'angmsdae;': '\u29ac',
|
| 320 |
+
'angmsdaf;': '\u29ad',
|
| 321 |
+
'angmsdag;': '\u29ae',
|
| 322 |
+
'angmsdah;': '\u29af',
|
| 323 |
+
'angrt;': '\u221f',
|
| 324 |
+
'angrtvb;': '\u22be',
|
| 325 |
+
'angrtvbd;': '\u299d',
|
| 326 |
+
'angsph;': '\u2222',
|
| 327 |
+
'angst;': '\xc5',
|
| 328 |
+
'angzarr;': '\u237c',
|
| 329 |
+
'Aogon;': '\u0104',
|
| 330 |
+
'aogon;': '\u0105',
|
| 331 |
+
'Aopf;': '\U0001d538',
|
| 332 |
+
'aopf;': '\U0001d552',
|
| 333 |
+
'ap;': '\u2248',
|
| 334 |
+
'apacir;': '\u2a6f',
|
| 335 |
+
'apE;': '\u2a70',
|
| 336 |
+
'ape;': '\u224a',
|
| 337 |
+
'apid;': '\u224b',
|
| 338 |
+
'apos;': "'",
|
| 339 |
+
'ApplyFunction;': '\u2061',
|
| 340 |
+
'approx;': '\u2248',
|
| 341 |
+
'approxeq;': '\u224a',
|
| 342 |
+
'Aring': '\xc5',
|
| 343 |
+
'aring': '\xe5',
|
| 344 |
+
'Aring;': '\xc5',
|
| 345 |
+
'aring;': '\xe5',
|
| 346 |
+
'Ascr;': '\U0001d49c',
|
| 347 |
+
'ascr;': '\U0001d4b6',
|
| 348 |
+
'Assign;': '\u2254',
|
| 349 |
+
'ast;': '*',
|
| 350 |
+
'asymp;': '\u2248',
|
| 351 |
+
'asympeq;': '\u224d',
|
| 352 |
+
'Atilde': '\xc3',
|
| 353 |
+
'atilde': '\xe3',
|
| 354 |
+
'Atilde;': '\xc3',
|
| 355 |
+
'atilde;': '\xe3',
|
| 356 |
+
'Auml': '\xc4',
|
| 357 |
+
'auml': '\xe4',
|
| 358 |
+
'Auml;': '\xc4',
|
| 359 |
+
'auml;': '\xe4',
|
| 360 |
+
'awconint;': '\u2233',
|
| 361 |
+
'awint;': '\u2a11',
|
| 362 |
+
'backcong;': '\u224c',
|
| 363 |
+
'backepsilon;': '\u03f6',
|
| 364 |
+
'backprime;': '\u2035',
|
| 365 |
+
'backsim;': '\u223d',
|
| 366 |
+
'backsimeq;': '\u22cd',
|
| 367 |
+
'Backslash;': '\u2216',
|
| 368 |
+
'Barv;': '\u2ae7',
|
| 369 |
+
'barvee;': '\u22bd',
|
| 370 |
+
'Barwed;': '\u2306',
|
| 371 |
+
'barwed;': '\u2305',
|
| 372 |
+
'barwedge;': '\u2305',
|
| 373 |
+
'bbrk;': '\u23b5',
|
| 374 |
+
'bbrktbrk;': '\u23b6',
|
| 375 |
+
'bcong;': '\u224c',
|
| 376 |
+
'Bcy;': '\u0411',
|
| 377 |
+
'bcy;': '\u0431',
|
| 378 |
+
'bdquo;': '\u201e',
|
| 379 |
+
'becaus;': '\u2235',
|
| 380 |
+
'Because;': '\u2235',
|
| 381 |
+
'because;': '\u2235',
|
| 382 |
+
'bemptyv;': '\u29b0',
|
| 383 |
+
'bepsi;': '\u03f6',
|
| 384 |
+
'bernou;': '\u212c',
|
| 385 |
+
'Bernoullis;': '\u212c',
|
| 386 |
+
'Beta;': '\u0392',
|
| 387 |
+
'beta;': '\u03b2',
|
| 388 |
+
'beth;': '\u2136',
|
| 389 |
+
'between;': '\u226c',
|
| 390 |
+
'Bfr;': '\U0001d505',
|
| 391 |
+
'bfr;': '\U0001d51f',
|
| 392 |
+
'bigcap;': '\u22c2',
|
| 393 |
+
'bigcirc;': '\u25ef',
|
| 394 |
+
'bigcup;': '\u22c3',
|
| 395 |
+
'bigodot;': '\u2a00',
|
| 396 |
+
'bigoplus;': '\u2a01',
|
| 397 |
+
'bigotimes;': '\u2a02',
|
| 398 |
+
'bigsqcup;': '\u2a06',
|
| 399 |
+
'bigstar;': '\u2605',
|
| 400 |
+
'bigtriangledown;': '\u25bd',
|
| 401 |
+
'bigtriangleup;': '\u25b3',
|
| 402 |
+
'biguplus;': '\u2a04',
|
| 403 |
+
'bigvee;': '\u22c1',
|
| 404 |
+
'bigwedge;': '\u22c0',
|
| 405 |
+
'bkarow;': '\u290d',
|
| 406 |
+
'blacklozenge;': '\u29eb',
|
| 407 |
+
'blacksquare;': '\u25aa',
|
| 408 |
+
'blacktriangle;': '\u25b4',
|
| 409 |
+
'blacktriangledown;': '\u25be',
|
| 410 |
+
'blacktriangleleft;': '\u25c2',
|
| 411 |
+
'blacktriangleright;': '\u25b8',
|
| 412 |
+
'blank;': '\u2423',
|
| 413 |
+
'blk12;': '\u2592',
|
| 414 |
+
'blk14;': '\u2591',
|
| 415 |
+
'blk34;': '\u2593',
|
| 416 |
+
'block;': '\u2588',
|
| 417 |
+
'bne;': '=\u20e5',
|
| 418 |
+
'bnequiv;': '\u2261\u20e5',
|
| 419 |
+
'bNot;': '\u2aed',
|
| 420 |
+
'bnot;': '\u2310',
|
| 421 |
+
'Bopf;': '\U0001d539',
|
| 422 |
+
'bopf;': '\U0001d553',
|
| 423 |
+
'bot;': '\u22a5',
|
| 424 |
+
'bottom;': '\u22a5',
|
| 425 |
+
'bowtie;': '\u22c8',
|
| 426 |
+
'boxbox;': '\u29c9',
|
| 427 |
+
'boxDL;': '\u2557',
|
| 428 |
+
'boxDl;': '\u2556',
|
| 429 |
+
'boxdL;': '\u2555',
|
| 430 |
+
'boxdl;': '\u2510',
|
| 431 |
+
'boxDR;': '\u2554',
|
| 432 |
+
'boxDr;': '\u2553',
|
| 433 |
+
'boxdR;': '\u2552',
|
| 434 |
+
'boxdr;': '\u250c',
|
| 435 |
+
'boxH;': '\u2550',
|
| 436 |
+
'boxh;': '\u2500',
|
| 437 |
+
'boxHD;': '\u2566',
|
| 438 |
+
'boxHd;': '\u2564',
|
| 439 |
+
'boxhD;': '\u2565',
|
| 440 |
+
'boxhd;': '\u252c',
|
| 441 |
+
'boxHU;': '\u2569',
|
| 442 |
+
'boxHu;': '\u2567',
|
| 443 |
+
'boxhU;': '\u2568',
|
| 444 |
+
'boxhu;': '\u2534',
|
| 445 |
+
'boxminus;': '\u229f',
|
| 446 |
+
'boxplus;': '\u229e',
|
| 447 |
+
'boxtimes;': '\u22a0',
|
| 448 |
+
'boxUL;': '\u255d',
|
| 449 |
+
'boxUl;': '\u255c',
|
| 450 |
+
'boxuL;': '\u255b',
|
| 451 |
+
'boxul;': '\u2518',
|
| 452 |
+
'boxUR;': '\u255a',
|
| 453 |
+
'boxUr;': '\u2559',
|
| 454 |
+
'boxuR;': '\u2558',
|
| 455 |
+
'boxur;': '\u2514',
|
| 456 |
+
'boxV;': '\u2551',
|
| 457 |
+
'boxv;': '\u2502',
|
| 458 |
+
'boxVH;': '\u256c',
|
| 459 |
+
'boxVh;': '\u256b',
|
| 460 |
+
'boxvH;': '\u256a',
|
| 461 |
+
'boxvh;': '\u253c',
|
| 462 |
+
'boxVL;': '\u2563',
|
| 463 |
+
'boxVl;': '\u2562',
|
| 464 |
+
'boxvL;': '\u2561',
|
| 465 |
+
'boxvl;': '\u2524',
|
| 466 |
+
'boxVR;': '\u2560',
|
| 467 |
+
'boxVr;': '\u255f',
|
| 468 |
+
'boxvR;': '\u255e',
|
| 469 |
+
'boxvr;': '\u251c',
|
| 470 |
+
'bprime;': '\u2035',
|
| 471 |
+
'Breve;': '\u02d8',
|
| 472 |
+
'breve;': '\u02d8',
|
| 473 |
+
'brvbar': '\xa6',
|
| 474 |
+
'brvbar;': '\xa6',
|
| 475 |
+
'Bscr;': '\u212c',
|
| 476 |
+
'bscr;': '\U0001d4b7',
|
| 477 |
+
'bsemi;': '\u204f',
|
| 478 |
+
'bsim;': '\u223d',
|
| 479 |
+
'bsime;': '\u22cd',
|
| 480 |
+
'bsol;': '\\',
|
| 481 |
+
'bsolb;': '\u29c5',
|
| 482 |
+
'bsolhsub;': '\u27c8',
|
| 483 |
+
'bull;': '\u2022',
|
| 484 |
+
'bullet;': '\u2022',
|
| 485 |
+
'bump;': '\u224e',
|
| 486 |
+
'bumpE;': '\u2aae',
|
| 487 |
+
'bumpe;': '\u224f',
|
| 488 |
+
'Bumpeq;': '\u224e',
|
| 489 |
+
'bumpeq;': '\u224f',
|
| 490 |
+
'Cacute;': '\u0106',
|
| 491 |
+
'cacute;': '\u0107',
|
| 492 |
+
'Cap;': '\u22d2',
|
| 493 |
+
'cap;': '\u2229',
|
| 494 |
+
'capand;': '\u2a44',
|
| 495 |
+
'capbrcup;': '\u2a49',
|
| 496 |
+
'capcap;': '\u2a4b',
|
| 497 |
+
'capcup;': '\u2a47',
|
| 498 |
+
'capdot;': '\u2a40',
|
| 499 |
+
'CapitalDifferentialD;': '\u2145',
|
| 500 |
+
'caps;': '\u2229\ufe00',
|
| 501 |
+
'caret;': '\u2041',
|
| 502 |
+
'caron;': '\u02c7',
|
| 503 |
+
'Cayleys;': '\u212d',
|
| 504 |
+
'ccaps;': '\u2a4d',
|
| 505 |
+
'Ccaron;': '\u010c',
|
| 506 |
+
'ccaron;': '\u010d',
|
| 507 |
+
'Ccedil': '\xc7',
|
| 508 |
+
'ccedil': '\xe7',
|
| 509 |
+
'Ccedil;': '\xc7',
|
| 510 |
+
'ccedil;': '\xe7',
|
| 511 |
+
'Ccirc;': '\u0108',
|
| 512 |
+
'ccirc;': '\u0109',
|
| 513 |
+
'Cconint;': '\u2230',
|
| 514 |
+
'ccups;': '\u2a4c',
|
| 515 |
+
'ccupssm;': '\u2a50',
|
| 516 |
+
'Cdot;': '\u010a',
|
| 517 |
+
'cdot;': '\u010b',
|
| 518 |
+
'cedil': '\xb8',
|
| 519 |
+
'cedil;': '\xb8',
|
| 520 |
+
'Cedilla;': '\xb8',
|
| 521 |
+
'cemptyv;': '\u29b2',
|
| 522 |
+
'cent': '\xa2',
|
| 523 |
+
'cent;': '\xa2',
|
| 524 |
+
'CenterDot;': '\xb7',
|
| 525 |
+
'centerdot;': '\xb7',
|
| 526 |
+
'Cfr;': '\u212d',
|
| 527 |
+
'cfr;': '\U0001d520',
|
| 528 |
+
'CHcy;': '\u0427',
|
| 529 |
+
'chcy;': '\u0447',
|
| 530 |
+
'check;': '\u2713',
|
| 531 |
+
'checkmark;': '\u2713',
|
| 532 |
+
'Chi;': '\u03a7',
|
| 533 |
+
'chi;': '\u03c7',
|
| 534 |
+
'cir;': '\u25cb',
|
| 535 |
+
'circ;': '\u02c6',
|
| 536 |
+
'circeq;': '\u2257',
|
| 537 |
+
'circlearrowleft;': '\u21ba',
|
| 538 |
+
'circlearrowright;': '\u21bb',
|
| 539 |
+
'circledast;': '\u229b',
|
| 540 |
+
'circledcirc;': '\u229a',
|
| 541 |
+
'circleddash;': '\u229d',
|
| 542 |
+
'CircleDot;': '\u2299',
|
| 543 |
+
'circledR;': '\xae',
|
| 544 |
+
'circledS;': '\u24c8',
|
| 545 |
+
'CircleMinus;': '\u2296',
|
| 546 |
+
'CirclePlus;': '\u2295',
|
| 547 |
+
'CircleTimes;': '\u2297',
|
| 548 |
+
'cirE;': '\u29c3',
|
| 549 |
+
'cire;': '\u2257',
|
| 550 |
+
'cirfnint;': '\u2a10',
|
| 551 |
+
'cirmid;': '\u2aef',
|
| 552 |
+
'cirscir;': '\u29c2',
|
| 553 |
+
'ClockwiseContourIntegral;': '\u2232',
|
| 554 |
+
'CloseCurlyDoubleQuote;': '\u201d',
|
| 555 |
+
'CloseCurlyQuote;': '\u2019',
|
| 556 |
+
'clubs;': '\u2663',
|
| 557 |
+
'clubsuit;': '\u2663',
|
| 558 |
+
'Colon;': '\u2237',
|
| 559 |
+
'colon;': ':',
|
| 560 |
+
'Colone;': '\u2a74',
|
| 561 |
+
'colone;': '\u2254',
|
| 562 |
+
'coloneq;': '\u2254',
|
| 563 |
+
'comma;': ',',
|
| 564 |
+
'commat;': '@',
|
| 565 |
+
'comp;': '\u2201',
|
| 566 |
+
'compfn;': '\u2218',
|
| 567 |
+
'complement;': '\u2201',
|
| 568 |
+
'complexes;': '\u2102',
|
| 569 |
+
'cong;': '\u2245',
|
| 570 |
+
'congdot;': '\u2a6d',
|
| 571 |
+
'Congruent;': '\u2261',
|
| 572 |
+
'Conint;': '\u222f',
|
| 573 |
+
'conint;': '\u222e',
|
| 574 |
+
'ContourIntegral;': '\u222e',
|
| 575 |
+
'Copf;': '\u2102',
|
| 576 |
+
'copf;': '\U0001d554',
|
| 577 |
+
'coprod;': '\u2210',
|
| 578 |
+
'Coproduct;': '\u2210',
|
| 579 |
+
'COPY': '\xa9',
|
| 580 |
+
'copy': '\xa9',
|
| 581 |
+
'COPY;': '\xa9',
|
| 582 |
+
'copy;': '\xa9',
|
| 583 |
+
'copysr;': '\u2117',
|
| 584 |
+
'CounterClockwiseContourIntegral;': '\u2233',
|
| 585 |
+
'crarr;': '\u21b5',
|
| 586 |
+
'Cross;': '\u2a2f',
|
| 587 |
+
'cross;': '\u2717',
|
| 588 |
+
'Cscr;': '\U0001d49e',
|
| 589 |
+
'cscr;': '\U0001d4b8',
|
| 590 |
+
'csub;': '\u2acf',
|
| 591 |
+
'csube;': '\u2ad1',
|
| 592 |
+
'csup;': '\u2ad0',
|
| 593 |
+
'csupe;': '\u2ad2',
|
| 594 |
+
'ctdot;': '\u22ef',
|
| 595 |
+
'cudarrl;': '\u2938',
|
| 596 |
+
'cudarrr;': '\u2935',
|
| 597 |
+
'cuepr;': '\u22de',
|
| 598 |
+
'cuesc;': '\u22df',
|
| 599 |
+
'cularr;': '\u21b6',
|
| 600 |
+
'cularrp;': '\u293d',
|
| 601 |
+
'Cup;': '\u22d3',
|
| 602 |
+
'cup;': '\u222a',
|
| 603 |
+
'cupbrcap;': '\u2a48',
|
| 604 |
+
'CupCap;': '\u224d',
|
| 605 |
+
'cupcap;': '\u2a46',
|
| 606 |
+
'cupcup;': '\u2a4a',
|
| 607 |
+
'cupdot;': '\u228d',
|
| 608 |
+
'cupor;': '\u2a45',
|
| 609 |
+
'cups;': '\u222a\ufe00',
|
| 610 |
+
'curarr;': '\u21b7',
|
| 611 |
+
'curarrm;': '\u293c',
|
| 612 |
+
'curlyeqprec;': '\u22de',
|
| 613 |
+
'curlyeqsucc;': '\u22df',
|
| 614 |
+
'curlyvee;': '\u22ce',
|
| 615 |
+
'curlywedge;': '\u22cf',
|
| 616 |
+
'curren': '\xa4',
|
| 617 |
+
'curren;': '\xa4',
|
| 618 |
+
'curvearrowleft;': '\u21b6',
|
| 619 |
+
'curvearrowright;': '\u21b7',
|
| 620 |
+
'cuvee;': '\u22ce',
|
| 621 |
+
'cuwed;': '\u22cf',
|
| 622 |
+
'cwconint;': '\u2232',
|
| 623 |
+
'cwint;': '\u2231',
|
| 624 |
+
'cylcty;': '\u232d',
|
| 625 |
+
'Dagger;': '\u2021',
|
| 626 |
+
'dagger;': '\u2020',
|
| 627 |
+
'daleth;': '\u2138',
|
| 628 |
+
'Darr;': '\u21a1',
|
| 629 |
+
'dArr;': '\u21d3',
|
| 630 |
+
'darr;': '\u2193',
|
| 631 |
+
'dash;': '\u2010',
|
| 632 |
+
'Dashv;': '\u2ae4',
|
| 633 |
+
'dashv;': '\u22a3',
|
| 634 |
+
'dbkarow;': '\u290f',
|
| 635 |
+
'dblac;': '\u02dd',
|
| 636 |
+
'Dcaron;': '\u010e',
|
| 637 |
+
'dcaron;': '\u010f',
|
| 638 |
+
'Dcy;': '\u0414',
|
| 639 |
+
'dcy;': '\u0434',
|
| 640 |
+
'DD;': '\u2145',
|
| 641 |
+
'dd;': '\u2146',
|
| 642 |
+
'ddagger;': '\u2021',
|
| 643 |
+
'ddarr;': '\u21ca',
|
| 644 |
+
'DDotrahd;': '\u2911',
|
| 645 |
+
'ddotseq;': '\u2a77',
|
| 646 |
+
'deg': '\xb0',
|
| 647 |
+
'deg;': '\xb0',
|
| 648 |
+
'Del;': '\u2207',
|
| 649 |
+
'Delta;': '\u0394',
|
| 650 |
+
'delta;': '\u03b4',
|
| 651 |
+
'demptyv;': '\u29b1',
|
| 652 |
+
'dfisht;': '\u297f',
|
| 653 |
+
'Dfr;': '\U0001d507',
|
| 654 |
+
'dfr;': '\U0001d521',
|
| 655 |
+
'dHar;': '\u2965',
|
| 656 |
+
'dharl;': '\u21c3',
|
| 657 |
+
'dharr;': '\u21c2',
|
| 658 |
+
'DiacriticalAcute;': '\xb4',
|
| 659 |
+
'DiacriticalDot;': '\u02d9',
|
| 660 |
+
'DiacriticalDoubleAcute;': '\u02dd',
|
| 661 |
+
'DiacriticalGrave;': '`',
|
| 662 |
+
'DiacriticalTilde;': '\u02dc',
|
| 663 |
+
'diam;': '\u22c4',
|
| 664 |
+
'Diamond;': '\u22c4',
|
| 665 |
+
'diamond;': '\u22c4',
|
| 666 |
+
'diamondsuit;': '\u2666',
|
| 667 |
+
'diams;': '\u2666',
|
| 668 |
+
'die;': '\xa8',
|
| 669 |
+
'DifferentialD;': '\u2146',
|
| 670 |
+
'digamma;': '\u03dd',
|
| 671 |
+
'disin;': '\u22f2',
|
| 672 |
+
'div;': '\xf7',
|
| 673 |
+
'divide': '\xf7',
|
| 674 |
+
'divide;': '\xf7',
|
| 675 |
+
'divideontimes;': '\u22c7',
|
| 676 |
+
'divonx;': '\u22c7',
|
| 677 |
+
'DJcy;': '\u0402',
|
| 678 |
+
'djcy;': '\u0452',
|
| 679 |
+
'dlcorn;': '\u231e',
|
| 680 |
+
'dlcrop;': '\u230d',
|
| 681 |
+
'dollar;': '$',
|
| 682 |
+
'Dopf;': '\U0001d53b',
|
| 683 |
+
'dopf;': '\U0001d555',
|
| 684 |
+
'Dot;': '\xa8',
|
| 685 |
+
'dot;': '\u02d9',
|
| 686 |
+
'DotDot;': '\u20dc',
|
| 687 |
+
'doteq;': '\u2250',
|
| 688 |
+
'doteqdot;': '\u2251',
|
| 689 |
+
'DotEqual;': '\u2250',
|
| 690 |
+
'dotminus;': '\u2238',
|
| 691 |
+
'dotplus;': '\u2214',
|
| 692 |
+
'dotsquare;': '\u22a1',
|
| 693 |
+
'doublebarwedge;': '\u2306',
|
| 694 |
+
'DoubleContourIntegral;': '\u222f',
|
| 695 |
+
'DoubleDot;': '\xa8',
|
| 696 |
+
'DoubleDownArrow;': '\u21d3',
|
| 697 |
+
'DoubleLeftArrow;': '\u21d0',
|
| 698 |
+
'DoubleLeftRightArrow;': '\u21d4',
|
| 699 |
+
'DoubleLeftTee;': '\u2ae4',
|
| 700 |
+
'DoubleLongLeftArrow;': '\u27f8',
|
| 701 |
+
'DoubleLongLeftRightArrow;': '\u27fa',
|
| 702 |
+
'DoubleLongRightArrow;': '\u27f9',
|
| 703 |
+
'DoubleRightArrow;': '\u21d2',
|
| 704 |
+
'DoubleRightTee;': '\u22a8',
|
| 705 |
+
'DoubleUpArrow;': '\u21d1',
|
| 706 |
+
'DoubleUpDownArrow;': '\u21d5',
|
| 707 |
+
'DoubleVerticalBar;': '\u2225',
|
| 708 |
+
'DownArrow;': '\u2193',
|
| 709 |
+
'Downarrow;': '\u21d3',
|
| 710 |
+
'downarrow;': '\u2193',
|
| 711 |
+
'DownArrowBar;': '\u2913',
|
| 712 |
+
'DownArrowUpArrow;': '\u21f5',
|
| 713 |
+
'DownBreve;': '\u0311',
|
| 714 |
+
'downdownarrows;': '\u21ca',
|
| 715 |
+
'downharpoonleft;': '\u21c3',
|
| 716 |
+
'downharpoonright;': '\u21c2',
|
| 717 |
+
'DownLeftRightVector;': '\u2950',
|
| 718 |
+
'DownLeftTeeVector;': '\u295e',
|
| 719 |
+
'DownLeftVector;': '\u21bd',
|
| 720 |
+
'DownLeftVectorBar;': '\u2956',
|
| 721 |
+
'DownRightTeeVector;': '\u295f',
|
| 722 |
+
'DownRightVector;': '\u21c1',
|
| 723 |
+
'DownRightVectorBar;': '\u2957',
|
| 724 |
+
'DownTee;': '\u22a4',
|
| 725 |
+
'DownTeeArrow;': '\u21a7',
|
| 726 |
+
'drbkarow;': '\u2910',
|
| 727 |
+
'drcorn;': '\u231f',
|
| 728 |
+
'drcrop;': '\u230c',
|
| 729 |
+
'Dscr;': '\U0001d49f',
|
| 730 |
+
'dscr;': '\U0001d4b9',
|
| 731 |
+
'DScy;': '\u0405',
|
| 732 |
+
'dscy;': '\u0455',
|
| 733 |
+
'dsol;': '\u29f6',
|
| 734 |
+
'Dstrok;': '\u0110',
|
| 735 |
+
'dstrok;': '\u0111',
|
| 736 |
+
'dtdot;': '\u22f1',
|
| 737 |
+
'dtri;': '\u25bf',
|
| 738 |
+
'dtrif;': '\u25be',
|
| 739 |
+
'duarr;': '\u21f5',
|
| 740 |
+
'duhar;': '\u296f',
|
| 741 |
+
'dwangle;': '\u29a6',
|
| 742 |
+
'DZcy;': '\u040f',
|
| 743 |
+
'dzcy;': '\u045f',
|
| 744 |
+
'dzigrarr;': '\u27ff',
|
| 745 |
+
'Eacute': '\xc9',
|
| 746 |
+
'eacute': '\xe9',
|
| 747 |
+
'Eacute;': '\xc9',
|
| 748 |
+
'eacute;': '\xe9',
|
| 749 |
+
'easter;': '\u2a6e',
|
| 750 |
+
'Ecaron;': '\u011a',
|
| 751 |
+
'ecaron;': '\u011b',
|
| 752 |
+
'ecir;': '\u2256',
|
| 753 |
+
'Ecirc': '\xca',
|
| 754 |
+
'ecirc': '\xea',
|
| 755 |
+
'Ecirc;': '\xca',
|
| 756 |
+
'ecirc;': '\xea',
|
| 757 |
+
'ecolon;': '\u2255',
|
| 758 |
+
'Ecy;': '\u042d',
|
| 759 |
+
'ecy;': '\u044d',
|
| 760 |
+
'eDDot;': '\u2a77',
|
| 761 |
+
'Edot;': '\u0116',
|
| 762 |
+
'eDot;': '\u2251',
|
| 763 |
+
'edot;': '\u0117',
|
| 764 |
+
'ee;': '\u2147',
|
| 765 |
+
'efDot;': '\u2252',
|
| 766 |
+
'Efr;': '\U0001d508',
|
| 767 |
+
'efr;': '\U0001d522',
|
| 768 |
+
'eg;': '\u2a9a',
|
| 769 |
+
'Egrave': '\xc8',
|
| 770 |
+
'egrave': '\xe8',
|
| 771 |
+
'Egrave;': '\xc8',
|
| 772 |
+
'egrave;': '\xe8',
|
| 773 |
+
'egs;': '\u2a96',
|
| 774 |
+
'egsdot;': '\u2a98',
|
| 775 |
+
'el;': '\u2a99',
|
| 776 |
+
'Element;': '\u2208',
|
| 777 |
+
'elinters;': '\u23e7',
|
| 778 |
+
'ell;': '\u2113',
|
| 779 |
+
'els;': '\u2a95',
|
| 780 |
+
'elsdot;': '\u2a97',
|
| 781 |
+
'Emacr;': '\u0112',
|
| 782 |
+
'emacr;': '\u0113',
|
| 783 |
+
'empty;': '\u2205',
|
| 784 |
+
'emptyset;': '\u2205',
|
| 785 |
+
'EmptySmallSquare;': '\u25fb',
|
| 786 |
+
'emptyv;': '\u2205',
|
| 787 |
+
'EmptyVerySmallSquare;': '\u25ab',
|
| 788 |
+
'emsp13;': '\u2004',
|
| 789 |
+
'emsp14;': '\u2005',
|
| 790 |
+
'emsp;': '\u2003',
|
| 791 |
+
'ENG;': '\u014a',
|
| 792 |
+
'eng;': '\u014b',
|
| 793 |
+
'ensp;': '\u2002',
|
| 794 |
+
'Eogon;': '\u0118',
|
| 795 |
+
'eogon;': '\u0119',
|
| 796 |
+
'Eopf;': '\U0001d53c',
|
| 797 |
+
'eopf;': '\U0001d556',
|
| 798 |
+
'epar;': '\u22d5',
|
| 799 |
+
'eparsl;': '\u29e3',
|
| 800 |
+
'eplus;': '\u2a71',
|
| 801 |
+
'epsi;': '\u03b5',
|
| 802 |
+
'Epsilon;': '\u0395',
|
| 803 |
+
'epsilon;': '\u03b5',
|
| 804 |
+
'epsiv;': '\u03f5',
|
| 805 |
+
'eqcirc;': '\u2256',
|
| 806 |
+
'eqcolon;': '\u2255',
|
| 807 |
+
'eqsim;': '\u2242',
|
| 808 |
+
'eqslantgtr;': '\u2a96',
|
| 809 |
+
'eqslantless;': '\u2a95',
|
| 810 |
+
'Equal;': '\u2a75',
|
| 811 |
+
'equals;': '=',
|
| 812 |
+
'EqualTilde;': '\u2242',
|
| 813 |
+
'equest;': '\u225f',
|
| 814 |
+
'Equilibrium;': '\u21cc',
|
| 815 |
+
'equiv;': '\u2261',
|
| 816 |
+
'equivDD;': '\u2a78',
|
| 817 |
+
'eqvparsl;': '\u29e5',
|
| 818 |
+
'erarr;': '\u2971',
|
| 819 |
+
'erDot;': '\u2253',
|
| 820 |
+
'Escr;': '\u2130',
|
| 821 |
+
'escr;': '\u212f',
|
| 822 |
+
'esdot;': '\u2250',
|
| 823 |
+
'Esim;': '\u2a73',
|
| 824 |
+
'esim;': '\u2242',
|
| 825 |
+
'Eta;': '\u0397',
|
| 826 |
+
'eta;': '\u03b7',
|
| 827 |
+
'ETH': '\xd0',
|
| 828 |
+
'eth': '\xf0',
|
| 829 |
+
'ETH;': '\xd0',
|
| 830 |
+
'eth;': '\xf0',
|
| 831 |
+
'Euml': '\xcb',
|
| 832 |
+
'euml': '\xeb',
|
| 833 |
+
'Euml;': '\xcb',
|
| 834 |
+
'euml;': '\xeb',
|
| 835 |
+
'euro;': '\u20ac',
|
| 836 |
+
'excl;': '!',
|
| 837 |
+
'exist;': '\u2203',
|
| 838 |
+
'Exists;': '\u2203',
|
| 839 |
+
'expectation;': '\u2130',
|
| 840 |
+
'ExponentialE;': '\u2147',
|
| 841 |
+
'exponentiale;': '\u2147',
|
| 842 |
+
'fallingdotseq;': '\u2252',
|
| 843 |
+
'Fcy;': '\u0424',
|
| 844 |
+
'fcy;': '\u0444',
|
| 845 |
+
'female;': '\u2640',
|
| 846 |
+
'ffilig;': '\ufb03',
|
| 847 |
+
'fflig;': '\ufb00',
|
| 848 |
+
'ffllig;': '\ufb04',
|
| 849 |
+
'Ffr;': '\U0001d509',
|
| 850 |
+
'ffr;': '\U0001d523',
|
| 851 |
+
'filig;': '\ufb01',
|
| 852 |
+
'FilledSmallSquare;': '\u25fc',
|
| 853 |
+
'FilledVerySmallSquare;': '\u25aa',
|
| 854 |
+
'fjlig;': 'fj',
|
| 855 |
+
'flat;': '\u266d',
|
| 856 |
+
'fllig;': '\ufb02',
|
| 857 |
+
'fltns;': '\u25b1',
|
| 858 |
+
'fnof;': '\u0192',
|
| 859 |
+
'Fopf;': '\U0001d53d',
|
| 860 |
+
'fopf;': '\U0001d557',
|
| 861 |
+
'ForAll;': '\u2200',
|
| 862 |
+
'forall;': '\u2200',
|
| 863 |
+
'fork;': '\u22d4',
|
| 864 |
+
'forkv;': '\u2ad9',
|
| 865 |
+
'Fouriertrf;': '\u2131',
|
| 866 |
+
'fpartint;': '\u2a0d',
|
| 867 |
+
'frac12': '\xbd',
|
| 868 |
+
'frac12;': '\xbd',
|
| 869 |
+
'frac13;': '\u2153',
|
| 870 |
+
'frac14': '\xbc',
|
| 871 |
+
'frac14;': '\xbc',
|
| 872 |
+
'frac15;': '\u2155',
|
| 873 |
+
'frac16;': '\u2159',
|
| 874 |
+
'frac18;': '\u215b',
|
| 875 |
+
'frac23;': '\u2154',
|
| 876 |
+
'frac25;': '\u2156',
|
| 877 |
+
'frac34': '\xbe',
|
| 878 |
+
'frac34;': '\xbe',
|
| 879 |
+
'frac35;': '\u2157',
|
| 880 |
+
'frac38;': '\u215c',
|
| 881 |
+
'frac45;': '\u2158',
|
| 882 |
+
'frac56;': '\u215a',
|
| 883 |
+
'frac58;': '\u215d',
|
| 884 |
+
'frac78;': '\u215e',
|
| 885 |
+
'frasl;': '\u2044',
|
| 886 |
+
'frown;': '\u2322',
|
| 887 |
+
'Fscr;': '\u2131',
|
| 888 |
+
'fscr;': '\U0001d4bb',
|
| 889 |
+
'gacute;': '\u01f5',
|
| 890 |
+
'Gamma;': '\u0393',
|
| 891 |
+
'gamma;': '\u03b3',
|
| 892 |
+
'Gammad;': '\u03dc',
|
| 893 |
+
'gammad;': '\u03dd',
|
| 894 |
+
'gap;': '\u2a86',
|
| 895 |
+
'Gbreve;': '\u011e',
|
| 896 |
+
'gbreve;': '\u011f',
|
| 897 |
+
'Gcedil;': '\u0122',
|
| 898 |
+
'Gcirc;': '\u011c',
|
| 899 |
+
'gcirc;': '\u011d',
|
| 900 |
+
'Gcy;': '\u0413',
|
| 901 |
+
'gcy;': '\u0433',
|
| 902 |
+
'Gdot;': '\u0120',
|
| 903 |
+
'gdot;': '\u0121',
|
| 904 |
+
'gE;': '\u2267',
|
| 905 |
+
'ge;': '\u2265',
|
| 906 |
+
'gEl;': '\u2a8c',
|
| 907 |
+
'gel;': '\u22db',
|
| 908 |
+
'geq;': '\u2265',
|
| 909 |
+
'geqq;': '\u2267',
|
| 910 |
+
'geqslant;': '\u2a7e',
|
| 911 |
+
'ges;': '\u2a7e',
|
| 912 |
+
'gescc;': '\u2aa9',
|
| 913 |
+
'gesdot;': '\u2a80',
|
| 914 |
+
'gesdoto;': '\u2a82',
|
| 915 |
+
'gesdotol;': '\u2a84',
|
| 916 |
+
'gesl;': '\u22db\ufe00',
|
| 917 |
+
'gesles;': '\u2a94',
|
| 918 |
+
'Gfr;': '\U0001d50a',
|
| 919 |
+
'gfr;': '\U0001d524',
|
| 920 |
+
'Gg;': '\u22d9',
|
| 921 |
+
'gg;': '\u226b',
|
| 922 |
+
'ggg;': '\u22d9',
|
| 923 |
+
'gimel;': '\u2137',
|
| 924 |
+
'GJcy;': '\u0403',
|
| 925 |
+
'gjcy;': '\u0453',
|
| 926 |
+
'gl;': '\u2277',
|
| 927 |
+
'gla;': '\u2aa5',
|
| 928 |
+
'glE;': '\u2a92',
|
| 929 |
+
'glj;': '\u2aa4',
|
| 930 |
+
'gnap;': '\u2a8a',
|
| 931 |
+
'gnapprox;': '\u2a8a',
|
| 932 |
+
'gnE;': '\u2269',
|
| 933 |
+
'gne;': '\u2a88',
|
| 934 |
+
'gneq;': '\u2a88',
|
| 935 |
+
'gneqq;': '\u2269',
|
| 936 |
+
'gnsim;': '\u22e7',
|
| 937 |
+
'Gopf;': '\U0001d53e',
|
| 938 |
+
'gopf;': '\U0001d558',
|
| 939 |
+
'grave;': '`',
|
| 940 |
+
'GreaterEqual;': '\u2265',
|
| 941 |
+
'GreaterEqualLess;': '\u22db',
|
| 942 |
+
'GreaterFullEqual;': '\u2267',
|
| 943 |
+
'GreaterGreater;': '\u2aa2',
|
| 944 |
+
'GreaterLess;': '\u2277',
|
| 945 |
+
'GreaterSlantEqual;': '\u2a7e',
|
| 946 |
+
'GreaterTilde;': '\u2273',
|
| 947 |
+
'Gscr;': '\U0001d4a2',
|
| 948 |
+
'gscr;': '\u210a',
|
| 949 |
+
'gsim;': '\u2273',
|
| 950 |
+
'gsime;': '\u2a8e',
|
| 951 |
+
'gsiml;': '\u2a90',
|
| 952 |
+
'GT': '>',
|
| 953 |
+
'gt': '>',
|
| 954 |
+
'GT;': '>',
|
| 955 |
+
'Gt;': '\u226b',
|
| 956 |
+
'gt;': '>',
|
| 957 |
+
'gtcc;': '\u2aa7',
|
| 958 |
+
'gtcir;': '\u2a7a',
|
| 959 |
+
'gtdot;': '\u22d7',
|
| 960 |
+
'gtlPar;': '\u2995',
|
| 961 |
+
'gtquest;': '\u2a7c',
|
| 962 |
+
'gtrapprox;': '\u2a86',
|
| 963 |
+
'gtrarr;': '\u2978',
|
| 964 |
+
'gtrdot;': '\u22d7',
|
| 965 |
+
'gtreqless;': '\u22db',
|
| 966 |
+
'gtreqqless;': '\u2a8c',
|
| 967 |
+
'gtrless;': '\u2277',
|
| 968 |
+
'gtrsim;': '\u2273',
|
| 969 |
+
'gvertneqq;': '\u2269\ufe00',
|
| 970 |
+
'gvnE;': '\u2269\ufe00',
|
| 971 |
+
'Hacek;': '\u02c7',
|
| 972 |
+
'hairsp;': '\u200a',
|
| 973 |
+
'half;': '\xbd',
|
| 974 |
+
'hamilt;': '\u210b',
|
| 975 |
+
'HARDcy;': '\u042a',
|
| 976 |
+
'hardcy;': '\u044a',
|
| 977 |
+
'hArr;': '\u21d4',
|
| 978 |
+
'harr;': '\u2194',
|
| 979 |
+
'harrcir;': '\u2948',
|
| 980 |
+
'harrw;': '\u21ad',
|
| 981 |
+
'Hat;': '^',
|
| 982 |
+
'hbar;': '\u210f',
|
| 983 |
+
'Hcirc;': '\u0124',
|
| 984 |
+
'hcirc;': '\u0125',
|
| 985 |
+
'hearts;': '\u2665',
|
| 986 |
+
'heartsuit;': '\u2665',
|
| 987 |
+
'hellip;': '\u2026',
|
| 988 |
+
'hercon;': '\u22b9',
|
| 989 |
+
'Hfr;': '\u210c',
|
| 990 |
+
'hfr;': '\U0001d525',
|
| 991 |
+
'HilbertSpace;': '\u210b',
|
| 992 |
+
'hksearow;': '\u2925',
|
| 993 |
+
'hkswarow;': '\u2926',
|
| 994 |
+
'hoarr;': '\u21ff',
|
| 995 |
+
'homtht;': '\u223b',
|
| 996 |
+
'hookleftarrow;': '\u21a9',
|
| 997 |
+
'hookrightarrow;': '\u21aa',
|
| 998 |
+
'Hopf;': '\u210d',
|
| 999 |
+
'hopf;': '\U0001d559',
|
| 1000 |
+
'horbar;': '\u2015',
|
| 1001 |
+
'HorizontalLine;': '\u2500',
|
| 1002 |
+
'Hscr;': '\u210b',
|
| 1003 |
+
'hscr;': '\U0001d4bd',
|
| 1004 |
+
'hslash;': '\u210f',
|
| 1005 |
+
'Hstrok;': '\u0126',
|
| 1006 |
+
'hstrok;': '\u0127',
|
| 1007 |
+
'HumpDownHump;': '\u224e',
|
| 1008 |
+
'HumpEqual;': '\u224f',
|
| 1009 |
+
'hybull;': '\u2043',
|
| 1010 |
+
'hyphen;': '\u2010',
|
| 1011 |
+
'Iacute': '\xcd',
|
| 1012 |
+
'iacute': '\xed',
|
| 1013 |
+
'Iacute;': '\xcd',
|
| 1014 |
+
'iacute;': '\xed',
|
| 1015 |
+
'ic;': '\u2063',
|
| 1016 |
+
'Icirc': '\xce',
|
| 1017 |
+
'icirc': '\xee',
|
| 1018 |
+
'Icirc;': '\xce',
|
| 1019 |
+
'icirc;': '\xee',
|
| 1020 |
+
'Icy;': '\u0418',
|
| 1021 |
+
'icy;': '\u0438',
|
| 1022 |
+
'Idot;': '\u0130',
|
| 1023 |
+
'IEcy;': '\u0415',
|
| 1024 |
+
'iecy;': '\u0435',
|
| 1025 |
+
'iexcl': '\xa1',
|
| 1026 |
+
'iexcl;': '\xa1',
|
| 1027 |
+
'iff;': '\u21d4',
|
| 1028 |
+
'Ifr;': '\u2111',
|
| 1029 |
+
'ifr;': '\U0001d526',
|
| 1030 |
+
'Igrave': '\xcc',
|
| 1031 |
+
'igrave': '\xec',
|
| 1032 |
+
'Igrave;': '\xcc',
|
| 1033 |
+
'igrave;': '\xec',
|
| 1034 |
+
'ii;': '\u2148',
|
| 1035 |
+
'iiiint;': '\u2a0c',
|
| 1036 |
+
'iiint;': '\u222d',
|
| 1037 |
+
'iinfin;': '\u29dc',
|
| 1038 |
+
'iiota;': '\u2129',
|
| 1039 |
+
'IJlig;': '\u0132',
|
| 1040 |
+
'ijlig;': '\u0133',
|
| 1041 |
+
'Im;': '\u2111',
|
| 1042 |
+
'Imacr;': '\u012a',
|
| 1043 |
+
'imacr;': '\u012b',
|
| 1044 |
+
'image;': '\u2111',
|
| 1045 |
+
'ImaginaryI;': '\u2148',
|
| 1046 |
+
'imagline;': '\u2110',
|
| 1047 |
+
'imagpart;': '\u2111',
|
| 1048 |
+
'imath;': '\u0131',
|
| 1049 |
+
'imof;': '\u22b7',
|
| 1050 |
+
'imped;': '\u01b5',
|
| 1051 |
+
'Implies;': '\u21d2',
|
| 1052 |
+
'in;': '\u2208',
|
| 1053 |
+
'incare;': '\u2105',
|
| 1054 |
+
'infin;': '\u221e',
|
| 1055 |
+
'infintie;': '\u29dd',
|
| 1056 |
+
'inodot;': '\u0131',
|
| 1057 |
+
'Int;': '\u222c',
|
| 1058 |
+
'int;': '\u222b',
|
| 1059 |
+
'intcal;': '\u22ba',
|
| 1060 |
+
'integers;': '\u2124',
|
| 1061 |
+
'Integral;': '\u222b',
|
| 1062 |
+
'intercal;': '\u22ba',
|
| 1063 |
+
'Intersection;': '\u22c2',
|
| 1064 |
+
'intlarhk;': '\u2a17',
|
| 1065 |
+
'intprod;': '\u2a3c',
|
| 1066 |
+
'InvisibleComma;': '\u2063',
|
| 1067 |
+
'InvisibleTimes;': '\u2062',
|
| 1068 |
+
'IOcy;': '\u0401',
|
| 1069 |
+
'iocy;': '\u0451',
|
| 1070 |
+
'Iogon;': '\u012e',
|
| 1071 |
+
'iogon;': '\u012f',
|
| 1072 |
+
'Iopf;': '\U0001d540',
|
| 1073 |
+
'iopf;': '\U0001d55a',
|
| 1074 |
+
'Iota;': '\u0399',
|
| 1075 |
+
'iota;': '\u03b9',
|
| 1076 |
+
'iprod;': '\u2a3c',
|
| 1077 |
+
'iquest': '\xbf',
|
| 1078 |
+
'iquest;': '\xbf',
|
| 1079 |
+
'Iscr;': '\u2110',
|
| 1080 |
+
'iscr;': '\U0001d4be',
|
| 1081 |
+
'isin;': '\u2208',
|
| 1082 |
+
'isindot;': '\u22f5',
|
| 1083 |
+
'isinE;': '\u22f9',
|
| 1084 |
+
'isins;': '\u22f4',
|
| 1085 |
+
'isinsv;': '\u22f3',
|
| 1086 |
+
'isinv;': '\u2208',
|
| 1087 |
+
'it;': '\u2062',
|
| 1088 |
+
'Itilde;': '\u0128',
|
| 1089 |
+
'itilde;': '\u0129',
|
| 1090 |
+
'Iukcy;': '\u0406',
|
| 1091 |
+
'iukcy;': '\u0456',
|
| 1092 |
+
'Iuml': '\xcf',
|
| 1093 |
+
'iuml': '\xef',
|
| 1094 |
+
'Iuml;': '\xcf',
|
| 1095 |
+
'iuml;': '\xef',
|
| 1096 |
+
'Jcirc;': '\u0134',
|
| 1097 |
+
'jcirc;': '\u0135',
|
| 1098 |
+
'Jcy;': '\u0419',
|
| 1099 |
+
'jcy;': '\u0439',
|
| 1100 |
+
'Jfr;': '\U0001d50d',
|
| 1101 |
+
'jfr;': '\U0001d527',
|
| 1102 |
+
'jmath;': '\u0237',
|
| 1103 |
+
'Jopf;': '\U0001d541',
|
| 1104 |
+
'jopf;': '\U0001d55b',
|
| 1105 |
+
'Jscr;': '\U0001d4a5',
|
| 1106 |
+
'jscr;': '\U0001d4bf',
|
| 1107 |
+
'Jsercy;': '\u0408',
|
| 1108 |
+
'jsercy;': '\u0458',
|
| 1109 |
+
'Jukcy;': '\u0404',
|
| 1110 |
+
'jukcy;': '\u0454',
|
| 1111 |
+
'Kappa;': '\u039a',
|
| 1112 |
+
'kappa;': '\u03ba',
|
| 1113 |
+
'kappav;': '\u03f0',
|
| 1114 |
+
'Kcedil;': '\u0136',
|
| 1115 |
+
'kcedil;': '\u0137',
|
| 1116 |
+
'Kcy;': '\u041a',
|
| 1117 |
+
'kcy;': '\u043a',
|
| 1118 |
+
'Kfr;': '\U0001d50e',
|
| 1119 |
+
'kfr;': '\U0001d528',
|
| 1120 |
+
'kgreen;': '\u0138',
|
| 1121 |
+
'KHcy;': '\u0425',
|
| 1122 |
+
'khcy;': '\u0445',
|
| 1123 |
+
'KJcy;': '\u040c',
|
| 1124 |
+
'kjcy;': '\u045c',
|
| 1125 |
+
'Kopf;': '\U0001d542',
|
| 1126 |
+
'kopf;': '\U0001d55c',
|
| 1127 |
+
'Kscr;': '\U0001d4a6',
|
| 1128 |
+
'kscr;': '\U0001d4c0',
|
| 1129 |
+
'lAarr;': '\u21da',
|
| 1130 |
+
'Lacute;': '\u0139',
|
| 1131 |
+
'lacute;': '\u013a',
|
| 1132 |
+
'laemptyv;': '\u29b4',
|
| 1133 |
+
'lagran;': '\u2112',
|
| 1134 |
+
'Lambda;': '\u039b',
|
| 1135 |
+
'lambda;': '\u03bb',
|
| 1136 |
+
'Lang;': '\u27ea',
|
| 1137 |
+
'lang;': '\u27e8',
|
| 1138 |
+
'langd;': '\u2991',
|
| 1139 |
+
'langle;': '\u27e8',
|
| 1140 |
+
'lap;': '\u2a85',
|
| 1141 |
+
'Laplacetrf;': '\u2112',
|
| 1142 |
+
'laquo': '\xab',
|
| 1143 |
+
'laquo;': '\xab',
|
| 1144 |
+
'Larr;': '\u219e',
|
| 1145 |
+
'lArr;': '\u21d0',
|
| 1146 |
+
'larr;': '\u2190',
|
| 1147 |
+
'larrb;': '\u21e4',
|
| 1148 |
+
'larrbfs;': '\u291f',
|
| 1149 |
+
'larrfs;': '\u291d',
|
| 1150 |
+
'larrhk;': '\u21a9',
|
| 1151 |
+
'larrlp;': '\u21ab',
|
| 1152 |
+
'larrpl;': '\u2939',
|
| 1153 |
+
'larrsim;': '\u2973',
|
| 1154 |
+
'larrtl;': '\u21a2',
|
| 1155 |
+
'lat;': '\u2aab',
|
| 1156 |
+
'lAtail;': '\u291b',
|
| 1157 |
+
'latail;': '\u2919',
|
| 1158 |
+
'late;': '\u2aad',
|
| 1159 |
+
'lates;': '\u2aad\ufe00',
|
| 1160 |
+
'lBarr;': '\u290e',
|
| 1161 |
+
'lbarr;': '\u290c',
|
| 1162 |
+
'lbbrk;': '\u2772',
|
| 1163 |
+
'lbrace;': '{',
|
| 1164 |
+
'lbrack;': '[',
|
| 1165 |
+
'lbrke;': '\u298b',
|
| 1166 |
+
'lbrksld;': '\u298f',
|
| 1167 |
+
'lbrkslu;': '\u298d',
|
| 1168 |
+
'Lcaron;': '\u013d',
|
| 1169 |
+
'lcaron;': '\u013e',
|
| 1170 |
+
'Lcedil;': '\u013b',
|
| 1171 |
+
'lcedil;': '\u013c',
|
| 1172 |
+
'lceil;': '\u2308',
|
| 1173 |
+
'lcub;': '{',
|
| 1174 |
+
'Lcy;': '\u041b',
|
| 1175 |
+
'lcy;': '\u043b',
|
| 1176 |
+
'ldca;': '\u2936',
|
| 1177 |
+
'ldquo;': '\u201c',
|
| 1178 |
+
'ldquor;': '\u201e',
|
| 1179 |
+
'ldrdhar;': '\u2967',
|
| 1180 |
+
'ldrushar;': '\u294b',
|
| 1181 |
+
'ldsh;': '\u21b2',
|
| 1182 |
+
'lE;': '\u2266',
|
| 1183 |
+
'le;': '\u2264',
|
| 1184 |
+
'LeftAngleBracket;': '\u27e8',
|
| 1185 |
+
'LeftArrow;': '\u2190',
|
| 1186 |
+
'Leftarrow;': '\u21d0',
|
| 1187 |
+
'leftarrow;': '\u2190',
|
| 1188 |
+
'LeftArrowBar;': '\u21e4',
|
| 1189 |
+
'LeftArrowRightArrow;': '\u21c6',
|
| 1190 |
+
'leftarrowtail;': '\u21a2',
|
| 1191 |
+
'LeftCeiling;': '\u2308',
|
| 1192 |
+
'LeftDoubleBracket;': '\u27e6',
|
| 1193 |
+
'LeftDownTeeVector;': '\u2961',
|
| 1194 |
+
'LeftDownVector;': '\u21c3',
|
| 1195 |
+
'LeftDownVectorBar;': '\u2959',
|
| 1196 |
+
'LeftFloor;': '\u230a',
|
| 1197 |
+
'leftharpoondown;': '\u21bd',
|
| 1198 |
+
'leftharpoonup;': '\u21bc',
|
| 1199 |
+
'leftleftarrows;': '\u21c7',
|
| 1200 |
+
'LeftRightArrow;': '\u2194',
|
| 1201 |
+
'Leftrightarrow;': '\u21d4',
|
| 1202 |
+
'leftrightarrow;': '\u2194',
|
| 1203 |
+
'leftrightarrows;': '\u21c6',
|
| 1204 |
+
'leftrightharpoons;': '\u21cb',
|
| 1205 |
+
'leftrightsquigarrow;': '\u21ad',
|
| 1206 |
+
'LeftRightVector;': '\u294e',
|
| 1207 |
+
'LeftTee;': '\u22a3',
|
| 1208 |
+
'LeftTeeArrow;': '\u21a4',
|
| 1209 |
+
'LeftTeeVector;': '\u295a',
|
| 1210 |
+
'leftthreetimes;': '\u22cb',
|
| 1211 |
+
'LeftTriangle;': '\u22b2',
|
| 1212 |
+
'LeftTriangleBar;': '\u29cf',
|
| 1213 |
+
'LeftTriangleEqual;': '\u22b4',
|
| 1214 |
+
'LeftUpDownVector;': '\u2951',
|
| 1215 |
+
'LeftUpTeeVector;': '\u2960',
|
| 1216 |
+
'LeftUpVector;': '\u21bf',
|
| 1217 |
+
'LeftUpVectorBar;': '\u2958',
|
| 1218 |
+
'LeftVector;': '\u21bc',
|
| 1219 |
+
'LeftVectorBar;': '\u2952',
|
| 1220 |
+
'lEg;': '\u2a8b',
|
| 1221 |
+
'leg;': '\u22da',
|
| 1222 |
+
'leq;': '\u2264',
|
| 1223 |
+
'leqq;': '\u2266',
|
| 1224 |
+
'leqslant;': '\u2a7d',
|
| 1225 |
+
'les;': '\u2a7d',
|
| 1226 |
+
'lescc;': '\u2aa8',
|
| 1227 |
+
'lesdot;': '\u2a7f',
|
| 1228 |
+
'lesdoto;': '\u2a81',
|
| 1229 |
+
'lesdotor;': '\u2a83',
|
| 1230 |
+
'lesg;': '\u22da\ufe00',
|
| 1231 |
+
'lesges;': '\u2a93',
|
| 1232 |
+
'lessapprox;': '\u2a85',
|
| 1233 |
+
'lessdot;': '\u22d6',
|
| 1234 |
+
'lesseqgtr;': '\u22da',
|
| 1235 |
+
'lesseqqgtr;': '\u2a8b',
|
| 1236 |
+
'LessEqualGreater;': '\u22da',
|
| 1237 |
+
'LessFullEqual;': '\u2266',
|
| 1238 |
+
'LessGreater;': '\u2276',
|
| 1239 |
+
'lessgtr;': '\u2276',
|
| 1240 |
+
'LessLess;': '\u2aa1',
|
| 1241 |
+
'lesssim;': '\u2272',
|
| 1242 |
+
'LessSlantEqual;': '\u2a7d',
|
| 1243 |
+
'LessTilde;': '\u2272',
|
| 1244 |
+
'lfisht;': '\u297c',
|
| 1245 |
+
'lfloor;': '\u230a',
|
| 1246 |
+
'Lfr;': '\U0001d50f',
|
| 1247 |
+
'lfr;': '\U0001d529',
|
| 1248 |
+
'lg;': '\u2276',
|
| 1249 |
+
'lgE;': '\u2a91',
|
| 1250 |
+
'lHar;': '\u2962',
|
| 1251 |
+
'lhard;': '\u21bd',
|
| 1252 |
+
'lharu;': '\u21bc',
|
| 1253 |
+
'lharul;': '\u296a',
|
| 1254 |
+
'lhblk;': '\u2584',
|
| 1255 |
+
'LJcy;': '\u0409',
|
| 1256 |
+
'ljcy;': '\u0459',
|
| 1257 |
+
'Ll;': '\u22d8',
|
| 1258 |
+
'll;': '\u226a',
|
| 1259 |
+
'llarr;': '\u21c7',
|
| 1260 |
+
'llcorner;': '\u231e',
|
| 1261 |
+
'Lleftarrow;': '\u21da',
|
| 1262 |
+
'llhard;': '\u296b',
|
| 1263 |
+
'lltri;': '\u25fa',
|
| 1264 |
+
'Lmidot;': '\u013f',
|
| 1265 |
+
'lmidot;': '\u0140',
|
| 1266 |
+
'lmoust;': '\u23b0',
|
| 1267 |
+
'lmoustache;': '\u23b0',
|
| 1268 |
+
'lnap;': '\u2a89',
|
| 1269 |
+
'lnapprox;': '\u2a89',
|
| 1270 |
+
'lnE;': '\u2268',
|
| 1271 |
+
'lne;': '\u2a87',
|
| 1272 |
+
'lneq;': '\u2a87',
|
| 1273 |
+
'lneqq;': '\u2268',
|
| 1274 |
+
'lnsim;': '\u22e6',
|
| 1275 |
+
'loang;': '\u27ec',
|
| 1276 |
+
'loarr;': '\u21fd',
|
| 1277 |
+
'lobrk;': '\u27e6',
|
| 1278 |
+
'LongLeftArrow;': '\u27f5',
|
| 1279 |
+
'Longleftarrow;': '\u27f8',
|
| 1280 |
+
'longleftarrow;': '\u27f5',
|
| 1281 |
+
'LongLeftRightArrow;': '\u27f7',
|
| 1282 |
+
'Longleftrightarrow;': '\u27fa',
|
| 1283 |
+
'longleftrightarrow;': '\u27f7',
|
| 1284 |
+
'longmapsto;': '\u27fc',
|
| 1285 |
+
'LongRightArrow;': '\u27f6',
|
| 1286 |
+
'Longrightarrow;': '\u27f9',
|
| 1287 |
+
'longrightarrow;': '\u27f6',
|
| 1288 |
+
'looparrowleft;': '\u21ab',
|
| 1289 |
+
'looparrowright;': '\u21ac',
|
| 1290 |
+
'lopar;': '\u2985',
|
| 1291 |
+
'Lopf;': '\U0001d543',
|
| 1292 |
+
'lopf;': '\U0001d55d',
|
| 1293 |
+
'loplus;': '\u2a2d',
|
| 1294 |
+
'lotimes;': '\u2a34',
|
| 1295 |
+
'lowast;': '\u2217',
|
| 1296 |
+
'lowbar;': '_',
|
| 1297 |
+
'LowerLeftArrow;': '\u2199',
|
| 1298 |
+
'LowerRightArrow;': '\u2198',
|
| 1299 |
+
'loz;': '\u25ca',
|
| 1300 |
+
'lozenge;': '\u25ca',
|
| 1301 |
+
'lozf;': '\u29eb',
|
| 1302 |
+
'lpar;': '(',
|
| 1303 |
+
'lparlt;': '\u2993',
|
| 1304 |
+
'lrarr;': '\u21c6',
|
| 1305 |
+
'lrcorner;': '\u231f',
|
| 1306 |
+
'lrhar;': '\u21cb',
|
| 1307 |
+
'lrhard;': '\u296d',
|
| 1308 |
+
'lrm;': '\u200e',
|
| 1309 |
+
'lrtri;': '\u22bf',
|
| 1310 |
+
'lsaquo;': '\u2039',
|
| 1311 |
+
'Lscr;': '\u2112',
|
| 1312 |
+
'lscr;': '\U0001d4c1',
|
| 1313 |
+
'Lsh;': '\u21b0',
|
| 1314 |
+
'lsh;': '\u21b0',
|
| 1315 |
+
'lsim;': '\u2272',
|
| 1316 |
+
'lsime;': '\u2a8d',
|
| 1317 |
+
'lsimg;': '\u2a8f',
|
| 1318 |
+
'lsqb;': '[',
|
| 1319 |
+
'lsquo;': '\u2018',
|
| 1320 |
+
'lsquor;': '\u201a',
|
| 1321 |
+
'Lstrok;': '\u0141',
|
| 1322 |
+
'lstrok;': '\u0142',
|
| 1323 |
+
'LT': '<',
|
| 1324 |
+
'lt': '<',
|
| 1325 |
+
'LT;': '<',
|
| 1326 |
+
'Lt;': '\u226a',
|
| 1327 |
+
'lt;': '<',
|
| 1328 |
+
'ltcc;': '\u2aa6',
|
| 1329 |
+
'ltcir;': '\u2a79',
|
| 1330 |
+
'ltdot;': '\u22d6',
|
| 1331 |
+
'lthree;': '\u22cb',
|
| 1332 |
+
'ltimes;': '\u22c9',
|
| 1333 |
+
'ltlarr;': '\u2976',
|
| 1334 |
+
'ltquest;': '\u2a7b',
|
| 1335 |
+
'ltri;': '\u25c3',
|
| 1336 |
+
'ltrie;': '\u22b4',
|
| 1337 |
+
'ltrif;': '\u25c2',
|
| 1338 |
+
'ltrPar;': '\u2996',
|
| 1339 |
+
'lurdshar;': '\u294a',
|
| 1340 |
+
'luruhar;': '\u2966',
|
| 1341 |
+
'lvertneqq;': '\u2268\ufe00',
|
| 1342 |
+
'lvnE;': '\u2268\ufe00',
|
| 1343 |
+
'macr': '\xaf',
|
| 1344 |
+
'macr;': '\xaf',
|
| 1345 |
+
'male;': '\u2642',
|
| 1346 |
+
'malt;': '\u2720',
|
| 1347 |
+
'maltese;': '\u2720',
|
| 1348 |
+
'Map;': '\u2905',
|
| 1349 |
+
'map;': '\u21a6',
|
| 1350 |
+
'mapsto;': '\u21a6',
|
| 1351 |
+
'mapstodown;': '\u21a7',
|
| 1352 |
+
'mapstoleft;': '\u21a4',
|
| 1353 |
+
'mapstoup;': '\u21a5',
|
| 1354 |
+
'marker;': '\u25ae',
|
| 1355 |
+
'mcomma;': '\u2a29',
|
| 1356 |
+
'Mcy;': '\u041c',
|
| 1357 |
+
'mcy;': '\u043c',
|
| 1358 |
+
'mdash;': '\u2014',
|
| 1359 |
+
'mDDot;': '\u223a',
|
| 1360 |
+
'measuredangle;': '\u2221',
|
| 1361 |
+
'MediumSpace;': '\u205f',
|
| 1362 |
+
'Mellintrf;': '\u2133',
|
| 1363 |
+
'Mfr;': '\U0001d510',
|
| 1364 |
+
'mfr;': '\U0001d52a',
|
| 1365 |
+
'mho;': '\u2127',
|
| 1366 |
+
'micro': '\xb5',
|
| 1367 |
+
'micro;': '\xb5',
|
| 1368 |
+
'mid;': '\u2223',
|
| 1369 |
+
'midast;': '*',
|
| 1370 |
+
'midcir;': '\u2af0',
|
| 1371 |
+
'middot': '\xb7',
|
| 1372 |
+
'middot;': '\xb7',
|
| 1373 |
+
'minus;': '\u2212',
|
| 1374 |
+
'minusb;': '\u229f',
|
| 1375 |
+
'minusd;': '\u2238',
|
| 1376 |
+
'minusdu;': '\u2a2a',
|
| 1377 |
+
'MinusPlus;': '\u2213',
|
| 1378 |
+
'mlcp;': '\u2adb',
|
| 1379 |
+
'mldr;': '\u2026',
|
| 1380 |
+
'mnplus;': '\u2213',
|
| 1381 |
+
'models;': '\u22a7',
|
| 1382 |
+
'Mopf;': '\U0001d544',
|
| 1383 |
+
'mopf;': '\U0001d55e',
|
| 1384 |
+
'mp;': '\u2213',
|
| 1385 |
+
'Mscr;': '\u2133',
|
| 1386 |
+
'mscr;': '\U0001d4c2',
|
| 1387 |
+
'mstpos;': '\u223e',
|
| 1388 |
+
'Mu;': '\u039c',
|
| 1389 |
+
'mu;': '\u03bc',
|
| 1390 |
+
'multimap;': '\u22b8',
|
| 1391 |
+
'mumap;': '\u22b8',
|
| 1392 |
+
'nabla;': '\u2207',
|
| 1393 |
+
'Nacute;': '\u0143',
|
| 1394 |
+
'nacute;': '\u0144',
|
| 1395 |
+
'nang;': '\u2220\u20d2',
|
| 1396 |
+
'nap;': '\u2249',
|
| 1397 |
+
'napE;': '\u2a70\u0338',
|
| 1398 |
+
'napid;': '\u224b\u0338',
|
| 1399 |
+
'napos;': '\u0149',
|
| 1400 |
+
'napprox;': '\u2249',
|
| 1401 |
+
'natur;': '\u266e',
|
| 1402 |
+
'natural;': '\u266e',
|
| 1403 |
+
'naturals;': '\u2115',
|
| 1404 |
+
'nbsp': '\xa0',
|
| 1405 |
+
'nbsp;': '\xa0',
|
| 1406 |
+
'nbump;': '\u224e\u0338',
|
| 1407 |
+
'nbumpe;': '\u224f\u0338',
|
| 1408 |
+
'ncap;': '\u2a43',
|
| 1409 |
+
'Ncaron;': '\u0147',
|
| 1410 |
+
'ncaron;': '\u0148',
|
| 1411 |
+
'Ncedil;': '\u0145',
|
| 1412 |
+
'ncedil;': '\u0146',
|
| 1413 |
+
'ncong;': '\u2247',
|
| 1414 |
+
'ncongdot;': '\u2a6d\u0338',
|
| 1415 |
+
'ncup;': '\u2a42',
|
| 1416 |
+
'Ncy;': '\u041d',
|
| 1417 |
+
'ncy;': '\u043d',
|
| 1418 |
+
'ndash;': '\u2013',
|
| 1419 |
+
'ne;': '\u2260',
|
| 1420 |
+
'nearhk;': '\u2924',
|
| 1421 |
+
'neArr;': '\u21d7',
|
| 1422 |
+
'nearr;': '\u2197',
|
| 1423 |
+
'nearrow;': '\u2197',
|
| 1424 |
+
'nedot;': '\u2250\u0338',
|
| 1425 |
+
'NegativeMediumSpace;': '\u200b',
|
| 1426 |
+
'NegativeThickSpace;': '\u200b',
|
| 1427 |
+
'NegativeThinSpace;': '\u200b',
|
| 1428 |
+
'NegativeVeryThinSpace;': '\u200b',
|
| 1429 |
+
'nequiv;': '\u2262',
|
| 1430 |
+
'nesear;': '\u2928',
|
| 1431 |
+
'nesim;': '\u2242\u0338',
|
| 1432 |
+
'NestedGreaterGreater;': '\u226b',
|
| 1433 |
+
'NestedLessLess;': '\u226a',
|
| 1434 |
+
'NewLine;': '\n',
|
| 1435 |
+
'nexist;': '\u2204',
|
| 1436 |
+
'nexists;': '\u2204',
|
| 1437 |
+
'Nfr;': '\U0001d511',
|
| 1438 |
+
'nfr;': '\U0001d52b',
|
| 1439 |
+
'ngE;': '\u2267\u0338',
|
| 1440 |
+
'nge;': '\u2271',
|
| 1441 |
+
'ngeq;': '\u2271',
|
| 1442 |
+
'ngeqq;': '\u2267\u0338',
|
| 1443 |
+
'ngeqslant;': '\u2a7e\u0338',
|
| 1444 |
+
'nges;': '\u2a7e\u0338',
|
| 1445 |
+
'nGg;': '\u22d9\u0338',
|
| 1446 |
+
'ngsim;': '\u2275',
|
| 1447 |
+
'nGt;': '\u226b\u20d2',
|
| 1448 |
+
'ngt;': '\u226f',
|
| 1449 |
+
'ngtr;': '\u226f',
|
| 1450 |
+
'nGtv;': '\u226b\u0338',
|
| 1451 |
+
'nhArr;': '\u21ce',
|
| 1452 |
+
'nharr;': '\u21ae',
|
| 1453 |
+
'nhpar;': '\u2af2',
|
| 1454 |
+
'ni;': '\u220b',
|
| 1455 |
+
'nis;': '\u22fc',
|
| 1456 |
+
'nisd;': '\u22fa',
|
| 1457 |
+
'niv;': '\u220b',
|
| 1458 |
+
'NJcy;': '\u040a',
|
| 1459 |
+
'njcy;': '\u045a',
|
| 1460 |
+
'nlArr;': '\u21cd',
|
| 1461 |
+
'nlarr;': '\u219a',
|
| 1462 |
+
'nldr;': '\u2025',
|
| 1463 |
+
'nlE;': '\u2266\u0338',
|
| 1464 |
+
'nle;': '\u2270',
|
| 1465 |
+
'nLeftarrow;': '\u21cd',
|
| 1466 |
+
'nleftarrow;': '\u219a',
|
| 1467 |
+
'nLeftrightarrow;': '\u21ce',
|
| 1468 |
+
'nleftrightarrow;': '\u21ae',
|
| 1469 |
+
'nleq;': '\u2270',
|
| 1470 |
+
'nleqq;': '\u2266\u0338',
|
| 1471 |
+
'nleqslant;': '\u2a7d\u0338',
|
| 1472 |
+
'nles;': '\u2a7d\u0338',
|
| 1473 |
+
'nless;': '\u226e',
|
| 1474 |
+
'nLl;': '\u22d8\u0338',
|
| 1475 |
+
'nlsim;': '\u2274',
|
| 1476 |
+
'nLt;': '\u226a\u20d2',
|
| 1477 |
+
'nlt;': '\u226e',
|
| 1478 |
+
'nltri;': '\u22ea',
|
| 1479 |
+
'nltrie;': '\u22ec',
|
| 1480 |
+
'nLtv;': '\u226a\u0338',
|
| 1481 |
+
'nmid;': '\u2224',
|
| 1482 |
+
'NoBreak;': '\u2060',
|
| 1483 |
+
'NonBreakingSpace;': '\xa0',
|
| 1484 |
+
'Nopf;': '\u2115',
|
| 1485 |
+
'nopf;': '\U0001d55f',
|
| 1486 |
+
'not': '\xac',
|
| 1487 |
+
'Not;': '\u2aec',
|
| 1488 |
+
'not;': '\xac',
|
| 1489 |
+
'NotCongruent;': '\u2262',
|
| 1490 |
+
'NotCupCap;': '\u226d',
|
| 1491 |
+
'NotDoubleVerticalBar;': '\u2226',
|
| 1492 |
+
'NotElement;': '\u2209',
|
| 1493 |
+
'NotEqual;': '\u2260',
|
| 1494 |
+
'NotEqualTilde;': '\u2242\u0338',
|
| 1495 |
+
'NotExists;': '\u2204',
|
| 1496 |
+
'NotGreater;': '\u226f',
|
| 1497 |
+
'NotGreaterEqual;': '\u2271',
|
| 1498 |
+
'NotGreaterFullEqual;': '\u2267\u0338',
|
| 1499 |
+
'NotGreaterGreater;': '\u226b\u0338',
|
| 1500 |
+
'NotGreaterLess;': '\u2279',
|
| 1501 |
+
'NotGreaterSlantEqual;': '\u2a7e\u0338',
|
| 1502 |
+
'NotGreaterTilde;': '\u2275',
|
| 1503 |
+
'NotHumpDownHump;': '\u224e\u0338',
|
| 1504 |
+
'NotHumpEqual;': '\u224f\u0338',
|
| 1505 |
+
'notin;': '\u2209',
|
| 1506 |
+
'notindot;': '\u22f5\u0338',
|
| 1507 |
+
'notinE;': '\u22f9\u0338',
|
| 1508 |
+
'notinva;': '\u2209',
|
| 1509 |
+
'notinvb;': '\u22f7',
|
| 1510 |
+
'notinvc;': '\u22f6',
|
| 1511 |
+
'NotLeftTriangle;': '\u22ea',
|
| 1512 |
+
'NotLeftTriangleBar;': '\u29cf\u0338',
|
| 1513 |
+
'NotLeftTriangleEqual;': '\u22ec',
|
| 1514 |
+
'NotLess;': '\u226e',
|
| 1515 |
+
'NotLessEqual;': '\u2270',
|
| 1516 |
+
'NotLessGreater;': '\u2278',
|
| 1517 |
+
'NotLessLess;': '\u226a\u0338',
|
| 1518 |
+
'NotLessSlantEqual;': '\u2a7d\u0338',
|
| 1519 |
+
'NotLessTilde;': '\u2274',
|
| 1520 |
+
'NotNestedGreaterGreater;': '\u2aa2\u0338',
|
| 1521 |
+
'NotNestedLessLess;': '\u2aa1\u0338',
|
| 1522 |
+
'notni;': '\u220c',
|
| 1523 |
+
'notniva;': '\u220c',
|
| 1524 |
+
'notnivb;': '\u22fe',
|
| 1525 |
+
'notnivc;': '\u22fd',
|
| 1526 |
+
'NotPrecedes;': '\u2280',
|
| 1527 |
+
'NotPrecedesEqual;': '\u2aaf\u0338',
|
| 1528 |
+
'NotPrecedesSlantEqual;': '\u22e0',
|
| 1529 |
+
'NotReverseElement;': '\u220c',
|
| 1530 |
+
'NotRightTriangle;': '\u22eb',
|
| 1531 |
+
'NotRightTriangleBar;': '\u29d0\u0338',
|
| 1532 |
+
'NotRightTriangleEqual;': '\u22ed',
|
| 1533 |
+
'NotSquareSubset;': '\u228f\u0338',
|
| 1534 |
+
'NotSquareSubsetEqual;': '\u22e2',
|
| 1535 |
+
'NotSquareSuperset;': '\u2290\u0338',
|
| 1536 |
+
'NotSquareSupersetEqual;': '\u22e3',
|
| 1537 |
+
'NotSubset;': '\u2282\u20d2',
|
| 1538 |
+
'NotSubsetEqual;': '\u2288',
|
| 1539 |
+
'NotSucceeds;': '\u2281',
|
| 1540 |
+
'NotSucceedsEqual;': '\u2ab0\u0338',
|
| 1541 |
+
'NotSucceedsSlantEqual;': '\u22e1',
|
| 1542 |
+
'NotSucceedsTilde;': '\u227f\u0338',
|
| 1543 |
+
'NotSuperset;': '\u2283\u20d2',
|
| 1544 |
+
'NotSupersetEqual;': '\u2289',
|
| 1545 |
+
'NotTilde;': '\u2241',
|
| 1546 |
+
'NotTildeEqual;': '\u2244',
|
| 1547 |
+
'NotTildeFullEqual;': '\u2247',
|
| 1548 |
+
'NotTildeTilde;': '\u2249',
|
| 1549 |
+
'NotVerticalBar;': '\u2224',
|
| 1550 |
+
'npar;': '\u2226',
|
| 1551 |
+
'nparallel;': '\u2226',
|
| 1552 |
+
'nparsl;': '\u2afd\u20e5',
|
| 1553 |
+
'npart;': '\u2202\u0338',
|
| 1554 |
+
'npolint;': '\u2a14',
|
| 1555 |
+
'npr;': '\u2280',
|
| 1556 |
+
'nprcue;': '\u22e0',
|
| 1557 |
+
'npre;': '\u2aaf\u0338',
|
| 1558 |
+
'nprec;': '\u2280',
|
| 1559 |
+
'npreceq;': '\u2aaf\u0338',
|
| 1560 |
+
'nrArr;': '\u21cf',
|
| 1561 |
+
'nrarr;': '\u219b',
|
| 1562 |
+
'nrarrc;': '\u2933\u0338',
|
| 1563 |
+
'nrarrw;': '\u219d\u0338',
|
| 1564 |
+
'nRightarrow;': '\u21cf',
|
| 1565 |
+
'nrightarrow;': '\u219b',
|
| 1566 |
+
'nrtri;': '\u22eb',
|
| 1567 |
+
'nrtrie;': '\u22ed',
|
| 1568 |
+
'nsc;': '\u2281',
|
| 1569 |
+
'nsccue;': '\u22e1',
|
| 1570 |
+
'nsce;': '\u2ab0\u0338',
|
| 1571 |
+
'Nscr;': '\U0001d4a9',
|
| 1572 |
+
'nscr;': '\U0001d4c3',
|
| 1573 |
+
'nshortmid;': '\u2224',
|
| 1574 |
+
'nshortparallel;': '\u2226',
|
| 1575 |
+
'nsim;': '\u2241',
|
| 1576 |
+
'nsime;': '\u2244',
|
| 1577 |
+
'nsimeq;': '\u2244',
|
| 1578 |
+
'nsmid;': '\u2224',
|
| 1579 |
+
'nspar;': '\u2226',
|
| 1580 |
+
'nsqsube;': '\u22e2',
|
| 1581 |
+
'nsqsupe;': '\u22e3',
|
| 1582 |
+
'nsub;': '\u2284',
|
| 1583 |
+
'nsubE;': '\u2ac5\u0338',
|
| 1584 |
+
'nsube;': '\u2288',
|
| 1585 |
+
'nsubset;': '\u2282\u20d2',
|
| 1586 |
+
'nsubseteq;': '\u2288',
|
| 1587 |
+
'nsubseteqq;': '\u2ac5\u0338',
|
| 1588 |
+
'nsucc;': '\u2281',
|
| 1589 |
+
'nsucceq;': '\u2ab0\u0338',
|
| 1590 |
+
'nsup;': '\u2285',
|
| 1591 |
+
'nsupE;': '\u2ac6\u0338',
|
| 1592 |
+
'nsupe;': '\u2289',
|
| 1593 |
+
'nsupset;': '\u2283\u20d2',
|
| 1594 |
+
'nsupseteq;': '\u2289',
|
| 1595 |
+
'nsupseteqq;': '\u2ac6\u0338',
|
| 1596 |
+
'ntgl;': '\u2279',
|
| 1597 |
+
'Ntilde': '\xd1',
|
| 1598 |
+
'ntilde': '\xf1',
|
| 1599 |
+
'Ntilde;': '\xd1',
|
| 1600 |
+
'ntilde;': '\xf1',
|
| 1601 |
+
'ntlg;': '\u2278',
|
| 1602 |
+
'ntriangleleft;': '\u22ea',
|
| 1603 |
+
'ntrianglelefteq;': '\u22ec',
|
| 1604 |
+
'ntriangleright;': '\u22eb',
|
| 1605 |
+
'ntrianglerighteq;': '\u22ed',
|
| 1606 |
+
'Nu;': '\u039d',
|
| 1607 |
+
'nu;': '\u03bd',
|
| 1608 |
+
'num;': '#',
|
| 1609 |
+
'numero;': '\u2116',
|
| 1610 |
+
'numsp;': '\u2007',
|
| 1611 |
+
'nvap;': '\u224d\u20d2',
|
| 1612 |
+
'nVDash;': '\u22af',
|
| 1613 |
+
'nVdash;': '\u22ae',
|
| 1614 |
+
'nvDash;': '\u22ad',
|
| 1615 |
+
'nvdash;': '\u22ac',
|
| 1616 |
+
'nvge;': '\u2265\u20d2',
|
| 1617 |
+
'nvgt;': '>\u20d2',
|
| 1618 |
+
'nvHarr;': '\u2904',
|
| 1619 |
+
'nvinfin;': '\u29de',
|
| 1620 |
+
'nvlArr;': '\u2902',
|
| 1621 |
+
'nvle;': '\u2264\u20d2',
|
| 1622 |
+
'nvlt;': '<\u20d2',
|
| 1623 |
+
'nvltrie;': '\u22b4\u20d2',
|
| 1624 |
+
'nvrArr;': '\u2903',
|
| 1625 |
+
'nvrtrie;': '\u22b5\u20d2',
|
| 1626 |
+
'nvsim;': '\u223c\u20d2',
|
| 1627 |
+
'nwarhk;': '\u2923',
|
| 1628 |
+
'nwArr;': '\u21d6',
|
| 1629 |
+
'nwarr;': '\u2196',
|
| 1630 |
+
'nwarrow;': '\u2196',
|
| 1631 |
+
'nwnear;': '\u2927',
|
| 1632 |
+
'Oacute': '\xd3',
|
| 1633 |
+
'oacute': '\xf3',
|
| 1634 |
+
'Oacute;': '\xd3',
|
| 1635 |
+
'oacute;': '\xf3',
|
| 1636 |
+
'oast;': '\u229b',
|
| 1637 |
+
'ocir;': '\u229a',
|
| 1638 |
+
'Ocirc': '\xd4',
|
| 1639 |
+
'ocirc': '\xf4',
|
| 1640 |
+
'Ocirc;': '\xd4',
|
| 1641 |
+
'ocirc;': '\xf4',
|
| 1642 |
+
'Ocy;': '\u041e',
|
| 1643 |
+
'ocy;': '\u043e',
|
| 1644 |
+
'odash;': '\u229d',
|
| 1645 |
+
'Odblac;': '\u0150',
|
| 1646 |
+
'odblac;': '\u0151',
|
| 1647 |
+
'odiv;': '\u2a38',
|
| 1648 |
+
'odot;': '\u2299',
|
| 1649 |
+
'odsold;': '\u29bc',
|
| 1650 |
+
'OElig;': '\u0152',
|
| 1651 |
+
'oelig;': '\u0153',
|
| 1652 |
+
'ofcir;': '\u29bf',
|
| 1653 |
+
'Ofr;': '\U0001d512',
|
| 1654 |
+
'ofr;': '\U0001d52c',
|
| 1655 |
+
'ogon;': '\u02db',
|
| 1656 |
+
'Ograve': '\xd2',
|
| 1657 |
+
'ograve': '\xf2',
|
| 1658 |
+
'Ograve;': '\xd2',
|
| 1659 |
+
'ograve;': '\xf2',
|
| 1660 |
+
'ogt;': '\u29c1',
|
| 1661 |
+
'ohbar;': '\u29b5',
|
| 1662 |
+
'ohm;': '\u03a9',
|
| 1663 |
+
'oint;': '\u222e',
|
| 1664 |
+
'olarr;': '\u21ba',
|
| 1665 |
+
'olcir;': '\u29be',
|
| 1666 |
+
'olcross;': '\u29bb',
|
| 1667 |
+
'oline;': '\u203e',
|
| 1668 |
+
'olt;': '\u29c0',
|
| 1669 |
+
'Omacr;': '\u014c',
|
| 1670 |
+
'omacr;': '\u014d',
|
| 1671 |
+
'Omega;': '\u03a9',
|
| 1672 |
+
'omega;': '\u03c9',
|
| 1673 |
+
'Omicron;': '\u039f',
|
| 1674 |
+
'omicron;': '\u03bf',
|
| 1675 |
+
'omid;': '\u29b6',
|
| 1676 |
+
'ominus;': '\u2296',
|
| 1677 |
+
'Oopf;': '\U0001d546',
|
| 1678 |
+
'oopf;': '\U0001d560',
|
| 1679 |
+
'opar;': '\u29b7',
|
| 1680 |
+
'OpenCurlyDoubleQuote;': '\u201c',
|
| 1681 |
+
'OpenCurlyQuote;': '\u2018',
|
| 1682 |
+
'operp;': '\u29b9',
|
| 1683 |
+
'oplus;': '\u2295',
|
| 1684 |
+
'Or;': '\u2a54',
|
| 1685 |
+
'or;': '\u2228',
|
| 1686 |
+
'orarr;': '\u21bb',
|
| 1687 |
+
'ord;': '\u2a5d',
|
| 1688 |
+
'order;': '\u2134',
|
| 1689 |
+
'orderof;': '\u2134',
|
| 1690 |
+
'ordf': '\xaa',
|
| 1691 |
+
'ordf;': '\xaa',
|
| 1692 |
+
'ordm': '\xba',
|
| 1693 |
+
'ordm;': '\xba',
|
| 1694 |
+
'origof;': '\u22b6',
|
| 1695 |
+
'oror;': '\u2a56',
|
| 1696 |
+
'orslope;': '\u2a57',
|
| 1697 |
+
'orv;': '\u2a5b',
|
| 1698 |
+
'oS;': '\u24c8',
|
| 1699 |
+
'Oscr;': '\U0001d4aa',
|
| 1700 |
+
'oscr;': '\u2134',
|
| 1701 |
+
'Oslash': '\xd8',
|
| 1702 |
+
'oslash': '\xf8',
|
| 1703 |
+
'Oslash;': '\xd8',
|
| 1704 |
+
'oslash;': '\xf8',
|
| 1705 |
+
'osol;': '\u2298',
|
| 1706 |
+
'Otilde': '\xd5',
|
| 1707 |
+
'otilde': '\xf5',
|
| 1708 |
+
'Otilde;': '\xd5',
|
| 1709 |
+
'otilde;': '\xf5',
|
| 1710 |
+
'Otimes;': '\u2a37',
|
| 1711 |
+
'otimes;': '\u2297',
|
| 1712 |
+
'otimesas;': '\u2a36',
|
| 1713 |
+
'Ouml': '\xd6',
|
| 1714 |
+
'ouml': '\xf6',
|
| 1715 |
+
'Ouml;': '\xd6',
|
| 1716 |
+
'ouml;': '\xf6',
|
| 1717 |
+
'ovbar;': '\u233d',
|
| 1718 |
+
'OverBar;': '\u203e',
|
| 1719 |
+
'OverBrace;': '\u23de',
|
| 1720 |
+
'OverBracket;': '\u23b4',
|
| 1721 |
+
'OverParenthesis;': '\u23dc',
|
| 1722 |
+
'par;': '\u2225',
|
| 1723 |
+
'para': '\xb6',
|
| 1724 |
+
'para;': '\xb6',
|
| 1725 |
+
'parallel;': '\u2225',
|
| 1726 |
+
'parsim;': '\u2af3',
|
| 1727 |
+
'parsl;': '\u2afd',
|
| 1728 |
+
'part;': '\u2202',
|
| 1729 |
+
'PartialD;': '\u2202',
|
| 1730 |
+
'Pcy;': '\u041f',
|
| 1731 |
+
'pcy;': '\u043f',
|
| 1732 |
+
'percnt;': '%',
|
| 1733 |
+
'period;': '.',
|
| 1734 |
+
'permil;': '\u2030',
|
| 1735 |
+
'perp;': '\u22a5',
|
| 1736 |
+
'pertenk;': '\u2031',
|
| 1737 |
+
'Pfr;': '\U0001d513',
|
| 1738 |
+
'pfr;': '\U0001d52d',
|
| 1739 |
+
'Phi;': '\u03a6',
|
| 1740 |
+
'phi;': '\u03c6',
|
| 1741 |
+
'phiv;': '\u03d5',
|
| 1742 |
+
'phmmat;': '\u2133',
|
| 1743 |
+
'phone;': '\u260e',
|
| 1744 |
+
'Pi;': '\u03a0',
|
| 1745 |
+
'pi;': '\u03c0',
|
| 1746 |
+
'pitchfork;': '\u22d4',
|
| 1747 |
+
'piv;': '\u03d6',
|
| 1748 |
+
'planck;': '\u210f',
|
| 1749 |
+
'planckh;': '\u210e',
|
| 1750 |
+
'plankv;': '\u210f',
|
| 1751 |
+
'plus;': '+',
|
| 1752 |
+
'plusacir;': '\u2a23',
|
| 1753 |
+
'plusb;': '\u229e',
|
| 1754 |
+
'pluscir;': '\u2a22',
|
| 1755 |
+
'plusdo;': '\u2214',
|
| 1756 |
+
'plusdu;': '\u2a25',
|
| 1757 |
+
'pluse;': '\u2a72',
|
| 1758 |
+
'PlusMinus;': '\xb1',
|
| 1759 |
+
'plusmn': '\xb1',
|
| 1760 |
+
'plusmn;': '\xb1',
|
| 1761 |
+
'plussim;': '\u2a26',
|
| 1762 |
+
'plustwo;': '\u2a27',
|
| 1763 |
+
'pm;': '\xb1',
|
| 1764 |
+
'Poincareplane;': '\u210c',
|
| 1765 |
+
'pointint;': '\u2a15',
|
| 1766 |
+
'Popf;': '\u2119',
|
| 1767 |
+
'popf;': '\U0001d561',
|
| 1768 |
+
'pound': '\xa3',
|
| 1769 |
+
'pound;': '\xa3',
|
| 1770 |
+
'Pr;': '\u2abb',
|
| 1771 |
+
'pr;': '\u227a',
|
| 1772 |
+
'prap;': '\u2ab7',
|
| 1773 |
+
'prcue;': '\u227c',
|
| 1774 |
+
'prE;': '\u2ab3',
|
| 1775 |
+
'pre;': '\u2aaf',
|
| 1776 |
+
'prec;': '\u227a',
|
| 1777 |
+
'precapprox;': '\u2ab7',
|
| 1778 |
+
'preccurlyeq;': '\u227c',
|
| 1779 |
+
'Precedes;': '\u227a',
|
| 1780 |
+
'PrecedesEqual;': '\u2aaf',
|
| 1781 |
+
'PrecedesSlantEqual;': '\u227c',
|
| 1782 |
+
'PrecedesTilde;': '\u227e',
|
| 1783 |
+
'preceq;': '\u2aaf',
|
| 1784 |
+
'precnapprox;': '\u2ab9',
|
| 1785 |
+
'precneqq;': '\u2ab5',
|
| 1786 |
+
'precnsim;': '\u22e8',
|
| 1787 |
+
'precsim;': '\u227e',
|
| 1788 |
+
'Prime;': '\u2033',
|
| 1789 |
+
'prime;': '\u2032',
|
| 1790 |
+
'primes;': '\u2119',
|
| 1791 |
+
'prnap;': '\u2ab9',
|
| 1792 |
+
'prnE;': '\u2ab5',
|
| 1793 |
+
'prnsim;': '\u22e8',
|
| 1794 |
+
'prod;': '\u220f',
|
| 1795 |
+
'Product;': '\u220f',
|
| 1796 |
+
'profalar;': '\u232e',
|
| 1797 |
+
'profline;': '\u2312',
|
| 1798 |
+
'profsurf;': '\u2313',
|
| 1799 |
+
'prop;': '\u221d',
|
| 1800 |
+
'Proportion;': '\u2237',
|
| 1801 |
+
'Proportional;': '\u221d',
|
| 1802 |
+
'propto;': '\u221d',
|
| 1803 |
+
'prsim;': '\u227e',
|
| 1804 |
+
'prurel;': '\u22b0',
|
| 1805 |
+
'Pscr;': '\U0001d4ab',
|
| 1806 |
+
'pscr;': '\U0001d4c5',
|
| 1807 |
+
'Psi;': '\u03a8',
|
| 1808 |
+
'psi;': '\u03c8',
|
| 1809 |
+
'puncsp;': '\u2008',
|
| 1810 |
+
'Qfr;': '\U0001d514',
|
| 1811 |
+
'qfr;': '\U0001d52e',
|
| 1812 |
+
'qint;': '\u2a0c',
|
| 1813 |
+
'Qopf;': '\u211a',
|
| 1814 |
+
'qopf;': '\U0001d562',
|
| 1815 |
+
'qprime;': '\u2057',
|
| 1816 |
+
'Qscr;': '\U0001d4ac',
|
| 1817 |
+
'qscr;': '\U0001d4c6',
|
| 1818 |
+
'quaternions;': '\u210d',
|
| 1819 |
+
'quatint;': '\u2a16',
|
| 1820 |
+
'quest;': '?',
|
| 1821 |
+
'questeq;': '\u225f',
|
| 1822 |
+
'QUOT': '"',
|
| 1823 |
+
'quot': '"',
|
| 1824 |
+
'QUOT;': '"',
|
| 1825 |
+
'quot;': '"',
|
| 1826 |
+
'rAarr;': '\u21db',
|
| 1827 |
+
'race;': '\u223d\u0331',
|
| 1828 |
+
'Racute;': '\u0154',
|
| 1829 |
+
'racute;': '\u0155',
|
| 1830 |
+
'radic;': '\u221a',
|
| 1831 |
+
'raemptyv;': '\u29b3',
|
| 1832 |
+
'Rang;': '\u27eb',
|
| 1833 |
+
'rang;': '\u27e9',
|
| 1834 |
+
'rangd;': '\u2992',
|
| 1835 |
+
'range;': '\u29a5',
|
| 1836 |
+
'rangle;': '\u27e9',
|
| 1837 |
+
'raquo': '\xbb',
|
| 1838 |
+
'raquo;': '\xbb',
|
| 1839 |
+
'Rarr;': '\u21a0',
|
| 1840 |
+
'rArr;': '\u21d2',
|
| 1841 |
+
'rarr;': '\u2192',
|
| 1842 |
+
'rarrap;': '\u2975',
|
| 1843 |
+
'rarrb;': '\u21e5',
|
| 1844 |
+
'rarrbfs;': '\u2920',
|
| 1845 |
+
'rarrc;': '\u2933',
|
| 1846 |
+
'rarrfs;': '\u291e',
|
| 1847 |
+
'rarrhk;': '\u21aa',
|
| 1848 |
+
'rarrlp;': '\u21ac',
|
| 1849 |
+
'rarrpl;': '\u2945',
|
| 1850 |
+
'rarrsim;': '\u2974',
|
| 1851 |
+
'Rarrtl;': '\u2916',
|
| 1852 |
+
'rarrtl;': '\u21a3',
|
| 1853 |
+
'rarrw;': '\u219d',
|
| 1854 |
+
'rAtail;': '\u291c',
|
| 1855 |
+
'ratail;': '\u291a',
|
| 1856 |
+
'ratio;': '\u2236',
|
| 1857 |
+
'rationals;': '\u211a',
|
| 1858 |
+
'RBarr;': '\u2910',
|
| 1859 |
+
'rBarr;': '\u290f',
|
| 1860 |
+
'rbarr;': '\u290d',
|
| 1861 |
+
'rbbrk;': '\u2773',
|
| 1862 |
+
'rbrace;': '}',
|
| 1863 |
+
'rbrack;': ']',
|
| 1864 |
+
'rbrke;': '\u298c',
|
| 1865 |
+
'rbrksld;': '\u298e',
|
| 1866 |
+
'rbrkslu;': '\u2990',
|
| 1867 |
+
'Rcaron;': '\u0158',
|
| 1868 |
+
'rcaron;': '\u0159',
|
| 1869 |
+
'Rcedil;': '\u0156',
|
| 1870 |
+
'rcedil;': '\u0157',
|
| 1871 |
+
'rceil;': '\u2309',
|
| 1872 |
+
'rcub;': '}',
|
| 1873 |
+
'Rcy;': '\u0420',
|
| 1874 |
+
'rcy;': '\u0440',
|
| 1875 |
+
'rdca;': '\u2937',
|
| 1876 |
+
'rdldhar;': '\u2969',
|
| 1877 |
+
'rdquo;': '\u201d',
|
| 1878 |
+
'rdquor;': '\u201d',
|
| 1879 |
+
'rdsh;': '\u21b3',
|
| 1880 |
+
'Re;': '\u211c',
|
| 1881 |
+
'real;': '\u211c',
|
| 1882 |
+
'realine;': '\u211b',
|
| 1883 |
+
'realpart;': '\u211c',
|
| 1884 |
+
'reals;': '\u211d',
|
| 1885 |
+
'rect;': '\u25ad',
|
| 1886 |
+
'REG': '\xae',
|
| 1887 |
+
'reg': '\xae',
|
| 1888 |
+
'REG;': '\xae',
|
| 1889 |
+
'reg;': '\xae',
|
| 1890 |
+
'ReverseElement;': '\u220b',
|
| 1891 |
+
'ReverseEquilibrium;': '\u21cb',
|
| 1892 |
+
'ReverseUpEquilibrium;': '\u296f',
|
| 1893 |
+
'rfisht;': '\u297d',
|
| 1894 |
+
'rfloor;': '\u230b',
|
| 1895 |
+
'Rfr;': '\u211c',
|
| 1896 |
+
'rfr;': '\U0001d52f',
|
| 1897 |
+
'rHar;': '\u2964',
|
| 1898 |
+
'rhard;': '\u21c1',
|
| 1899 |
+
'rharu;': '\u21c0',
|
| 1900 |
+
'rharul;': '\u296c',
|
| 1901 |
+
'Rho;': '\u03a1',
|
| 1902 |
+
'rho;': '\u03c1',
|
| 1903 |
+
'rhov;': '\u03f1',
|
| 1904 |
+
'RightAngleBracket;': '\u27e9',
|
| 1905 |
+
'RightArrow;': '\u2192',
|
| 1906 |
+
'Rightarrow;': '\u21d2',
|
| 1907 |
+
'rightarrow;': '\u2192',
|
| 1908 |
+
'RightArrowBar;': '\u21e5',
|
| 1909 |
+
'RightArrowLeftArrow;': '\u21c4',
|
| 1910 |
+
'rightarrowtail;': '\u21a3',
|
| 1911 |
+
'RightCeiling;': '\u2309',
|
| 1912 |
+
'RightDoubleBracket;': '\u27e7',
|
| 1913 |
+
'RightDownTeeVector;': '\u295d',
|
| 1914 |
+
'RightDownVector;': '\u21c2',
|
| 1915 |
+
'RightDownVectorBar;': '\u2955',
|
| 1916 |
+
'RightFloor;': '\u230b',
|
| 1917 |
+
'rightharpoondown;': '\u21c1',
|
| 1918 |
+
'rightharpoonup;': '\u21c0',
|
| 1919 |
+
'rightleftarrows;': '\u21c4',
|
| 1920 |
+
'rightleftharpoons;': '\u21cc',
|
| 1921 |
+
'rightrightarrows;': '\u21c9',
|
| 1922 |
+
'rightsquigarrow;': '\u219d',
|
| 1923 |
+
'RightTee;': '\u22a2',
|
| 1924 |
+
'RightTeeArrow;': '\u21a6',
|
| 1925 |
+
'RightTeeVector;': '\u295b',
|
| 1926 |
+
'rightthreetimes;': '\u22cc',
|
| 1927 |
+
'RightTriangle;': '\u22b3',
|
| 1928 |
+
'RightTriangleBar;': '\u29d0',
|
| 1929 |
+
'RightTriangleEqual;': '\u22b5',
|
| 1930 |
+
'RightUpDownVector;': '\u294f',
|
| 1931 |
+
'RightUpTeeVector;': '\u295c',
|
| 1932 |
+
'RightUpVector;': '\u21be',
|
| 1933 |
+
'RightUpVectorBar;': '\u2954',
|
| 1934 |
+
'RightVector;': '\u21c0',
|
| 1935 |
+
'RightVectorBar;': '\u2953',
|
| 1936 |
+
'ring;': '\u02da',
|
| 1937 |
+
'risingdotseq;': '\u2253',
|
| 1938 |
+
'rlarr;': '\u21c4',
|
| 1939 |
+
'rlhar;': '\u21cc',
|
| 1940 |
+
'rlm;': '\u200f',
|
| 1941 |
+
'rmoust;': '\u23b1',
|
| 1942 |
+
'rmoustache;': '\u23b1',
|
| 1943 |
+
'rnmid;': '\u2aee',
|
| 1944 |
+
'roang;': '\u27ed',
|
| 1945 |
+
'roarr;': '\u21fe',
|
| 1946 |
+
'robrk;': '\u27e7',
|
| 1947 |
+
'ropar;': '\u2986',
|
| 1948 |
+
'Ropf;': '\u211d',
|
| 1949 |
+
'ropf;': '\U0001d563',
|
| 1950 |
+
'roplus;': '\u2a2e',
|
| 1951 |
+
'rotimes;': '\u2a35',
|
| 1952 |
+
'RoundImplies;': '\u2970',
|
| 1953 |
+
'rpar;': ')',
|
| 1954 |
+
'rpargt;': '\u2994',
|
| 1955 |
+
'rppolint;': '\u2a12',
|
| 1956 |
+
'rrarr;': '\u21c9',
|
| 1957 |
+
'Rrightarrow;': '\u21db',
|
| 1958 |
+
'rsaquo;': '\u203a',
|
| 1959 |
+
'Rscr;': '\u211b',
|
| 1960 |
+
'rscr;': '\U0001d4c7',
|
| 1961 |
+
'Rsh;': '\u21b1',
|
| 1962 |
+
'rsh;': '\u21b1',
|
| 1963 |
+
'rsqb;': ']',
|
| 1964 |
+
'rsquo;': '\u2019',
|
| 1965 |
+
'rsquor;': '\u2019',
|
| 1966 |
+
'rthree;': '\u22cc',
|
| 1967 |
+
'rtimes;': '\u22ca',
|
| 1968 |
+
'rtri;': '\u25b9',
|
| 1969 |
+
'rtrie;': '\u22b5',
|
| 1970 |
+
'rtrif;': '\u25b8',
|
| 1971 |
+
'rtriltri;': '\u29ce',
|
| 1972 |
+
'RuleDelayed;': '\u29f4',
|
| 1973 |
+
'ruluhar;': '\u2968',
|
| 1974 |
+
'rx;': '\u211e',
|
| 1975 |
+
'Sacute;': '\u015a',
|
| 1976 |
+
'sacute;': '\u015b',
|
| 1977 |
+
'sbquo;': '\u201a',
|
| 1978 |
+
'Sc;': '\u2abc',
|
| 1979 |
+
'sc;': '\u227b',
|
| 1980 |
+
'scap;': '\u2ab8',
|
| 1981 |
+
'Scaron;': '\u0160',
|
| 1982 |
+
'scaron;': '\u0161',
|
| 1983 |
+
'sccue;': '\u227d',
|
| 1984 |
+
'scE;': '\u2ab4',
|
| 1985 |
+
'sce;': '\u2ab0',
|
| 1986 |
+
'Scedil;': '\u015e',
|
| 1987 |
+
'scedil;': '\u015f',
|
| 1988 |
+
'Scirc;': '\u015c',
|
| 1989 |
+
'scirc;': '\u015d',
|
| 1990 |
+
'scnap;': '\u2aba',
|
| 1991 |
+
'scnE;': '\u2ab6',
|
| 1992 |
+
'scnsim;': '\u22e9',
|
| 1993 |
+
'scpolint;': '\u2a13',
|
| 1994 |
+
'scsim;': '\u227f',
|
| 1995 |
+
'Scy;': '\u0421',
|
| 1996 |
+
'scy;': '\u0441',
|
| 1997 |
+
'sdot;': '\u22c5',
|
| 1998 |
+
'sdotb;': '\u22a1',
|
| 1999 |
+
'sdote;': '\u2a66',
|
| 2000 |
+
'searhk;': '\u2925',
|
| 2001 |
+
'seArr;': '\u21d8',
|
| 2002 |
+
'searr;': '\u2198',
|
| 2003 |
+
'searrow;': '\u2198',
|
| 2004 |
+
'sect': '\xa7',
|
| 2005 |
+
'sect;': '\xa7',
|
| 2006 |
+
'semi;': ';',
|
| 2007 |
+
'seswar;': '\u2929',
|
| 2008 |
+
'setminus;': '\u2216',
|
| 2009 |
+
'setmn;': '\u2216',
|
| 2010 |
+
'sext;': '\u2736',
|
| 2011 |
+
'Sfr;': '\U0001d516',
|
| 2012 |
+
'sfr;': '\U0001d530',
|
| 2013 |
+
'sfrown;': '\u2322',
|
| 2014 |
+
'sharp;': '\u266f',
|
| 2015 |
+
'SHCHcy;': '\u0429',
|
| 2016 |
+
'shchcy;': '\u0449',
|
| 2017 |
+
'SHcy;': '\u0428',
|
| 2018 |
+
'shcy;': '\u0448',
|
| 2019 |
+
'ShortDownArrow;': '\u2193',
|
| 2020 |
+
'ShortLeftArrow;': '\u2190',
|
| 2021 |
+
'shortmid;': '\u2223',
|
| 2022 |
+
'shortparallel;': '\u2225',
|
| 2023 |
+
'ShortRightArrow;': '\u2192',
|
| 2024 |
+
'ShortUpArrow;': '\u2191',
|
| 2025 |
+
'shy': '\xad',
|
| 2026 |
+
'shy;': '\xad',
|
| 2027 |
+
'Sigma;': '\u03a3',
|
| 2028 |
+
'sigma;': '\u03c3',
|
| 2029 |
+
'sigmaf;': '\u03c2',
|
| 2030 |
+
'sigmav;': '\u03c2',
|
| 2031 |
+
'sim;': '\u223c',
|
| 2032 |
+
'simdot;': '\u2a6a',
|
| 2033 |
+
'sime;': '\u2243',
|
| 2034 |
+
'simeq;': '\u2243',
|
| 2035 |
+
'simg;': '\u2a9e',
|
| 2036 |
+
'simgE;': '\u2aa0',
|
| 2037 |
+
'siml;': '\u2a9d',
|
| 2038 |
+
'simlE;': '\u2a9f',
|
| 2039 |
+
'simne;': '\u2246',
|
| 2040 |
+
'simplus;': '\u2a24',
|
| 2041 |
+
'simrarr;': '\u2972',
|
| 2042 |
+
'slarr;': '\u2190',
|
| 2043 |
+
'SmallCircle;': '\u2218',
|
| 2044 |
+
'smallsetminus;': '\u2216',
|
| 2045 |
+
'smashp;': '\u2a33',
|
| 2046 |
+
'smeparsl;': '\u29e4',
|
| 2047 |
+
'smid;': '\u2223',
|
| 2048 |
+
'smile;': '\u2323',
|
| 2049 |
+
'smt;': '\u2aaa',
|
| 2050 |
+
'smte;': '\u2aac',
|
| 2051 |
+
'smtes;': '\u2aac\ufe00',
|
| 2052 |
+
'SOFTcy;': '\u042c',
|
| 2053 |
+
'softcy;': '\u044c',
|
| 2054 |
+
'sol;': '/',
|
| 2055 |
+
'solb;': '\u29c4',
|
| 2056 |
+
'solbar;': '\u233f',
|
| 2057 |
+
'Sopf;': '\U0001d54a',
|
| 2058 |
+
'sopf;': '\U0001d564',
|
| 2059 |
+
'spades;': '\u2660',
|
| 2060 |
+
'spadesuit;': '\u2660',
|
| 2061 |
+
'spar;': '\u2225',
|
| 2062 |
+
'sqcap;': '\u2293',
|
| 2063 |
+
'sqcaps;': '\u2293\ufe00',
|
| 2064 |
+
'sqcup;': '\u2294',
|
| 2065 |
+
'sqcups;': '\u2294\ufe00',
|
| 2066 |
+
'Sqrt;': '\u221a',
|
| 2067 |
+
'sqsub;': '\u228f',
|
| 2068 |
+
'sqsube;': '\u2291',
|
| 2069 |
+
'sqsubset;': '\u228f',
|
| 2070 |
+
'sqsubseteq;': '\u2291',
|
| 2071 |
+
'sqsup;': '\u2290',
|
| 2072 |
+
'sqsupe;': '\u2292',
|
| 2073 |
+
'sqsupset;': '\u2290',
|
| 2074 |
+
'sqsupseteq;': '\u2292',
|
| 2075 |
+
'squ;': '\u25a1',
|
| 2076 |
+
'Square;': '\u25a1',
|
| 2077 |
+
'square;': '\u25a1',
|
| 2078 |
+
'SquareIntersection;': '\u2293',
|
| 2079 |
+
'SquareSubset;': '\u228f',
|
| 2080 |
+
'SquareSubsetEqual;': '\u2291',
|
| 2081 |
+
'SquareSuperset;': '\u2290',
|
| 2082 |
+
'SquareSupersetEqual;': '\u2292',
|
| 2083 |
+
'SquareUnion;': '\u2294',
|
| 2084 |
+
'squarf;': '\u25aa',
|
| 2085 |
+
'squf;': '\u25aa',
|
| 2086 |
+
'srarr;': '\u2192',
|
| 2087 |
+
'Sscr;': '\U0001d4ae',
|
| 2088 |
+
'sscr;': '\U0001d4c8',
|
| 2089 |
+
'ssetmn;': '\u2216',
|
| 2090 |
+
'ssmile;': '\u2323',
|
| 2091 |
+
'sstarf;': '\u22c6',
|
| 2092 |
+
'Star;': '\u22c6',
|
| 2093 |
+
'star;': '\u2606',
|
| 2094 |
+
'starf;': '\u2605',
|
| 2095 |
+
'straightepsilon;': '\u03f5',
|
| 2096 |
+
'straightphi;': '\u03d5',
|
| 2097 |
+
'strns;': '\xaf',
|
| 2098 |
+
'Sub;': '\u22d0',
|
| 2099 |
+
'sub;': '\u2282',
|
| 2100 |
+
'subdot;': '\u2abd',
|
| 2101 |
+
'subE;': '\u2ac5',
|
| 2102 |
+
'sube;': '\u2286',
|
| 2103 |
+
'subedot;': '\u2ac3',
|
| 2104 |
+
'submult;': '\u2ac1',
|
| 2105 |
+
'subnE;': '\u2acb',
|
| 2106 |
+
'subne;': '\u228a',
|
| 2107 |
+
'subplus;': '\u2abf',
|
| 2108 |
+
'subrarr;': '\u2979',
|
| 2109 |
+
'Subset;': '\u22d0',
|
| 2110 |
+
'subset;': '\u2282',
|
| 2111 |
+
'subseteq;': '\u2286',
|
| 2112 |
+
'subseteqq;': '\u2ac5',
|
| 2113 |
+
'SubsetEqual;': '\u2286',
|
| 2114 |
+
'subsetneq;': '\u228a',
|
| 2115 |
+
'subsetneqq;': '\u2acb',
|
| 2116 |
+
'subsim;': '\u2ac7',
|
| 2117 |
+
'subsub;': '\u2ad5',
|
| 2118 |
+
'subsup;': '\u2ad3',
|
| 2119 |
+
'succ;': '\u227b',
|
| 2120 |
+
'succapprox;': '\u2ab8',
|
| 2121 |
+
'succcurlyeq;': '\u227d',
|
| 2122 |
+
'Succeeds;': '\u227b',
|
| 2123 |
+
'SucceedsEqual;': '\u2ab0',
|
| 2124 |
+
'SucceedsSlantEqual;': '\u227d',
|
| 2125 |
+
'SucceedsTilde;': '\u227f',
|
| 2126 |
+
'succeq;': '\u2ab0',
|
| 2127 |
+
'succnapprox;': '\u2aba',
|
| 2128 |
+
'succneqq;': '\u2ab6',
|
| 2129 |
+
'succnsim;': '\u22e9',
|
| 2130 |
+
'succsim;': '\u227f',
|
| 2131 |
+
'SuchThat;': '\u220b',
|
| 2132 |
+
'Sum;': '\u2211',
|
| 2133 |
+
'sum;': '\u2211',
|
| 2134 |
+
'sung;': '\u266a',
|
| 2135 |
+
'sup1': '\xb9',
|
| 2136 |
+
'sup1;': '\xb9',
|
| 2137 |
+
'sup2': '\xb2',
|
| 2138 |
+
'sup2;': '\xb2',
|
| 2139 |
+
'sup3': '\xb3',
|
| 2140 |
+
'sup3;': '\xb3',
|
| 2141 |
+
'Sup;': '\u22d1',
|
| 2142 |
+
'sup;': '\u2283',
|
| 2143 |
+
'supdot;': '\u2abe',
|
| 2144 |
+
'supdsub;': '\u2ad8',
|
| 2145 |
+
'supE;': '\u2ac6',
|
| 2146 |
+
'supe;': '\u2287',
|
| 2147 |
+
'supedot;': '\u2ac4',
|
| 2148 |
+
'Superset;': '\u2283',
|
| 2149 |
+
'SupersetEqual;': '\u2287',
|
| 2150 |
+
'suphsol;': '\u27c9',
|
| 2151 |
+
'suphsub;': '\u2ad7',
|
| 2152 |
+
'suplarr;': '\u297b',
|
| 2153 |
+
'supmult;': '\u2ac2',
|
| 2154 |
+
'supnE;': '\u2acc',
|
| 2155 |
+
'supne;': '\u228b',
|
| 2156 |
+
'supplus;': '\u2ac0',
|
| 2157 |
+
'Supset;': '\u22d1',
|
| 2158 |
+
'supset;': '\u2283',
|
| 2159 |
+
'supseteq;': '\u2287',
|
| 2160 |
+
'supseteqq;': '\u2ac6',
|
| 2161 |
+
'supsetneq;': '\u228b',
|
| 2162 |
+
'supsetneqq;': '\u2acc',
|
| 2163 |
+
'supsim;': '\u2ac8',
|
| 2164 |
+
'supsub;': '\u2ad4',
|
| 2165 |
+
'supsup;': '\u2ad6',
|
| 2166 |
+
'swarhk;': '\u2926',
|
| 2167 |
+
'swArr;': '\u21d9',
|
| 2168 |
+
'swarr;': '\u2199',
|
| 2169 |
+
'swarrow;': '\u2199',
|
| 2170 |
+
'swnwar;': '\u292a',
|
| 2171 |
+
'szlig': '\xdf',
|
| 2172 |
+
'szlig;': '\xdf',
|
| 2173 |
+
'Tab;': '\t',
|
| 2174 |
+
'target;': '\u2316',
|
| 2175 |
+
'Tau;': '\u03a4',
|
| 2176 |
+
'tau;': '\u03c4',
|
| 2177 |
+
'tbrk;': '\u23b4',
|
| 2178 |
+
'Tcaron;': '\u0164',
|
| 2179 |
+
'tcaron;': '\u0165',
|
| 2180 |
+
'Tcedil;': '\u0162',
|
| 2181 |
+
'tcedil;': '\u0163',
|
| 2182 |
+
'Tcy;': '\u0422',
|
| 2183 |
+
'tcy;': '\u0442',
|
| 2184 |
+
'tdot;': '\u20db',
|
| 2185 |
+
'telrec;': '\u2315',
|
| 2186 |
+
'Tfr;': '\U0001d517',
|
| 2187 |
+
'tfr;': '\U0001d531',
|
| 2188 |
+
'there4;': '\u2234',
|
| 2189 |
+
'Therefore;': '\u2234',
|
| 2190 |
+
'therefore;': '\u2234',
|
| 2191 |
+
'Theta;': '\u0398',
|
| 2192 |
+
'theta;': '\u03b8',
|
| 2193 |
+
'thetasym;': '\u03d1',
|
| 2194 |
+
'thetav;': '\u03d1',
|
| 2195 |
+
'thickapprox;': '\u2248',
|
| 2196 |
+
'thicksim;': '\u223c',
|
| 2197 |
+
'ThickSpace;': '\u205f\u200a',
|
| 2198 |
+
'thinsp;': '\u2009',
|
| 2199 |
+
'ThinSpace;': '\u2009',
|
| 2200 |
+
'thkap;': '\u2248',
|
| 2201 |
+
'thksim;': '\u223c',
|
| 2202 |
+
'THORN': '\xde',
|
| 2203 |
+
'thorn': '\xfe',
|
| 2204 |
+
'THORN;': '\xde',
|
| 2205 |
+
'thorn;': '\xfe',
|
| 2206 |
+
'Tilde;': '\u223c',
|
| 2207 |
+
'tilde;': '\u02dc',
|
| 2208 |
+
'TildeEqual;': '\u2243',
|
| 2209 |
+
'TildeFullEqual;': '\u2245',
|
| 2210 |
+
'TildeTilde;': '\u2248',
|
| 2211 |
+
'times': '\xd7',
|
| 2212 |
+
'times;': '\xd7',
|
| 2213 |
+
'timesb;': '\u22a0',
|
| 2214 |
+
'timesbar;': '\u2a31',
|
| 2215 |
+
'timesd;': '\u2a30',
|
| 2216 |
+
'tint;': '\u222d',
|
| 2217 |
+
'toea;': '\u2928',
|
| 2218 |
+
'top;': '\u22a4',
|
| 2219 |
+
'topbot;': '\u2336',
|
| 2220 |
+
'topcir;': '\u2af1',
|
| 2221 |
+
'Topf;': '\U0001d54b',
|
| 2222 |
+
'topf;': '\U0001d565',
|
| 2223 |
+
'topfork;': '\u2ada',
|
| 2224 |
+
'tosa;': '\u2929',
|
| 2225 |
+
'tprime;': '\u2034',
|
| 2226 |
+
'TRADE;': '\u2122',
|
| 2227 |
+
'trade;': '\u2122',
|
| 2228 |
+
'triangle;': '\u25b5',
|
| 2229 |
+
'triangledown;': '\u25bf',
|
| 2230 |
+
'triangleleft;': '\u25c3',
|
| 2231 |
+
'trianglelefteq;': '\u22b4',
|
| 2232 |
+
'triangleq;': '\u225c',
|
| 2233 |
+
'triangleright;': '\u25b9',
|
| 2234 |
+
'trianglerighteq;': '\u22b5',
|
| 2235 |
+
'tridot;': '\u25ec',
|
| 2236 |
+
'trie;': '\u225c',
|
| 2237 |
+
'triminus;': '\u2a3a',
|
| 2238 |
+
'TripleDot;': '\u20db',
|
| 2239 |
+
'triplus;': '\u2a39',
|
| 2240 |
+
'trisb;': '\u29cd',
|
| 2241 |
+
'tritime;': '\u2a3b',
|
| 2242 |
+
'trpezium;': '\u23e2',
|
| 2243 |
+
'Tscr;': '\U0001d4af',
|
| 2244 |
+
'tscr;': '\U0001d4c9',
|
| 2245 |
+
'TScy;': '\u0426',
|
| 2246 |
+
'tscy;': '\u0446',
|
| 2247 |
+
'TSHcy;': '\u040b',
|
| 2248 |
+
'tshcy;': '\u045b',
|
| 2249 |
+
'Tstrok;': '\u0166',
|
| 2250 |
+
'tstrok;': '\u0167',
|
| 2251 |
+
'twixt;': '\u226c',
|
| 2252 |
+
'twoheadleftarrow;': '\u219e',
|
| 2253 |
+
'twoheadrightarrow;': '\u21a0',
|
| 2254 |
+
'Uacute': '\xda',
|
| 2255 |
+
'uacute': '\xfa',
|
| 2256 |
+
'Uacute;': '\xda',
|
| 2257 |
+
'uacute;': '\xfa',
|
| 2258 |
+
'Uarr;': '\u219f',
|
| 2259 |
+
'uArr;': '\u21d1',
|
| 2260 |
+
'uarr;': '\u2191',
|
| 2261 |
+
'Uarrocir;': '\u2949',
|
| 2262 |
+
'Ubrcy;': '\u040e',
|
| 2263 |
+
'ubrcy;': '\u045e',
|
| 2264 |
+
'Ubreve;': '\u016c',
|
| 2265 |
+
'ubreve;': '\u016d',
|
| 2266 |
+
'Ucirc': '\xdb',
|
| 2267 |
+
'ucirc': '\xfb',
|
| 2268 |
+
'Ucirc;': '\xdb',
|
| 2269 |
+
'ucirc;': '\xfb',
|
| 2270 |
+
'Ucy;': '\u0423',
|
| 2271 |
+
'ucy;': '\u0443',
|
| 2272 |
+
'udarr;': '\u21c5',
|
| 2273 |
+
'Udblac;': '\u0170',
|
| 2274 |
+
'udblac;': '\u0171',
|
| 2275 |
+
'udhar;': '\u296e',
|
| 2276 |
+
'ufisht;': '\u297e',
|
| 2277 |
+
'Ufr;': '\U0001d518',
|
| 2278 |
+
'ufr;': '\U0001d532',
|
| 2279 |
+
'Ugrave': '\xd9',
|
| 2280 |
+
'ugrave': '\xf9',
|
| 2281 |
+
'Ugrave;': '\xd9',
|
| 2282 |
+
'ugrave;': '\xf9',
|
| 2283 |
+
'uHar;': '\u2963',
|
| 2284 |
+
'uharl;': '\u21bf',
|
| 2285 |
+
'uharr;': '\u21be',
|
| 2286 |
+
'uhblk;': '\u2580',
|
| 2287 |
+
'ulcorn;': '\u231c',
|
| 2288 |
+
'ulcorner;': '\u231c',
|
| 2289 |
+
'ulcrop;': '\u230f',
|
| 2290 |
+
'ultri;': '\u25f8',
|
| 2291 |
+
'Umacr;': '\u016a',
|
| 2292 |
+
'umacr;': '\u016b',
|
| 2293 |
+
'uml': '\xa8',
|
| 2294 |
+
'uml;': '\xa8',
|
| 2295 |
+
'UnderBar;': '_',
|
| 2296 |
+
'UnderBrace;': '\u23df',
|
| 2297 |
+
'UnderBracket;': '\u23b5',
|
| 2298 |
+
'UnderParenthesis;': '\u23dd',
|
| 2299 |
+
'Union;': '\u22c3',
|
| 2300 |
+
'UnionPlus;': '\u228e',
|
| 2301 |
+
'Uogon;': '\u0172',
|
| 2302 |
+
'uogon;': '\u0173',
|
| 2303 |
+
'Uopf;': '\U0001d54c',
|
| 2304 |
+
'uopf;': '\U0001d566',
|
| 2305 |
+
'UpArrow;': '\u2191',
|
| 2306 |
+
'Uparrow;': '\u21d1',
|
| 2307 |
+
'uparrow;': '\u2191',
|
| 2308 |
+
'UpArrowBar;': '\u2912',
|
| 2309 |
+
'UpArrowDownArrow;': '\u21c5',
|
| 2310 |
+
'UpDownArrow;': '\u2195',
|
| 2311 |
+
'Updownarrow;': '\u21d5',
|
| 2312 |
+
'updownarrow;': '\u2195',
|
| 2313 |
+
'UpEquilibrium;': '\u296e',
|
| 2314 |
+
'upharpoonleft;': '\u21bf',
|
| 2315 |
+
'upharpoonright;': '\u21be',
|
| 2316 |
+
'uplus;': '\u228e',
|
| 2317 |
+
'UpperLeftArrow;': '\u2196',
|
| 2318 |
+
'UpperRightArrow;': '\u2197',
|
| 2319 |
+
'Upsi;': '\u03d2',
|
| 2320 |
+
'upsi;': '\u03c5',
|
| 2321 |
+
'upsih;': '\u03d2',
|
| 2322 |
+
'Upsilon;': '\u03a5',
|
| 2323 |
+
'upsilon;': '\u03c5',
|
| 2324 |
+
'UpTee;': '\u22a5',
|
| 2325 |
+
'UpTeeArrow;': '\u21a5',
|
| 2326 |
+
'upuparrows;': '\u21c8',
|
| 2327 |
+
'urcorn;': '\u231d',
|
| 2328 |
+
'urcorner;': '\u231d',
|
| 2329 |
+
'urcrop;': '\u230e',
|
| 2330 |
+
'Uring;': '\u016e',
|
| 2331 |
+
'uring;': '\u016f',
|
| 2332 |
+
'urtri;': '\u25f9',
|
| 2333 |
+
'Uscr;': '\U0001d4b0',
|
| 2334 |
+
'uscr;': '\U0001d4ca',
|
| 2335 |
+
'utdot;': '\u22f0',
|
| 2336 |
+
'Utilde;': '\u0168',
|
| 2337 |
+
'utilde;': '\u0169',
|
| 2338 |
+
'utri;': '\u25b5',
|
| 2339 |
+
'utrif;': '\u25b4',
|
| 2340 |
+
'uuarr;': '\u21c8',
|
| 2341 |
+
'Uuml': '\xdc',
|
| 2342 |
+
'uuml': '\xfc',
|
| 2343 |
+
'Uuml;': '\xdc',
|
| 2344 |
+
'uuml;': '\xfc',
|
| 2345 |
+
'uwangle;': '\u29a7',
|
| 2346 |
+
'vangrt;': '\u299c',
|
| 2347 |
+
'varepsilon;': '\u03f5',
|
| 2348 |
+
'varkappa;': '\u03f0',
|
| 2349 |
+
'varnothing;': '\u2205',
|
| 2350 |
+
'varphi;': '\u03d5',
|
| 2351 |
+
'varpi;': '\u03d6',
|
| 2352 |
+
'varpropto;': '\u221d',
|
| 2353 |
+
'vArr;': '\u21d5',
|
| 2354 |
+
'varr;': '\u2195',
|
| 2355 |
+
'varrho;': '\u03f1',
|
| 2356 |
+
'varsigma;': '\u03c2',
|
| 2357 |
+
'varsubsetneq;': '\u228a\ufe00',
|
| 2358 |
+
'varsubsetneqq;': '\u2acb\ufe00',
|
| 2359 |
+
'varsupsetneq;': '\u228b\ufe00',
|
| 2360 |
+
'varsupsetneqq;': '\u2acc\ufe00',
|
| 2361 |
+
'vartheta;': '\u03d1',
|
| 2362 |
+
'vartriangleleft;': '\u22b2',
|
| 2363 |
+
'vartriangleright;': '\u22b3',
|
| 2364 |
+
'Vbar;': '\u2aeb',
|
| 2365 |
+
'vBar;': '\u2ae8',
|
| 2366 |
+
'vBarv;': '\u2ae9',
|
| 2367 |
+
'Vcy;': '\u0412',
|
| 2368 |
+
'vcy;': '\u0432',
|
| 2369 |
+
'VDash;': '\u22ab',
|
| 2370 |
+
'Vdash;': '\u22a9',
|
| 2371 |
+
'vDash;': '\u22a8',
|
| 2372 |
+
'vdash;': '\u22a2',
|
| 2373 |
+
'Vdashl;': '\u2ae6',
|
| 2374 |
+
'Vee;': '\u22c1',
|
| 2375 |
+
'vee;': '\u2228',
|
| 2376 |
+
'veebar;': '\u22bb',
|
| 2377 |
+
'veeeq;': '\u225a',
|
| 2378 |
+
'vellip;': '\u22ee',
|
| 2379 |
+
'Verbar;': '\u2016',
|
| 2380 |
+
'verbar;': '|',
|
| 2381 |
+
'Vert;': '\u2016',
|
| 2382 |
+
'vert;': '|',
|
| 2383 |
+
'VerticalBar;': '\u2223',
|
| 2384 |
+
'VerticalLine;': '|',
|
| 2385 |
+
'VerticalSeparator;': '\u2758',
|
| 2386 |
+
'VerticalTilde;': '\u2240',
|
| 2387 |
+
'VeryThinSpace;': '\u200a',
|
| 2388 |
+
'Vfr;': '\U0001d519',
|
| 2389 |
+
'vfr;': '\U0001d533',
|
| 2390 |
+
'vltri;': '\u22b2',
|
| 2391 |
+
'vnsub;': '\u2282\u20d2',
|
| 2392 |
+
'vnsup;': '\u2283\u20d2',
|
| 2393 |
+
'Vopf;': '\U0001d54d',
|
| 2394 |
+
'vopf;': '\U0001d567',
|
| 2395 |
+
'vprop;': '\u221d',
|
| 2396 |
+
'vrtri;': '\u22b3',
|
| 2397 |
+
'Vscr;': '\U0001d4b1',
|
| 2398 |
+
'vscr;': '\U0001d4cb',
|
| 2399 |
+
'vsubnE;': '\u2acb\ufe00',
|
| 2400 |
+
'vsubne;': '\u228a\ufe00',
|
| 2401 |
+
'vsupnE;': '\u2acc\ufe00',
|
| 2402 |
+
'vsupne;': '\u228b\ufe00',
|
| 2403 |
+
'Vvdash;': '\u22aa',
|
| 2404 |
+
'vzigzag;': '\u299a',
|
| 2405 |
+
'Wcirc;': '\u0174',
|
| 2406 |
+
'wcirc;': '\u0175',
|
| 2407 |
+
'wedbar;': '\u2a5f',
|
| 2408 |
+
'Wedge;': '\u22c0',
|
| 2409 |
+
'wedge;': '\u2227',
|
| 2410 |
+
'wedgeq;': '\u2259',
|
| 2411 |
+
'weierp;': '\u2118',
|
| 2412 |
+
'Wfr;': '\U0001d51a',
|
| 2413 |
+
'wfr;': '\U0001d534',
|
| 2414 |
+
'Wopf;': '\U0001d54e',
|
| 2415 |
+
'wopf;': '\U0001d568',
|
| 2416 |
+
'wp;': '\u2118',
|
| 2417 |
+
'wr;': '\u2240',
|
| 2418 |
+
'wreath;': '\u2240',
|
| 2419 |
+
'Wscr;': '\U0001d4b2',
|
| 2420 |
+
'wscr;': '\U0001d4cc',
|
| 2421 |
+
'xcap;': '\u22c2',
|
| 2422 |
+
'xcirc;': '\u25ef',
|
| 2423 |
+
'xcup;': '\u22c3',
|
| 2424 |
+
'xdtri;': '\u25bd',
|
| 2425 |
+
'Xfr;': '\U0001d51b',
|
| 2426 |
+
'xfr;': '\U0001d535',
|
| 2427 |
+
'xhArr;': '\u27fa',
|
| 2428 |
+
'xharr;': '\u27f7',
|
| 2429 |
+
'Xi;': '\u039e',
|
| 2430 |
+
'xi;': '\u03be',
|
| 2431 |
+
'xlArr;': '\u27f8',
|
| 2432 |
+
'xlarr;': '\u27f5',
|
| 2433 |
+
'xmap;': '\u27fc',
|
| 2434 |
+
'xnis;': '\u22fb',
|
| 2435 |
+
'xodot;': '\u2a00',
|
| 2436 |
+
'Xopf;': '\U0001d54f',
|
| 2437 |
+
'xopf;': '\U0001d569',
|
| 2438 |
+
'xoplus;': '\u2a01',
|
| 2439 |
+
'xotime;': '\u2a02',
|
| 2440 |
+
'xrArr;': '\u27f9',
|
| 2441 |
+
'xrarr;': '\u27f6',
|
| 2442 |
+
'Xscr;': '\U0001d4b3',
|
| 2443 |
+
'xscr;': '\U0001d4cd',
|
| 2444 |
+
'xsqcup;': '\u2a06',
|
| 2445 |
+
'xuplus;': '\u2a04',
|
| 2446 |
+
'xutri;': '\u25b3',
|
| 2447 |
+
'xvee;': '\u22c1',
|
| 2448 |
+
'xwedge;': '\u22c0',
|
| 2449 |
+
'Yacute': '\xdd',
|
| 2450 |
+
'yacute': '\xfd',
|
| 2451 |
+
'Yacute;': '\xdd',
|
| 2452 |
+
'yacute;': '\xfd',
|
| 2453 |
+
'YAcy;': '\u042f',
|
| 2454 |
+
'yacy;': '\u044f',
|
| 2455 |
+
'Ycirc;': '\u0176',
|
| 2456 |
+
'ycirc;': '\u0177',
|
| 2457 |
+
'Ycy;': '\u042b',
|
| 2458 |
+
'ycy;': '\u044b',
|
| 2459 |
+
'yen': '\xa5',
|
| 2460 |
+
'yen;': '\xa5',
|
| 2461 |
+
'Yfr;': '\U0001d51c',
|
| 2462 |
+
'yfr;': '\U0001d536',
|
| 2463 |
+
'YIcy;': '\u0407',
|
| 2464 |
+
'yicy;': '\u0457',
|
| 2465 |
+
'Yopf;': '\U0001d550',
|
| 2466 |
+
'yopf;': '\U0001d56a',
|
| 2467 |
+
'Yscr;': '\U0001d4b4',
|
| 2468 |
+
'yscr;': '\U0001d4ce',
|
| 2469 |
+
'YUcy;': '\u042e',
|
| 2470 |
+
'yucy;': '\u044e',
|
| 2471 |
+
'yuml': '\xff',
|
| 2472 |
+
'Yuml;': '\u0178',
|
| 2473 |
+
'yuml;': '\xff',
|
| 2474 |
+
'Zacute;': '\u0179',
|
| 2475 |
+
'zacute;': '\u017a',
|
| 2476 |
+
'Zcaron;': '\u017d',
|
| 2477 |
+
'zcaron;': '\u017e',
|
| 2478 |
+
'Zcy;': '\u0417',
|
| 2479 |
+
'zcy;': '\u0437',
|
| 2480 |
+
'Zdot;': '\u017b',
|
| 2481 |
+
'zdot;': '\u017c',
|
| 2482 |
+
'zeetrf;': '\u2128',
|
| 2483 |
+
'ZeroWidthSpace;': '\u200b',
|
| 2484 |
+
'Zeta;': '\u0396',
|
| 2485 |
+
'zeta;': '\u03b6',
|
| 2486 |
+
'Zfr;': '\u2128',
|
| 2487 |
+
'zfr;': '\U0001d537',
|
| 2488 |
+
'ZHcy;': '\u0416',
|
| 2489 |
+
'zhcy;': '\u0436',
|
| 2490 |
+
'zigrarr;': '\u21dd',
|
| 2491 |
+
'Zopf;': '\u2124',
|
| 2492 |
+
'zopf;': '\U0001d56b',
|
| 2493 |
+
'Zscr;': '\U0001d4b5',
|
| 2494 |
+
'zscr;': '\U0001d4cf',
|
| 2495 |
+
'zwj;': '\u200d',
|
| 2496 |
+
'zwnj;': '\u200c',
|
| 2497 |
+
}
|
| 2498 |
+
|
| 2499 |
+
# maps the Unicode code point to the HTML entity name
|
| 2500 |
+
codepoint2name = {}
|
| 2501 |
+
|
| 2502 |
+
# maps the HTML entity name to the character
|
| 2503 |
+
# (or a character reference if the character is outside the Latin-1 range)
|
| 2504 |
+
entitydefs = {}
|
| 2505 |
+
|
| 2506 |
+
for (name, codepoint) in name2codepoint.items():
|
| 2507 |
+
codepoint2name[codepoint] = name
|
| 2508 |
+
entitydefs[name] = chr(codepoint)
|
| 2509 |
+
|
| 2510 |
+
del name, codepoint
|
janus/lib/python3.10/html/parser.py
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A parser for HTML and XHTML."""
|
| 2 |
+
|
| 3 |
+
# This file is based on sgmllib.py, but the API is slightly different.
|
| 4 |
+
|
| 5 |
+
# XXX There should be a way to distinguish between PCDATA (parsed
|
| 6 |
+
# character data -- the normal case), RCDATA (replaceable character
|
| 7 |
+
# data -- only char and entity references and end tags are special)
|
| 8 |
+
# and CDATA (character data -- only end tags are special).
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
import re
|
| 12 |
+
import _markupbase
|
| 13 |
+
|
| 14 |
+
from html import unescape
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
__all__ = ['HTMLParser']
|
| 18 |
+
|
| 19 |
+
# Regular expressions used for parsing
|
| 20 |
+
|
| 21 |
+
interesting_normal = re.compile('[&<]')
|
| 22 |
+
incomplete = re.compile('&[a-zA-Z#]')
|
| 23 |
+
|
| 24 |
+
entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
|
| 25 |
+
charref = re.compile('&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]')
|
| 26 |
+
|
| 27 |
+
starttagopen = re.compile('<[a-zA-Z]')
|
| 28 |
+
piclose = re.compile('>')
|
| 29 |
+
commentclose = re.compile(r'--\s*>')
|
| 30 |
+
# Note:
|
| 31 |
+
# 1) if you change tagfind/attrfind remember to update locatestarttagend too;
|
| 32 |
+
# 2) if you change tagfind/attrfind and/or locatestarttagend the parser will
|
| 33 |
+
# explode, so don't do it.
|
| 34 |
+
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
|
| 35 |
+
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
|
| 36 |
+
tagfind_tolerant = re.compile(r'([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
|
| 37 |
+
attrfind_tolerant = re.compile(
|
| 38 |
+
r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*'
|
| 39 |
+
r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*')
|
| 40 |
+
locatestarttagend_tolerant = re.compile(r"""
|
| 41 |
+
<[a-zA-Z][^\t\n\r\f />\x00]* # tag name
|
| 42 |
+
(?:[\s/]* # optional whitespace before attribute name
|
| 43 |
+
(?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name
|
| 44 |
+
(?:\s*=+\s* # value indicator
|
| 45 |
+
(?:'[^']*' # LITA-enclosed value
|
| 46 |
+
|"[^"]*" # LIT-enclosed value
|
| 47 |
+
|(?!['"])[^>\s]* # bare value
|
| 48 |
+
)
|
| 49 |
+
\s* # possibly followed by a space
|
| 50 |
+
)?(?:\s|/(?!>))*
|
| 51 |
+
)*
|
| 52 |
+
)?
|
| 53 |
+
\s* # trailing whitespace
|
| 54 |
+
""", re.VERBOSE)
|
| 55 |
+
endendtag = re.compile('>')
|
| 56 |
+
# the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
|
| 57 |
+
# </ and the tag name, so maybe this should be fixed
|
| 58 |
+
endtagfind = re.compile(r'</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class HTMLParser(_markupbase.ParserBase):
|
| 63 |
+
"""Find tags and other markup and call handler functions.
|
| 64 |
+
|
| 65 |
+
Usage:
|
| 66 |
+
p = HTMLParser()
|
| 67 |
+
p.feed(data)
|
| 68 |
+
...
|
| 69 |
+
p.close()
|
| 70 |
+
|
| 71 |
+
Start tags are handled by calling self.handle_starttag() or
|
| 72 |
+
self.handle_startendtag(); end tags by self.handle_endtag(). The
|
| 73 |
+
data between tags is passed from the parser to the derived class
|
| 74 |
+
by calling self.handle_data() with the data as argument (the data
|
| 75 |
+
may be split up in arbitrary chunks). If convert_charrefs is
|
| 76 |
+
True the character references are converted automatically to the
|
| 77 |
+
corresponding Unicode character (and self.handle_data() is no
|
| 78 |
+
longer split in chunks), otherwise they are passed by calling
|
| 79 |
+
self.handle_entityref() or self.handle_charref() with the string
|
| 80 |
+
containing respectively the named or numeric reference as the
|
| 81 |
+
argument.
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
CDATA_CONTENT_ELEMENTS = ("script", "style")
|
| 85 |
+
|
| 86 |
+
def __init__(self, *, convert_charrefs=True):
|
| 87 |
+
"""Initialize and reset this instance.
|
| 88 |
+
|
| 89 |
+
If convert_charrefs is True (the default), all character references
|
| 90 |
+
are automatically converted to the corresponding Unicode characters.
|
| 91 |
+
"""
|
| 92 |
+
self.convert_charrefs = convert_charrefs
|
| 93 |
+
self.reset()
|
| 94 |
+
|
| 95 |
+
def reset(self):
|
| 96 |
+
"""Reset this instance. Loses all unprocessed data."""
|
| 97 |
+
self.rawdata = ''
|
| 98 |
+
self.lasttag = '???'
|
| 99 |
+
self.interesting = interesting_normal
|
| 100 |
+
self.cdata_elem = None
|
| 101 |
+
_markupbase.ParserBase.reset(self)
|
| 102 |
+
|
| 103 |
+
def feed(self, data):
|
| 104 |
+
r"""Feed data to the parser.
|
| 105 |
+
|
| 106 |
+
Call this as often as you want, with as little or as much text
|
| 107 |
+
as you want (may include '\n').
|
| 108 |
+
"""
|
| 109 |
+
self.rawdata = self.rawdata + data
|
| 110 |
+
self.goahead(0)
|
| 111 |
+
|
| 112 |
+
def close(self):
|
| 113 |
+
"""Handle any buffered data."""
|
| 114 |
+
self.goahead(1)
|
| 115 |
+
|
| 116 |
+
__starttag_text = None
|
| 117 |
+
|
| 118 |
+
def get_starttag_text(self):
|
| 119 |
+
"""Return full source of start tag: '<...>'."""
|
| 120 |
+
return self.__starttag_text
|
| 121 |
+
|
| 122 |
+
def set_cdata_mode(self, elem):
|
| 123 |
+
self.cdata_elem = elem.lower()
|
| 124 |
+
self.interesting = re.compile(r'</\s*%s\s*>' % self.cdata_elem, re.I)
|
| 125 |
+
|
| 126 |
+
def clear_cdata_mode(self):
|
| 127 |
+
self.interesting = interesting_normal
|
| 128 |
+
self.cdata_elem = None
|
| 129 |
+
|
| 130 |
+
# Internal -- handle data as far as reasonable. May leave state
|
| 131 |
+
# and data to be processed by a subsequent call. If 'end' is
|
| 132 |
+
# true, force handling all data as if followed by EOF marker.
|
| 133 |
+
def goahead(self, end):
|
| 134 |
+
rawdata = self.rawdata
|
| 135 |
+
i = 0
|
| 136 |
+
n = len(rawdata)
|
| 137 |
+
while i < n:
|
| 138 |
+
if self.convert_charrefs and not self.cdata_elem:
|
| 139 |
+
j = rawdata.find('<', i)
|
| 140 |
+
if j < 0:
|
| 141 |
+
# if we can't find the next <, either we are at the end
|
| 142 |
+
# or there's more text incoming. If the latter is True,
|
| 143 |
+
# we can't pass the text to handle_data in case we have
|
| 144 |
+
# a charref cut in half at end. Try to determine if
|
| 145 |
+
# this is the case before proceeding by looking for an
|
| 146 |
+
# & near the end and see if it's followed by a space or ;.
|
| 147 |
+
amppos = rawdata.rfind('&', max(i, n-34))
|
| 148 |
+
if (amppos >= 0 and
|
| 149 |
+
not re.compile(r'[\s;]').search(rawdata, amppos)):
|
| 150 |
+
break # wait till we get all the text
|
| 151 |
+
j = n
|
| 152 |
+
else:
|
| 153 |
+
match = self.interesting.search(rawdata, i) # < or &
|
| 154 |
+
if match:
|
| 155 |
+
j = match.start()
|
| 156 |
+
else:
|
| 157 |
+
if self.cdata_elem:
|
| 158 |
+
break
|
| 159 |
+
j = n
|
| 160 |
+
if i < j:
|
| 161 |
+
if self.convert_charrefs and not self.cdata_elem:
|
| 162 |
+
self.handle_data(unescape(rawdata[i:j]))
|
| 163 |
+
else:
|
| 164 |
+
self.handle_data(rawdata[i:j])
|
| 165 |
+
i = self.updatepos(i, j)
|
| 166 |
+
if i == n: break
|
| 167 |
+
startswith = rawdata.startswith
|
| 168 |
+
if startswith('<', i):
|
| 169 |
+
if starttagopen.match(rawdata, i): # < + letter
|
| 170 |
+
k = self.parse_starttag(i)
|
| 171 |
+
elif startswith("</", i):
|
| 172 |
+
k = self.parse_endtag(i)
|
| 173 |
+
elif startswith("<!--", i):
|
| 174 |
+
k = self.parse_comment(i)
|
| 175 |
+
elif startswith("<?", i):
|
| 176 |
+
k = self.parse_pi(i)
|
| 177 |
+
elif startswith("<!", i):
|
| 178 |
+
k = self.parse_html_declaration(i)
|
| 179 |
+
elif (i + 1) < n:
|
| 180 |
+
self.handle_data("<")
|
| 181 |
+
k = i + 1
|
| 182 |
+
else:
|
| 183 |
+
break
|
| 184 |
+
if k < 0:
|
| 185 |
+
if not end:
|
| 186 |
+
break
|
| 187 |
+
k = rawdata.find('>', i + 1)
|
| 188 |
+
if k < 0:
|
| 189 |
+
k = rawdata.find('<', i + 1)
|
| 190 |
+
if k < 0:
|
| 191 |
+
k = i + 1
|
| 192 |
+
else:
|
| 193 |
+
k += 1
|
| 194 |
+
if self.convert_charrefs and not self.cdata_elem:
|
| 195 |
+
self.handle_data(unescape(rawdata[i:k]))
|
| 196 |
+
else:
|
| 197 |
+
self.handle_data(rawdata[i:k])
|
| 198 |
+
i = self.updatepos(i, k)
|
| 199 |
+
elif startswith("&#", i):
|
| 200 |
+
match = charref.match(rawdata, i)
|
| 201 |
+
if match:
|
| 202 |
+
name = match.group()[2:-1]
|
| 203 |
+
self.handle_charref(name)
|
| 204 |
+
k = match.end()
|
| 205 |
+
if not startswith(';', k-1):
|
| 206 |
+
k = k - 1
|
| 207 |
+
i = self.updatepos(i, k)
|
| 208 |
+
continue
|
| 209 |
+
else:
|
| 210 |
+
if ";" in rawdata[i:]: # bail by consuming &#
|
| 211 |
+
self.handle_data(rawdata[i:i+2])
|
| 212 |
+
i = self.updatepos(i, i+2)
|
| 213 |
+
break
|
| 214 |
+
elif startswith('&', i):
|
| 215 |
+
match = entityref.match(rawdata, i)
|
| 216 |
+
if match:
|
| 217 |
+
name = match.group(1)
|
| 218 |
+
self.handle_entityref(name)
|
| 219 |
+
k = match.end()
|
| 220 |
+
if not startswith(';', k-1):
|
| 221 |
+
k = k - 1
|
| 222 |
+
i = self.updatepos(i, k)
|
| 223 |
+
continue
|
| 224 |
+
match = incomplete.match(rawdata, i)
|
| 225 |
+
if match:
|
| 226 |
+
# match.group() will contain at least 2 chars
|
| 227 |
+
if end and match.group() == rawdata[i:]:
|
| 228 |
+
k = match.end()
|
| 229 |
+
if k <= i:
|
| 230 |
+
k = n
|
| 231 |
+
i = self.updatepos(i, i + 1)
|
| 232 |
+
# incomplete
|
| 233 |
+
break
|
| 234 |
+
elif (i + 1) < n:
|
| 235 |
+
# not the end of the buffer, and can't be confused
|
| 236 |
+
# with some other construct
|
| 237 |
+
self.handle_data("&")
|
| 238 |
+
i = self.updatepos(i, i + 1)
|
| 239 |
+
else:
|
| 240 |
+
break
|
| 241 |
+
else:
|
| 242 |
+
assert 0, "interesting.search() lied"
|
| 243 |
+
# end while
|
| 244 |
+
if end and i < n and not self.cdata_elem:
|
| 245 |
+
if self.convert_charrefs and not self.cdata_elem:
|
| 246 |
+
self.handle_data(unescape(rawdata[i:n]))
|
| 247 |
+
else:
|
| 248 |
+
self.handle_data(rawdata[i:n])
|
| 249 |
+
i = self.updatepos(i, n)
|
| 250 |
+
self.rawdata = rawdata[i:]
|
| 251 |
+
|
| 252 |
+
# Internal -- parse html declarations, return length or -1 if not terminated
|
| 253 |
+
# See w3.org/TR/html5/tokenization.html#markup-declaration-open-state
|
| 254 |
+
# See also parse_declaration in _markupbase
|
| 255 |
+
def parse_html_declaration(self, i):
|
| 256 |
+
rawdata = self.rawdata
|
| 257 |
+
assert rawdata[i:i+2] == '<!', ('unexpected call to '
|
| 258 |
+
'parse_html_declaration()')
|
| 259 |
+
if rawdata[i:i+4] == '<!--':
|
| 260 |
+
# this case is actually already handled in goahead()
|
| 261 |
+
return self.parse_comment(i)
|
| 262 |
+
elif rawdata[i:i+3] == '<![':
|
| 263 |
+
return self.parse_marked_section(i)
|
| 264 |
+
elif rawdata[i:i+9].lower() == '<!doctype':
|
| 265 |
+
# find the closing >
|
| 266 |
+
gtpos = rawdata.find('>', i+9)
|
| 267 |
+
if gtpos == -1:
|
| 268 |
+
return -1
|
| 269 |
+
self.handle_decl(rawdata[i+2:gtpos])
|
| 270 |
+
return gtpos+1
|
| 271 |
+
else:
|
| 272 |
+
return self.parse_bogus_comment(i)
|
| 273 |
+
|
| 274 |
+
# Internal -- parse bogus comment, return length or -1 if not terminated
|
| 275 |
+
# see http://www.w3.org/TR/html5/tokenization.html#bogus-comment-state
|
| 276 |
+
def parse_bogus_comment(self, i, report=1):
|
| 277 |
+
rawdata = self.rawdata
|
| 278 |
+
assert rawdata[i:i+2] in ('<!', '</'), ('unexpected call to '
|
| 279 |
+
'parse_comment()')
|
| 280 |
+
pos = rawdata.find('>', i+2)
|
| 281 |
+
if pos == -1:
|
| 282 |
+
return -1
|
| 283 |
+
if report:
|
| 284 |
+
self.handle_comment(rawdata[i+2:pos])
|
| 285 |
+
return pos + 1
|
| 286 |
+
|
| 287 |
+
# Internal -- parse processing instr, return end or -1 if not terminated
|
| 288 |
+
def parse_pi(self, i):
|
| 289 |
+
rawdata = self.rawdata
|
| 290 |
+
assert rawdata[i:i+2] == '<?', 'unexpected call to parse_pi()'
|
| 291 |
+
match = piclose.search(rawdata, i+2) # >
|
| 292 |
+
if not match:
|
| 293 |
+
return -1
|
| 294 |
+
j = match.start()
|
| 295 |
+
self.handle_pi(rawdata[i+2: j])
|
| 296 |
+
j = match.end()
|
| 297 |
+
return j
|
| 298 |
+
|
| 299 |
+
# Internal -- handle starttag, return end or -1 if not terminated
|
| 300 |
+
def parse_starttag(self, i):
|
| 301 |
+
self.__starttag_text = None
|
| 302 |
+
endpos = self.check_for_whole_start_tag(i)
|
| 303 |
+
if endpos < 0:
|
| 304 |
+
return endpos
|
| 305 |
+
rawdata = self.rawdata
|
| 306 |
+
self.__starttag_text = rawdata[i:endpos]
|
| 307 |
+
|
| 308 |
+
# Now parse the data between i+1 and j into a tag and attrs
|
| 309 |
+
attrs = []
|
| 310 |
+
match = tagfind_tolerant.match(rawdata, i+1)
|
| 311 |
+
assert match, 'unexpected call to parse_starttag()'
|
| 312 |
+
k = match.end()
|
| 313 |
+
self.lasttag = tag = match.group(1).lower()
|
| 314 |
+
while k < endpos:
|
| 315 |
+
m = attrfind_tolerant.match(rawdata, k)
|
| 316 |
+
if not m:
|
| 317 |
+
break
|
| 318 |
+
attrname, rest, attrvalue = m.group(1, 2, 3)
|
| 319 |
+
if not rest:
|
| 320 |
+
attrvalue = None
|
| 321 |
+
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
|
| 322 |
+
attrvalue[:1] == '"' == attrvalue[-1:]:
|
| 323 |
+
attrvalue = attrvalue[1:-1]
|
| 324 |
+
if attrvalue:
|
| 325 |
+
attrvalue = unescape(attrvalue)
|
| 326 |
+
attrs.append((attrname.lower(), attrvalue))
|
| 327 |
+
k = m.end()
|
| 328 |
+
|
| 329 |
+
end = rawdata[k:endpos].strip()
|
| 330 |
+
if end not in (">", "/>"):
|
| 331 |
+
lineno, offset = self.getpos()
|
| 332 |
+
if "\n" in self.__starttag_text:
|
| 333 |
+
lineno = lineno + self.__starttag_text.count("\n")
|
| 334 |
+
offset = len(self.__starttag_text) \
|
| 335 |
+
- self.__starttag_text.rfind("\n")
|
| 336 |
+
else:
|
| 337 |
+
offset = offset + len(self.__starttag_text)
|
| 338 |
+
self.handle_data(rawdata[i:endpos])
|
| 339 |
+
return endpos
|
| 340 |
+
if end.endswith('/>'):
|
| 341 |
+
# XHTML-style empty tag: <span attr="value" />
|
| 342 |
+
self.handle_startendtag(tag, attrs)
|
| 343 |
+
else:
|
| 344 |
+
self.handle_starttag(tag, attrs)
|
| 345 |
+
if tag in self.CDATA_CONTENT_ELEMENTS:
|
| 346 |
+
self.set_cdata_mode(tag)
|
| 347 |
+
return endpos
|
| 348 |
+
|
| 349 |
+
# Internal -- check to see if we have a complete starttag; return end
|
| 350 |
+
# or -1 if incomplete.
|
| 351 |
+
def check_for_whole_start_tag(self, i):
|
| 352 |
+
rawdata = self.rawdata
|
| 353 |
+
m = locatestarttagend_tolerant.match(rawdata, i)
|
| 354 |
+
if m:
|
| 355 |
+
j = m.end()
|
| 356 |
+
next = rawdata[j:j+1]
|
| 357 |
+
if next == ">":
|
| 358 |
+
return j + 1
|
| 359 |
+
if next == "/":
|
| 360 |
+
if rawdata.startswith("/>", j):
|
| 361 |
+
return j + 2
|
| 362 |
+
if rawdata.startswith("/", j):
|
| 363 |
+
# buffer boundary
|
| 364 |
+
return -1
|
| 365 |
+
# else bogus input
|
| 366 |
+
if j > i:
|
| 367 |
+
return j
|
| 368 |
+
else:
|
| 369 |
+
return i + 1
|
| 370 |
+
if next == "":
|
| 371 |
+
# end of input
|
| 372 |
+
return -1
|
| 373 |
+
if next in ("abcdefghijklmnopqrstuvwxyz=/"
|
| 374 |
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
|
| 375 |
+
# end of input in or before attribute value, or we have the
|
| 376 |
+
# '/' from a '/>' ending
|
| 377 |
+
return -1
|
| 378 |
+
if j > i:
|
| 379 |
+
return j
|
| 380 |
+
else:
|
| 381 |
+
return i + 1
|
| 382 |
+
raise AssertionError("we should not get here!")
|
| 383 |
+
|
| 384 |
+
# Internal -- parse endtag, return end or -1 if incomplete
|
| 385 |
+
def parse_endtag(self, i):
|
| 386 |
+
rawdata = self.rawdata
|
| 387 |
+
assert rawdata[i:i+2] == "</", "unexpected call to parse_endtag"
|
| 388 |
+
match = endendtag.search(rawdata, i+1) # >
|
| 389 |
+
if not match:
|
| 390 |
+
return -1
|
| 391 |
+
gtpos = match.end()
|
| 392 |
+
match = endtagfind.match(rawdata, i) # </ + tag + >
|
| 393 |
+
if not match:
|
| 394 |
+
if self.cdata_elem is not None:
|
| 395 |
+
self.handle_data(rawdata[i:gtpos])
|
| 396 |
+
return gtpos
|
| 397 |
+
# find the name: w3.org/TR/html5/tokenization.html#tag-name-state
|
| 398 |
+
namematch = tagfind_tolerant.match(rawdata, i+2)
|
| 399 |
+
if not namematch:
|
| 400 |
+
# w3.org/TR/html5/tokenization.html#end-tag-open-state
|
| 401 |
+
if rawdata[i:i+3] == '</>':
|
| 402 |
+
return i+3
|
| 403 |
+
else:
|
| 404 |
+
return self.parse_bogus_comment(i)
|
| 405 |
+
tagname = namematch.group(1).lower()
|
| 406 |
+
# consume and ignore other stuff between the name and the >
|
| 407 |
+
# Note: this is not 100% correct, since we might have things like
|
| 408 |
+
# </tag attr=">">, but looking for > after the name should cover
|
| 409 |
+
# most of the cases and is much simpler
|
| 410 |
+
gtpos = rawdata.find('>', namematch.end())
|
| 411 |
+
self.handle_endtag(tagname)
|
| 412 |
+
return gtpos+1
|
| 413 |
+
|
| 414 |
+
elem = match.group(1).lower() # script or style
|
| 415 |
+
if self.cdata_elem is not None:
|
| 416 |
+
if elem != self.cdata_elem:
|
| 417 |
+
self.handle_data(rawdata[i:gtpos])
|
| 418 |
+
return gtpos
|
| 419 |
+
|
| 420 |
+
self.handle_endtag(elem)
|
| 421 |
+
self.clear_cdata_mode()
|
| 422 |
+
return gtpos
|
| 423 |
+
|
| 424 |
+
# Overridable -- finish processing of start+end tag: <tag.../>
|
| 425 |
+
def handle_startendtag(self, tag, attrs):
|
| 426 |
+
self.handle_starttag(tag, attrs)
|
| 427 |
+
self.handle_endtag(tag)
|
| 428 |
+
|
| 429 |
+
# Overridable -- handle start tag
|
| 430 |
+
def handle_starttag(self, tag, attrs):
|
| 431 |
+
pass
|
| 432 |
+
|
| 433 |
+
# Overridable -- handle end tag
|
| 434 |
+
def handle_endtag(self, tag):
|
| 435 |
+
pass
|
| 436 |
+
|
| 437 |
+
# Overridable -- handle character reference
|
| 438 |
+
def handle_charref(self, name):
|
| 439 |
+
pass
|
| 440 |
+
|
| 441 |
+
# Overridable -- handle entity reference
|
| 442 |
+
def handle_entityref(self, name):
|
| 443 |
+
pass
|
| 444 |
+
|
| 445 |
+
# Overridable -- handle data
|
| 446 |
+
def handle_data(self, data):
|
| 447 |
+
pass
|
| 448 |
+
|
| 449 |
+
# Overridable -- handle comment
|
| 450 |
+
def handle_comment(self, data):
|
| 451 |
+
pass
|
| 452 |
+
|
| 453 |
+
# Overridable -- handle declaration
|
| 454 |
+
def handle_decl(self, decl):
|
| 455 |
+
pass
|
| 456 |
+
|
| 457 |
+
# Overridable -- handle processing instruction
|
| 458 |
+
def handle_pi(self, data):
|
| 459 |
+
pass
|
| 460 |
+
|
| 461 |
+
def unknown_decl(self, data):
|
| 462 |
+
pass
|