__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ 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_runtime -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
__all__ = [
"seconds",
"shortPythonVersion",
"Platform",
"platform",
"platformType",
]
import os
import sys
import warnings
from time import time as seconds
from typing import Optional
def shortPythonVersion() -> str:
"""
Returns the Python version as a dot-separated string.
"""
return "%s.%s.%s" % sys.version_info[:3]
knownPlatforms = {
"nt": "win32",
"ce": "win32",
"posix": "posix",
"java": "java",
"org.python.modules.os": "java",
}
class Platform:
"""
Gives us information about the platform we're running on.
"""
type: Optional[str] = knownPlatforms.get(os.name)
seconds = staticmethod(seconds)
_platform = sys.platform
def __init__(
self, name: Optional[str] = None, platform: Optional[str] = None
) -> None:
if name is not None:
self.type = knownPlatforms.get(name)
if platform is not None:
self._platform = platform
def isKnown(self) -> bool:
"""
Do we know about this platform?
@return: Boolean indicating whether this is a known platform or not.
"""
return self.type != None
def getType(self) -> Optional[str]:
"""
Get platform type.
@return: Either 'posix', 'win32' or 'java'
"""
return self.type
def isMacOSX(self) -> bool:
"""
Check if current platform is macOS.
@return: C{True} if the current platform has been detected as macOS.
"""
return self._platform == "darwin"
def isWinNT(self) -> bool:
"""
Are we running in Windows NT?
This is deprecated and always returns C{True} on win32 because
Twisted only supports Windows NT-derived platforms at this point.
@return: C{True} if the current platform has been detected as
Windows NT.
"""
warnings.warn(
"twisted.python.runtime.Platform.isWinNT was deprecated in "
"Twisted 13.0. Use Platform.isWindows instead.",
DeprecationWarning,
stacklevel=2,
)
return self.isWindows()
def isWindows(self) -> bool:
"""
Are we running in Windows?
@return: C{True} if the current platform has been detected as
Windows.
"""
return self.getType() == "win32"
def isVista(self) -> bool:
"""
Check if current platform is Windows Vista or Windows Server 2008.
@return: C{True} if the current platform has been detected as Vista
"""
return sys.platform == "win32" and sys.getwindowsversion().major == 6
def isLinux(self) -> bool:
"""
Check if current platform is Linux.
@return: C{True} if the current platform has been detected as Linux.
"""
return self._platform.startswith("linux")
def isDocker(self, _initCGroupLocation: str = "/proc/1/cgroup") -> bool:
"""
Check if the current platform is Linux in a Docker container.
@return: C{True} if the current platform has been detected as Linux
inside a Docker container.
"""
if not self.isLinux():
return False
from twisted.python.filepath import FilePath
# Ask for the cgroups of init (pid 1)
initCGroups = FilePath(_initCGroupLocation)
if initCGroups.exists():
# The cgroups file looks like "2:cpu:/". The third element will
# begin with /docker if it is inside a Docker container.
controlGroups = [
x.split(b":") for x in initCGroups.getContent().split(b"\n")
]
for group in controlGroups:
if len(group) == 3 and group[2].startswith(b"/docker/"):
# If it starts with /docker/, we're in a docker container
return True
return False
def _supportsSymlinks(self) -> bool:
"""
Check for symlink support usable for Twisted's purposes.
@return: C{True} if symlinks are supported on the current platform,
otherwise C{False}.
"""
if self.isWindows():
# We do the isWindows() check as newer Pythons support the symlink
# support in Vista+, but only if you have some obscure permission
# (SeCreateSymbolicLinkPrivilege), which can only be given on
# platforms with msc.exe (so, Business/Enterprise editions).
# This uncommon requirement makes the Twisted test suite test fail
# in 99.99% of cases as general users don't have permission to do
# it, even if there is "symlink support".
return False
else:
# If we're not on Windows, check for existence of os.symlink.
try:
os.symlink
except AttributeError:
return False
else:
return True
def supportsThreads(self) -> bool:
"""
Can threads be created?
@return: C{True} if the threads are supported on the current platform.
"""
try:
import threading
return threading is not None # shh pyflakes
except ImportError:
return False
def supportsINotify(self) -> bool:
"""
Return C{True} if we can use the inotify API on this platform.
@since: 10.1
"""
try:
from twisted.python._inotify import INotifyError, init
except ImportError:
return False
try:
os.close(init())
except INotifyError:
return False
return True
platform = Platform()
platformType = platform.getType()
| 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 |
|