py2docfx 0.1.11rc1981066__py3-none-any.whl → 0.1.11rc1997820__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py2docfx/__main__.py +24 -15
- py2docfx/convert_prepare/environment.py +13 -10
- py2docfx/convert_prepare/generate_document.py +6 -6
- py2docfx/convert_prepare/get_source.py +7 -7
- py2docfx/convert_prepare/git.py +10 -13
- py2docfx/convert_prepare/install_package.py +2 -2
- py2docfx/convert_prepare/pack.py +7 -10
- py2docfx/convert_prepare/package_info.py +3 -3
- py2docfx/convert_prepare/pip_utils.py +12 -14
- py2docfx/convert_prepare/post_process/merge_toc.py +3 -2
- py2docfx/convert_prepare/sphinx_caller.py +34 -12
- py2docfx/convert_prepare/tests/test_environment.py +0 -3
- py2docfx/convert_prepare/tests/test_generate_document.py +4 -2
- py2docfx/convert_prepare/tests/test_get_source.py +22 -14
- py2docfx/convert_prepare/tests/test_pack.py +6 -3
- py2docfx/convert_prepare/tests/test_params.py +0 -1
- py2docfx/convert_prepare/tests/test_sphinx_caller.py +10 -8
- py2docfx/convert_prepare/tests/test_subpackage.py +1 -0
- py2docfx/docfx_yaml/build_finished.py +1 -1
- py2docfx/docfx_yaml/logger.py +56 -55
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +20 -14
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_arc.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +36 -14
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +4 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/managed_identity.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +2 -0
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/auth_code_redirect_handler.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/decorators.py +15 -7
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/managed_identity_client.py +0 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_client.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_managed_identity_client.py +2 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/shared_token_cache.py +3 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +17 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +14 -11
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +30 -12
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +3 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/managed_identity.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/decorators.py +15 -7
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/managed_identity_client.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/google/api/annotations_pb2.py +7 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/auth_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/backend_pb2.py +14 -7
- py2docfx/venv/venv1/Lib/site-packages/google/api/billing_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/client_pb2.py +47 -38
- py2docfx/venv/venv1/Lib/site-packages/google/api/config_change_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/consumer_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/context_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/control_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/distribution_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/api/documentation_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/endpoint_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/error_reason_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/field_behavior_pb2.py +8 -6
- py2docfx/venv/venv1/Lib/site-packages/google/api/field_info_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/http_pb2.py +7 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/httpbody_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/label_pb2.py +7 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/launch_stage_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/log_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/logging_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/metric_pb2.py +12 -9
- py2docfx/venv/venv1/Lib/site-packages/google/api/monitored_resource_pb2.py +15 -10
- py2docfx/venv/venv1/Lib/site-packages/google/api/monitoring_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/policy_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/api/quota_pb2.py +10 -7
- py2docfx/venv/venv1/Lib/site-packages/google/api/resource_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/api/routing_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/service_pb2.py +15 -12
- py2docfx/venv/venv1/Lib/site-packages/google/api/source_info_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/api/system_parameter_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/usage_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api/visibility_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/cloud/extended_operations_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/cloud/location/locations_pb2.py +18 -13
- py2docfx/venv/venv1/Lib/site-packages/google/gapic/metadata/gapic_metadata_pb2.py +31 -26
- py2docfx/venv/venv1/Lib/site-packages/google/logging/type/http_request_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/logging/type/log_severity_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc.py +2 -1
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc_pb2.py +11 -10
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2.py +20 -17
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2_grpc.py +1 -2
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto.py +2 -1
- py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto_pb2.py +22 -19
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/code_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/attribute_context_pb2.py +20 -16
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/audit_context_pb2.py +7 -5
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.py +21 -19
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/http_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/rpc/status_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/calendar_period_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/color_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/date_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/datetime_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/dayofweek_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/decimal_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/expr_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/fraction_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/interval_pb2.py +6 -4
- py2docfx/venv/venv1/Lib/site-packages/google/type/latlng_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/localized_text_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/money_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/month_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/phone_number_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/postal_address_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/quaternion_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/google/type/timeofday_pb2.py +6 -3
- py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +122 -201
- py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +84 -128
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +24 -38
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +44 -58
- py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +170 -254
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +8 -16
- py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +13 -49
- py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +41 -60
- py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +75 -145
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +105 -193
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_aix.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +27 -26
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +16 -17
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +5 -19
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +153 -211
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +0 -6
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +22 -207
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +9 -4
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +8 -15
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +104 -184
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +28 -36
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +240 -0
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sunos.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +44 -50
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -33
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +8 -67
- py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +32 -52
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/METADATA +1 -1
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/RECORD +145 -145
- py2docfx/venv/venv1/Lib/site-packages/psutil/_compat.py +0 -477
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/WHEEL +0 -0
- {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/top_level.txt +0 -0
@@ -2,17 +2,14 @@
|
|
2
2
|
# Use of this source code is governed by a BSD-style license that can be
|
3
3
|
# found in the LICENSE file.
|
4
4
|
|
5
|
-
"""Common objects shared by __init__.py and _ps*.py modules.
|
5
|
+
"""Common objects shared by __init__.py and _ps*.py modules.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
from __future__ import division
|
11
|
-
from __future__ import print_function
|
7
|
+
Note: this module is imported by setup.py, so it should not import
|
8
|
+
psutil or third-party modules.
|
9
|
+
"""
|
12
10
|
|
13
11
|
import collections
|
14
|
-
import
|
15
|
-
import errno
|
12
|
+
import enum
|
16
13
|
import functools
|
17
14
|
import os
|
18
15
|
import socket
|
@@ -36,14 +33,6 @@ except ImportError:
|
|
36
33
|
AF_UNIX = None
|
37
34
|
|
38
35
|
|
39
|
-
# can't take it from _common.py as this script is imported by setup.py
|
40
|
-
PY3 = sys.version_info[0] >= 3
|
41
|
-
if PY3:
|
42
|
-
import enum
|
43
|
-
else:
|
44
|
-
enum = None
|
45
|
-
|
46
|
-
|
47
36
|
PSUTIL_DEBUG = bool(os.getenv('PSUTIL_DEBUG'))
|
48
37
|
_DEFAULT = object()
|
49
38
|
|
@@ -57,7 +46,7 @@ __all__ = [
|
|
57
46
|
'CONN_FIN_WAIT1', 'CONN_FIN_WAIT2', 'CONN_LAST_ACK', 'CONN_LISTEN',
|
58
47
|
'CONN_NONE', 'CONN_SYN_RECV', 'CONN_SYN_SENT', 'CONN_TIME_WAIT',
|
59
48
|
# net constants
|
60
|
-
'NIC_DUPLEX_FULL', 'NIC_DUPLEX_HALF', 'NIC_DUPLEX_UNKNOWN',
|
49
|
+
'NIC_DUPLEX_FULL', 'NIC_DUPLEX_HALF', 'NIC_DUPLEX_UNKNOWN', # noqa: F822
|
61
50
|
# process status constants
|
62
51
|
'STATUS_DEAD', 'STATUS_DISK_SLEEP', 'STATUS_IDLE', 'STATUS_LOCKED',
|
63
52
|
'STATUS_RUNNING', 'STATUS_SLEEPING', 'STATUS_STOPPED', 'STATUS_SUSPENDED',
|
@@ -134,42 +123,29 @@ CONN_LISTEN = "LISTEN"
|
|
134
123
|
CONN_CLOSING = "CLOSING"
|
135
124
|
CONN_NONE = "NONE"
|
136
125
|
|
126
|
+
|
137
127
|
# net_if_stats()
|
138
|
-
|
128
|
+
class NicDuplex(enum.IntEnum):
|
139
129
|
NIC_DUPLEX_FULL = 2
|
140
130
|
NIC_DUPLEX_HALF = 1
|
141
131
|
NIC_DUPLEX_UNKNOWN = 0
|
142
|
-
else:
|
143
132
|
|
144
|
-
class NicDuplex(enum.IntEnum):
|
145
|
-
NIC_DUPLEX_FULL = 2
|
146
|
-
NIC_DUPLEX_HALF = 1
|
147
|
-
NIC_DUPLEX_UNKNOWN = 0
|
148
133
|
|
149
|
-
|
134
|
+
globals().update(NicDuplex.__members__)
|
135
|
+
|
150
136
|
|
151
137
|
# sensors_battery()
|
152
|
-
|
138
|
+
class BatteryTime(enum.IntEnum):
|
153
139
|
POWER_TIME_UNKNOWN = -1
|
154
140
|
POWER_TIME_UNLIMITED = -2
|
155
|
-
else:
|
156
141
|
|
157
|
-
class BatteryTime(enum.IntEnum):
|
158
|
-
POWER_TIME_UNKNOWN = -1
|
159
|
-
POWER_TIME_UNLIMITED = -2
|
160
142
|
|
161
|
-
|
143
|
+
globals().update(BatteryTime.__members__)
|
162
144
|
|
163
145
|
# --- others
|
164
146
|
|
165
147
|
ENCODING = sys.getfilesystemencoding()
|
166
|
-
|
167
|
-
ENCODING_ERRS = "replace"
|
168
|
-
else:
|
169
|
-
try:
|
170
|
-
ENCODING_ERRS = sys.getfilesystemencodeerrors() # py 3.6
|
171
|
-
except AttributeError:
|
172
|
-
ENCODING_ERRS = "surrogateescape" if POSIX else "replace"
|
148
|
+
ENCODING_ERRS = sys.getfilesystemencodeerrors()
|
173
149
|
|
174
150
|
|
175
151
|
# ===================================================================
|
@@ -273,7 +249,7 @@ if AF_INET6 is not None:
|
|
273
249
|
"udp6": ([AF_INET6], [SOCK_DGRAM]),
|
274
250
|
})
|
275
251
|
|
276
|
-
if AF_UNIX is not None:
|
252
|
+
if AF_UNIX is not None and not SUNOS:
|
277
253
|
conn_tmap.update({"unix": ([AF_UNIX], [SOCK_STREAM, SOCK_DGRAM])})
|
278
254
|
|
279
255
|
|
@@ -293,9 +269,7 @@ class Error(Exception):
|
|
293
269
|
info = collections.OrderedDict()
|
294
270
|
for name in attrs:
|
295
271
|
value = getattr(self, name, None)
|
296
|
-
if value:
|
297
|
-
info[name] = value
|
298
|
-
elif name == "pid" and value == 0:
|
272
|
+
if value or (name == "pid" and value == 0):
|
299
273
|
info[name] = value
|
300
274
|
return info
|
301
275
|
|
@@ -303,8 +277,8 @@ class Error(Exception):
|
|
303
277
|
# invoked on `raise Error`
|
304
278
|
info = self._infodict(("pid", "ppid", "name"))
|
305
279
|
if info:
|
306
|
-
details = "(
|
307
|
-
|
280
|
+
details = "({})".format(
|
281
|
+
", ".join([f"{k}={v!r}" for k, v in info.items()])
|
308
282
|
)
|
309
283
|
else:
|
310
284
|
details = None
|
@@ -313,8 +287,8 @@ class Error(Exception):
|
|
313
287
|
def __repr__(self):
|
314
288
|
# invoked on `repr(Error)`
|
315
289
|
info = self._infodict(("pid", "ppid", "name", "seconds", "msg"))
|
316
|
-
details = ", ".join(["
|
317
|
-
return "psutil
|
290
|
+
details = ", ".join([f"{k}={v!r}" for k, v in info.items()])
|
291
|
+
return f"psutil.{self.__class__.__name__}({details})"
|
318
292
|
|
319
293
|
|
320
294
|
class NoSuchProcess(Error):
|
@@ -380,7 +354,7 @@ class TimeoutExpired(Error):
|
|
380
354
|
self.seconds = seconds
|
381
355
|
self.pid = pid
|
382
356
|
self.name = name
|
383
|
-
self.msg = "timeout after
|
357
|
+
self.msg = f"timeout after {seconds} seconds"
|
384
358
|
|
385
359
|
def __reduce__(self):
|
386
360
|
return (self.__class__, (self.seconds, self.pid, self.name))
|
@@ -391,26 +365,6 @@ class TimeoutExpired(Error):
|
|
391
365
|
# ===================================================================
|
392
366
|
|
393
367
|
|
394
|
-
# This should be in _compat.py rather than here, but does not work well
|
395
|
-
# with setup.py importing this module via a sys.path trick.
|
396
|
-
if PY3:
|
397
|
-
if isinstance(__builtins__, dict): # cpython
|
398
|
-
exec_ = __builtins__["exec"]
|
399
|
-
else: # pypy
|
400
|
-
exec_ = getattr(__builtins__, "exec") # noqa
|
401
|
-
|
402
|
-
exec_("""def raise_from(value, from_value):
|
403
|
-
try:
|
404
|
-
raise value from from_value
|
405
|
-
finally:
|
406
|
-
value = None
|
407
|
-
""")
|
408
|
-
else:
|
409
|
-
|
410
|
-
def raise_from(value, from_value):
|
411
|
-
raise value
|
412
|
-
|
413
|
-
|
414
368
|
def usage_percent(used, total, round_=None):
|
415
369
|
"""Calculate percentage usage of 'used' against 'total'."""
|
416
370
|
try:
|
@@ -456,7 +410,7 @@ def memoize(fun):
|
|
456
410
|
try:
|
457
411
|
ret = cache[key] = fun(*args, **kwargs)
|
458
412
|
except Exception as err: # noqa: BLE001
|
459
|
-
raise
|
413
|
+
raise err from None
|
460
414
|
return ret
|
461
415
|
|
462
416
|
def cache_clear():
|
@@ -505,14 +459,14 @@ def memoize_when_activated(fun):
|
|
505
459
|
try:
|
506
460
|
return fun(self)
|
507
461
|
except Exception as err: # noqa: BLE001
|
508
|
-
raise
|
462
|
+
raise err from None
|
509
463
|
except KeyError:
|
510
464
|
# case 3: we entered oneshot() ctx but there's no cache
|
511
465
|
# for this entry yet
|
512
466
|
try:
|
513
467
|
ret = fun(self)
|
514
468
|
except Exception as err: # noqa: BLE001
|
515
|
-
raise
|
469
|
+
raise err from None
|
516
470
|
try:
|
517
471
|
self._cache[fun] = ret
|
518
472
|
except AttributeError:
|
@@ -546,9 +500,9 @@ def isfile_strict(path):
|
|
546
500
|
"""
|
547
501
|
try:
|
548
502
|
st = os.stat(path)
|
549
|
-
except
|
550
|
-
|
551
|
-
|
503
|
+
except PermissionError:
|
504
|
+
raise
|
505
|
+
except OSError:
|
552
506
|
return False
|
553
507
|
else:
|
554
508
|
return stat.S_ISREG(st.st_mode)
|
@@ -561,9 +515,9 @@ def path_exists_strict(path):
|
|
561
515
|
"""
|
562
516
|
try:
|
563
517
|
os.stat(path)
|
564
|
-
except
|
565
|
-
|
566
|
-
|
518
|
+
except PermissionError:
|
519
|
+
raise
|
520
|
+
except OSError:
|
567
521
|
return False
|
568
522
|
else:
|
569
523
|
return True
|
@@ -575,11 +529,10 @@ def supports_ipv6():
|
|
575
529
|
if not socket.has_ipv6 or AF_INET6 is None:
|
576
530
|
return False
|
577
531
|
try:
|
578
|
-
|
579
|
-
with contextlib.closing(sock):
|
532
|
+
with socket.socket(AF_INET6, socket.SOCK_STREAM) as sock:
|
580
533
|
sock.bind(("::1", 0))
|
581
534
|
return True
|
582
|
-
except
|
535
|
+
except OSError:
|
583
536
|
return False
|
584
537
|
|
585
538
|
|
@@ -615,26 +568,20 @@ def sockfam_to_enum(num):
|
|
615
568
|
"""Convert a numeric socket family value to an IntEnum member.
|
616
569
|
If it's not a known member, return the numeric value itself.
|
617
570
|
"""
|
618
|
-
|
571
|
+
try:
|
572
|
+
return socket.AddressFamily(num)
|
573
|
+
except ValueError:
|
619
574
|
return num
|
620
|
-
else: # pragma: no cover
|
621
|
-
try:
|
622
|
-
return socket.AddressFamily(num)
|
623
|
-
except ValueError:
|
624
|
-
return num
|
625
575
|
|
626
576
|
|
627
577
|
def socktype_to_enum(num):
|
628
578
|
"""Convert a numeric socket type value to an IntEnum member.
|
629
579
|
If it's not a known member, return the numeric value itself.
|
630
580
|
"""
|
631
|
-
|
581
|
+
try:
|
582
|
+
return socket.SocketKind(num)
|
583
|
+
except ValueError:
|
632
584
|
return num
|
633
|
-
else: # pragma: no cover
|
634
|
-
try:
|
635
|
-
return socket.SocketKind(num)
|
636
|
-
except ValueError:
|
637
|
-
return num
|
638
585
|
|
639
586
|
|
640
587
|
def conn_to_ntuple(fd, fam, type_, laddr, raddr, status, status_map, pid=None):
|
@@ -656,15 +603,37 @@ def conn_to_ntuple(fd, fam, type_, laddr, raddr, status, status_map, pid=None):
|
|
656
603
|
return sconn(fd, fam, type_, laddr, raddr, status, pid)
|
657
604
|
|
658
605
|
|
606
|
+
def broadcast_addr(addr):
|
607
|
+
"""Given the address ntuple returned by ``net_if_addrs()``
|
608
|
+
calculates the broadcast address.
|
609
|
+
"""
|
610
|
+
import ipaddress
|
611
|
+
|
612
|
+
if not addr.address or not addr.netmask:
|
613
|
+
return None
|
614
|
+
if addr.family == socket.AF_INET:
|
615
|
+
return str(
|
616
|
+
ipaddress.IPv4Network(
|
617
|
+
f"{addr.address}/{addr.netmask}", strict=False
|
618
|
+
).broadcast_address
|
619
|
+
)
|
620
|
+
if addr.family == socket.AF_INET6:
|
621
|
+
return str(
|
622
|
+
ipaddress.IPv6Network(
|
623
|
+
f"{addr.address}/{addr.netmask}", strict=False
|
624
|
+
).broadcast_address
|
625
|
+
)
|
626
|
+
|
627
|
+
|
659
628
|
def deprecated_method(replacement):
|
660
629
|
"""A decorator which can be used to mark a method as deprecated
|
661
630
|
'replcement' is the method name which will be called instead.
|
662
631
|
"""
|
663
632
|
|
664
633
|
def outer(fun):
|
665
|
-
msg =
|
666
|
-
fun.__name__
|
667
|
-
replacement
|
634
|
+
msg = (
|
635
|
+
f"{fun.__name__}() is deprecated and will be removed; use"
|
636
|
+
f" {replacement}() instead"
|
668
637
|
)
|
669
638
|
if fun.__doc__ is None:
|
670
639
|
fun.__doc__ = msg
|
@@ -789,8 +758,6 @@ wrap_numbers.cache_info = _wn.cache_info
|
|
789
758
|
# is 8K. We use a bigger buffer (32K) in order to have more consistent
|
790
759
|
# results when reading /proc pseudo files on Linux, see:
|
791
760
|
# https://github.com/giampaolo/psutil/issues/2050
|
792
|
-
# On Python 2 this also speeds up the reading of big files:
|
793
|
-
# (namely /proc/{pid}/smaps and /proc/net/*):
|
794
761
|
# https://github.com/giampaolo/psutil/issues/708
|
795
762
|
FILE_READ_BUFFER_SIZE = 32 * 1024
|
796
763
|
|
@@ -800,17 +767,13 @@ def open_binary(fname):
|
|
800
767
|
|
801
768
|
|
802
769
|
def open_text(fname):
|
803
|
-
"""
|
804
|
-
|
805
|
-
On Python 2 this is just an alias for open(name, 'rt').
|
770
|
+
"""Open a file in text mode by using the proper FS encoding and
|
771
|
+
en/decoding error handlers.
|
806
772
|
"""
|
807
|
-
if not PY3:
|
808
|
-
return open(fname, buffering=FILE_READ_BUFFER_SIZE)
|
809
|
-
|
810
773
|
# See:
|
811
774
|
# https://github.com/giampaolo/psutil/issues/675
|
812
775
|
# https://github.com/giampaolo/psutil/pull/733
|
813
|
-
fobj = open(
|
776
|
+
fobj = open( # noqa: SIM115
|
814
777
|
fname,
|
815
778
|
buffering=FILE_READ_BUFFER_SIZE,
|
816
779
|
encoding=ENCODING,
|
@@ -842,7 +805,7 @@ def cat(fname, fallback=_DEFAULT, _open=open_text):
|
|
842
805
|
try:
|
843
806
|
with _open(fname) as f:
|
844
807
|
return f.read()
|
845
|
-
except
|
808
|
+
except OSError:
|
846
809
|
return fallback
|
847
810
|
|
848
811
|
|
@@ -852,7 +815,7 @@ def bcat(fname, fallback=_DEFAULT):
|
|
852
815
|
|
853
816
|
|
854
817
|
def bytes2human(n, format="%(value).1f%(symbol)s"):
|
855
|
-
"""Used by various scripts. See:
|
818
|
+
"""Used by various scripts. See: https://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/?in=user-4178764.
|
856
819
|
|
857
820
|
>>> bytes2human(10000)
|
858
821
|
'9.8K'
|
@@ -875,15 +838,8 @@ def get_procfs_path():
|
|
875
838
|
return sys.modules['psutil'].PROCFS_PATH
|
876
839
|
|
877
840
|
|
878
|
-
|
879
|
-
|
880
|
-
def decode(s):
|
881
|
-
return s.decode(encoding=ENCODING, errors=ENCODING_ERRS)
|
882
|
-
|
883
|
-
else:
|
884
|
-
|
885
|
-
def decode(s):
|
886
|
-
return s
|
841
|
+
def decode(s):
|
842
|
+
return s.decode(encoding=ENCODING, errors=ENCODING_ERRS)
|
887
843
|
|
888
844
|
|
889
845
|
# =====================================================================
|
@@ -927,13 +883,12 @@ def hilite(s, color=None, bold=False): # pragma: no cover
|
|
927
883
|
try:
|
928
884
|
color = colors[color]
|
929
885
|
except KeyError:
|
930
|
-
|
931
|
-
|
932
|
-
)
|
886
|
+
msg = f"invalid color {color!r}; choose amongst {list(colors.keys())}"
|
887
|
+
raise ValueError(msg) from None
|
933
888
|
attr.append(color)
|
934
889
|
if bold:
|
935
890
|
attr.append('1')
|
936
|
-
return
|
891
|
+
return f"\x1b[{';'.join(attr)}m{s}\x1b[0m"
|
937
892
|
|
938
893
|
|
939
894
|
def print_color(
|
@@ -941,9 +896,9 @@ def print_color(
|
|
941
896
|
): # pragma: no cover
|
942
897
|
"""Print a colorized version of string."""
|
943
898
|
if not term_supports_colors():
|
944
|
-
print(s, file=file)
|
899
|
+
print(s, file=file)
|
945
900
|
elif POSIX:
|
946
|
-
print(hilite(s, color, bold), file=file)
|
901
|
+
print(hilite(s, color, bold), file=file)
|
947
902
|
else:
|
948
903
|
import ctypes
|
949
904
|
|
@@ -958,10 +913,11 @@ def print_color(
|
|
958
913
|
try:
|
959
914
|
color = colors[color]
|
960
915
|
except KeyError:
|
961
|
-
|
962
|
-
"invalid color
|
963
|
-
|
916
|
+
msg = (
|
917
|
+
f"invalid color {color!r}; choose between"
|
918
|
+
f" {list(colors.keys())!r}"
|
964
919
|
)
|
920
|
+
raise ValueError(msg) from None
|
965
921
|
if bold and color <= 7:
|
966
922
|
color += 8
|
967
923
|
|
@@ -970,7 +926,7 @@ def print_color(
|
|
970
926
|
handle = GetStdHandle(handle_id)
|
971
927
|
SetConsoleTextAttribute(handle, color)
|
972
928
|
try:
|
973
|
-
print(s, file=file)
|
929
|
+
print(s, file=file)
|
974
930
|
finally:
|
975
931
|
SetConsoleTextAttribute(handle, DEFAULT_COLOR)
|
976
932
|
|
@@ -984,11 +940,11 @@ def debug(msg):
|
|
984
940
|
inspect.currentframe().f_back
|
985
941
|
)
|
986
942
|
if isinstance(msg, Exception):
|
987
|
-
if isinstance(msg,
|
943
|
+
if isinstance(msg, OSError):
|
988
944
|
# ...because str(exc) may contain info about the file name
|
989
|
-
msg = "ignoring
|
945
|
+
msg = f"ignoring {msg}"
|
990
946
|
else:
|
991
|
-
msg = "ignoring
|
992
|
-
print( # noqa
|
993
|
-
"psutil-debug [
|
947
|
+
msg = f"ignoring {msg!r}"
|
948
|
+
print( # noqa: T201
|
949
|
+
f"psutil-debug [{fname}:{lineno}]> {msg}", file=sys.stderr
|
994
950
|
)
|
@@ -28,10 +28,6 @@ from ._common import conn_to_ntuple
|
|
28
28
|
from ._common import get_procfs_path
|
29
29
|
from ._common import memoize_when_activated
|
30
30
|
from ._common import usage_percent
|
31
|
-
from ._compat import PY3
|
32
|
-
from ._compat import FileNotFoundError
|
33
|
-
from ._compat import PermissionError
|
34
|
-
from ._compat import ProcessLookupError
|
35
31
|
|
36
32
|
|
37
33
|
__extra__all__ = ["PROCFS_PATH"]
|
@@ -148,12 +144,10 @@ def cpu_count_cores():
|
|
148
144
|
cmd = ["lsdev", "-Cc", "processor"]
|
149
145
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
150
146
|
stdout, stderr = p.communicate()
|
151
|
-
|
152
|
-
stdout, stderr = (
|
153
|
-
x.decode(sys.stdout.encoding) for x in (stdout, stderr)
|
154
|
-
)
|
147
|
+
stdout, stderr = (x.decode(sys.stdout.encoding) for x in (stdout, stderr))
|
155
148
|
if p.returncode != 0:
|
156
|
-
|
149
|
+
msg = f"{cmd!r} command error\n{stderr}"
|
150
|
+
raise RuntimeError(msg)
|
157
151
|
processors = stdout.strip().splitlines()
|
158
152
|
return len(processors) or None
|
159
153
|
|
@@ -211,12 +205,6 @@ def net_connections(kind, _pid=-1):
|
|
211
205
|
"""Return socket connections. If pid == -1 return system-wide
|
212
206
|
connections (as opposed to connections opened by one process only).
|
213
207
|
"""
|
214
|
-
cmap = _common.conn_tmap
|
215
|
-
if kind not in cmap:
|
216
|
-
raise ValueError(
|
217
|
-
"invalid %r kind argument; choose between %s"
|
218
|
-
% (kind, ', '.join([repr(x) for x in cmap]))
|
219
|
-
)
|
220
208
|
families, types = _common.conn_tmap[kind]
|
221
209
|
rawlist = cext.net_connections(_pid)
|
222
210
|
ret = []
|
@@ -243,7 +231,7 @@ def net_connections(kind, _pid=-1):
|
|
243
231
|
def net_if_stats():
|
244
232
|
"""Get NIC stats (isup, duplex, speed, mtu)."""
|
245
233
|
duplex_map = {"Full": NIC_DUPLEX_FULL, "Half": NIC_DUPLEX_HALF}
|
246
|
-
names =
|
234
|
+
names = {x[0] for x in net_if_addrs()}
|
247
235
|
ret = {}
|
248
236
|
for name in names:
|
249
237
|
mtu = cext_posix.net_if_mtu(name)
|
@@ -260,10 +248,9 @@ def net_if_stats():
|
|
260
248
|
stderr=subprocess.PIPE,
|
261
249
|
)
|
262
250
|
stdout, stderr = p.communicate()
|
263
|
-
|
264
|
-
stdout
|
265
|
-
|
266
|
-
)
|
251
|
+
stdout, stderr = (
|
252
|
+
x.decode(sys.stdout.encoding) for x in (stdout, stderr)
|
253
|
+
)
|
267
254
|
if p.returncode == 0:
|
268
255
|
re_result = re.search(
|
269
256
|
r"Running: (\d+) Mbps.*?(\w+) Duplex", stdout
|
@@ -330,18 +317,18 @@ def wrap_exceptions(fun):
|
|
330
317
|
|
331
318
|
@functools.wraps(fun)
|
332
319
|
def wrapper(self, *args, **kwargs):
|
320
|
+
pid, ppid, name = self.pid, self._ppid, self._name
|
333
321
|
try:
|
334
322
|
return fun(self, *args, **kwargs)
|
335
|
-
except (FileNotFoundError, ProcessLookupError):
|
323
|
+
except (FileNotFoundError, ProcessLookupError) as err:
|
336
324
|
# ENOENT (no such file or directory) gets raised on open().
|
337
325
|
# ESRCH (no such process) can get raised on read() if
|
338
326
|
# process is gone in meantime.
|
339
|
-
if not pid_exists(
|
340
|
-
raise NoSuchProcess(
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
raise AccessDenied(self.pid, self._name)
|
327
|
+
if not pid_exists(pid):
|
328
|
+
raise NoSuchProcess(pid, name) from err
|
329
|
+
raise ZombieProcess(pid, name, ppid) from err
|
330
|
+
except PermissionError as err:
|
331
|
+
raise AccessDenied(pid, name) from err
|
345
332
|
|
346
333
|
return wrapper
|
347
334
|
|
@@ -444,7 +431,7 @@ class Process:
|
|
444
431
|
# is no longer there.
|
445
432
|
if not retlist:
|
446
433
|
# will raise NSP if process is gone
|
447
|
-
os.stat(
|
434
|
+
os.stat(f"{self._procfs_path}/{self.pid}")
|
448
435
|
return retlist
|
449
436
|
|
450
437
|
@wrap_exceptions
|
@@ -457,7 +444,7 @@ class Process:
|
|
457
444
|
# is no longer there.
|
458
445
|
if not ret:
|
459
446
|
# will raise NSP if process is gone
|
460
|
-
os.stat(
|
447
|
+
os.stat(f"{self._procfs_path}/{self.pid}")
|
461
448
|
return ret
|
462
449
|
|
463
450
|
@wrap_exceptions
|
@@ -503,10 +490,10 @@ class Process:
|
|
503
490
|
def cwd(self):
|
504
491
|
procfs_path = self._procfs_path
|
505
492
|
try:
|
506
|
-
result = os.readlink("
|
493
|
+
result = os.readlink(f"{procfs_path}/{self.pid}/cwd")
|
507
494
|
return result.rstrip('/')
|
508
495
|
except FileNotFoundError:
|
509
|
-
os.stat("
|
496
|
+
os.stat(f"{procfs_path}/{self.pid}") # raise NSP or AD
|
510
497
|
return ""
|
511
498
|
|
512
499
|
@wrap_exceptions
|
@@ -533,10 +520,9 @@ class Process:
|
|
533
520
|
stderr=subprocess.PIPE,
|
534
521
|
)
|
535
522
|
stdout, stderr = p.communicate()
|
536
|
-
|
537
|
-
stdout
|
538
|
-
|
539
|
-
)
|
523
|
+
stdout, stderr = (
|
524
|
+
x.decode(sys.stdout.encoding) for x in (stdout, stderr)
|
525
|
+
)
|
540
526
|
if "no such process" in stderr.lower():
|
541
527
|
raise NoSuchProcess(self.pid, self._name)
|
542
528
|
procfiles = re.findall(r"(\d+): S_IFREG.*name:(.*)\n", stdout)
|
@@ -554,7 +540,7 @@ class Process:
|
|
554
540
|
def num_fds(self):
|
555
541
|
if self.pid == 0: # no /proc/0/fd
|
556
542
|
return 0
|
557
|
-
return len(os.listdir("
|
543
|
+
return len(os.listdir(f"{self._procfs_path}/{self.pid}/fd"))
|
558
544
|
|
559
545
|
@wrap_exceptions
|
560
546
|
def num_ctx_switches(self):
|
@@ -570,10 +556,10 @@ class Process:
|
|
570
556
|
def io_counters(self):
|
571
557
|
try:
|
572
558
|
rc, wc, rb, wb = cext.proc_io_counters(self.pid)
|
573
|
-
except OSError:
|
559
|
+
except OSError as err:
|
574
560
|
# if process is terminated, proc_io_counters returns OSError
|
575
561
|
# instead of NSP
|
576
562
|
if not pid_exists(self.pid):
|
577
|
-
raise NoSuchProcess(self.pid, self._name)
|
563
|
+
raise NoSuchProcess(self.pid, self._name) from err
|
578
564
|
raise
|
579
565
|
return _common.pio(rc, wc, rb, wb)
|