__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- test-case-name: twisted.python.test.test_systemd -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Integration with systemd.
Currently only the minimum APIs necessary for using systemd's socket activation
feature are supported.
"""
__all__ = ["ListenFDs"]
from os import getpid
from typing import Dict, List, Mapping, Optional, Sequence
from attrs import Factory, define
@define
class ListenFDs:
"""
L{ListenFDs} provides access to file descriptors inherited from systemd.
Typically L{ListenFDs.fromEnvironment} should be used to construct a new
instance of L{ListenFDs}.
@cvar _START: File descriptors inherited from systemd are always
consecutively numbered, with a fixed lowest "starting" descriptor. This
gives the default starting descriptor. Since this must agree with the
value systemd is using, it typically should not be overridden.
@ivar _descriptors: A C{list} of C{int} giving the descriptors which were
inherited.
@ivar _names: A L{Sequence} of C{str} giving the names of the descriptors
which were inherited.
"""
_descriptors: Sequence[int]
_names: Sequence[str] = Factory(tuple)
_START = 3
@classmethod
def fromEnvironment(
cls,
environ: Optional[Mapping[str, str]] = None,
start: Optional[int] = None,
) -> "ListenFDs":
"""
@param environ: A dictionary-like object to inspect to discover
inherited descriptors. By default, L{None}, indicating that the
real process environment should be inspected. The default is
suitable for typical usage.
@param start: An integer giving the lowest value of an inherited
descriptor systemd will give us. By default, L{None}, indicating
the known correct (that is, in agreement with systemd) value will be
used. The default is suitable for typical usage.
@return: A new instance of C{cls} which can be used to look up the
descriptors which have been inherited.
"""
if environ is None:
from os import environ as _environ
environ = _environ
if start is None:
start = cls._START
if str(getpid()) == environ.get("LISTEN_PID"):
descriptors: List[int] = _parseDescriptors(start, environ)
names: Sequence[str] = _parseNames(environ)
else:
descriptors = []
names = ()
# They may both be missing (consistent with not running under systemd
# at all) or they may both be present (consistent with running under
# systemd 227 or newer). It is not allowed for only one to be present
# or for the values to disagree with each other (per
# systemd.socket(5), systemd will use a default value based on the
# socket unit name if the socket unit doesn't explicitly define a name
# with FileDescriptorName).
if len(names) != len(descriptors):
return cls([], ())
return cls(descriptors, names)
def inheritedDescriptors(self) -> List[int]:
"""
@return: The configured descriptors.
"""
return list(self._descriptors)
def inheritedNamedDescriptors(self) -> Dict[str, int]:
"""
@return: A mapping from the names of configured descriptors to
their integer values.
"""
return dict(zip(self._names, self._descriptors))
def _parseDescriptors(start: int, environ: Mapping[str, str]) -> List[int]:
"""
Parse the I{LISTEN_FDS} environment variable supplied by systemd.
@param start: systemd provides only a count of the number of descriptors
that have been inherited. This is the integer value of the first
inherited descriptor. Subsequent inherited descriptors are numbered
counting up from here. See L{ListenFDs._START}.
@param environ: The environment variable mapping in which to look for the
value to parse.
@return: The integer values of the inherited file descriptors, in order.
"""
try:
count = int(environ["LISTEN_FDS"])
except (KeyError, ValueError):
return []
else:
descriptors = list(range(start, start + count))
# Remove the information from the environment so that a second
# `ListenFDs` cannot find the same information. This is a precaution
# against some application code accidentally trying to handle the same
# inherited descriptor more than once - which probably wouldn't work.
#
# This precaution is perhaps somewhat questionable since it is up to
# the application itself to know whether its handling of the file
# descriptor will actually be safe. Also, nothing stops an
# application from getting the same descriptor more than once using
# multiple calls to `ListenFDs.inheritedDescriptors()` on the same
# `ListenFDs` instance.
del environ["LISTEN_PID"], environ["LISTEN_FDS"]
return descriptors
def _parseNames(environ: Mapping[str, str]) -> Sequence[str]:
"""
Parse the I{LISTEN_FDNAMES} environment variable supplied by systemd.
@param environ: The environment variable mapping in which to look for the
value to parse.
@return: The names of the inherited descriptors, in order.
"""
names = environ.get("LISTEN_FDNAMES", "")
if len(names) > 0:
return tuple(names.split(":"))
return ()
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| _pydoctortemplates | Folder | 0755 |
|
|
| test | Folder | 0755 |
|
|
| __init__.py | File | 598 B | 0644 |
|
| _appdirs.py | File | 828 B | 0644 |
|
| _inotify.py | File | 3.42 KB | 0644 |
|
| _release.py | File | 8.57 KB | 0644 |
|
| _shellcomp.py | File | 24.68 KB | 0644 |
|
| _textattributes.py | File | 8.88 KB | 0644 |
|
| _tzhelper.py | File | 3.12 KB | 0644 |
|
| _url.py | File | 228 B | 0644 |
|
| compat.py | File | 16.42 KB | 0644 |
|
| components.py | File | 13.87 KB | 0644 |
|
| constants.py | File | 460 B | 0644 |
|
| context.py | File | 3.96 KB | 0644 |
|
| deprecate.py | File | 27.49 KB | 0644 |
|
| failure.py | File | 27.43 KB | 0644 |
|
| fakepwd.py | File | 6.88 KB | 0644 |
|
| filepath.py | File | 58.92 KB | 0644 |
|
| formmethod.py | File | 11.82 KB | 0644 |
|
| htmlizer.py | File | 3.54 KB | 0644 |
|
| lockfile.py | File | 7.79 KB | 0644 |
|
| log.py | File | 21.89 KB | 0644 |
|
| logfile.py | File | 9.88 KB | 0644 |
|
| modules.py | File | 26.21 KB | 0644 |
|
| monkey.py | File | 2.23 KB | 0644 |
|
| procutils.py | File | 1.34 KB | 0644 |
|
| randbytes.py | File | 3.43 KB | 0644 |
|
| rebuild.py | File | 6.96 KB | 0644 |
|
| reflect.py | File | 20.02 KB | 0644 |
|
| release.py | File | 1.08 KB | 0644 |
|
| roots.py | File | 7.01 KB | 0644 |
|
| runtime.py | File | 5.79 KB | 0644 |
|
| sendmsg.py | File | 2.62 KB | 0644 |
|
| shortcut.py | File | 2.23 KB | 0644 |
|
| syslog.py | File | 3.57 KB | 0644 |
|
| systemd.py | File | 5.45 KB | 0644 |
|
| text.py | File | 5.28 KB | 0644 |
|
| threadable.py | File | 3.25 KB | 0644 |
|
| threadpool.py | File | 10.65 KB | 0644 |
|
| twisted-completion.zsh | File | 1.34 KB | 0644 |
|
| url.py | File | 244 B | 0644 |
|
| urlpath.py | File | 8.25 KB | 0644 |
|
| usage.py | File | 33.79 KB | 0644 |
|
| util.py | File | 26.86 KB | 0644 |
|
| versions.py | File | 273 B | 0644 |
|
| win32.py | File | 4.66 KB | 0644 |
|
| zippath.py | File | 11.99 KB | 0644 |
|
| zipstream.py | File | 9.45 KB | 0644 |
|