py2docfx 0.1.11rc1981066__py3-none-any.whl → 0.1.11rc1996319__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.
Files changed (126) hide show
  1. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
  2. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +20 -14
  3. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_arc.py +1 -1
  4. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +36 -14
  5. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +1 -1
  6. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +2 -2
  7. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +4 -3
  8. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +2 -2
  9. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/managed_identity.py +1 -1
  10. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +2 -0
  11. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/auth_code_redirect_handler.py +1 -1
  12. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/decorators.py +15 -7
  13. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +1 -1
  14. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/managed_identity_client.py +0 -1
  15. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_client.py +1 -1
  16. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_managed_identity_client.py +2 -1
  17. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/shared_token_cache.py +3 -3
  18. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +17 -2
  19. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
  20. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +14 -11
  21. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +30 -12
  22. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +2 -2
  23. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +3 -3
  24. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/managed_identity.py +1 -1
  25. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/decorators.py +15 -7
  26. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/managed_identity_client.py +1 -1
  27. py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
  28. py2docfx/venv/venv1/Lib/site-packages/google/api/annotations_pb2.py +7 -4
  29. py2docfx/venv/venv1/Lib/site-packages/google/api/auth_pb2.py +6 -3
  30. py2docfx/venv/venv1/Lib/site-packages/google/api/backend_pb2.py +14 -7
  31. py2docfx/venv/venv1/Lib/site-packages/google/api/billing_pb2.py +6 -3
  32. py2docfx/venv/venv1/Lib/site-packages/google/api/client_pb2.py +47 -38
  33. py2docfx/venv/venv1/Lib/site-packages/google/api/config_change_pb2.py +6 -3
  34. py2docfx/venv/venv1/Lib/site-packages/google/api/consumer_pb2.py +6 -3
  35. py2docfx/venv/venv1/Lib/site-packages/google/api/context_pb2.py +6 -3
  36. py2docfx/venv/venv1/Lib/site-packages/google/api/control_pb2.py +6 -4
  37. py2docfx/venv/venv1/Lib/site-packages/google/api/distribution_pb2.py +7 -5
  38. py2docfx/venv/venv1/Lib/site-packages/google/api/documentation_pb2.py +6 -3
  39. py2docfx/venv/venv1/Lib/site-packages/google/api/endpoint_pb2.py +6 -3
  40. py2docfx/venv/venv1/Lib/site-packages/google/api/error_reason_pb2.py +6 -3
  41. py2docfx/venv/venv1/Lib/site-packages/google/api/field_behavior_pb2.py +8 -6
  42. py2docfx/venv/venv1/Lib/site-packages/google/api/field_info_pb2.py +6 -4
  43. py2docfx/venv/venv1/Lib/site-packages/google/api/http_pb2.py +7 -4
  44. py2docfx/venv/venv1/Lib/site-packages/google/api/httpbody_pb2.py +6 -4
  45. py2docfx/venv/venv1/Lib/site-packages/google/api/label_pb2.py +7 -4
  46. py2docfx/venv/venv1/Lib/site-packages/google/api/launch_stage_pb2.py +6 -3
  47. py2docfx/venv/venv1/Lib/site-packages/google/api/log_pb2.py +6 -4
  48. py2docfx/venv/venv1/Lib/site-packages/google/api/logging_pb2.py +6 -3
  49. py2docfx/venv/venv1/Lib/site-packages/google/api/metric_pb2.py +12 -9
  50. py2docfx/venv/venv1/Lib/site-packages/google/api/monitored_resource_pb2.py +15 -10
  51. py2docfx/venv/venv1/Lib/site-packages/google/api/monitoring_pb2.py +6 -3
  52. py2docfx/venv/venv1/Lib/site-packages/google/api/policy_pb2.py +7 -5
  53. py2docfx/venv/venv1/Lib/site-packages/google/api/quota_pb2.py +10 -7
  54. py2docfx/venv/venv1/Lib/site-packages/google/api/resource_pb2.py +7 -5
  55. py2docfx/venv/venv1/Lib/site-packages/google/api/routing_pb2.py +6 -4
  56. py2docfx/venv/venv1/Lib/site-packages/google/api/service_pb2.py +15 -12
  57. py2docfx/venv/venv1/Lib/site-packages/google/api/source_info_pb2.py +6 -4
  58. py2docfx/venv/venv1/Lib/site-packages/google/api/system_parameter_pb2.py +6 -3
  59. py2docfx/venv/venv1/Lib/site-packages/google/api/usage_pb2.py +6 -3
  60. py2docfx/venv/venv1/Lib/site-packages/google/api/visibility_pb2.py +7 -5
  61. py2docfx/venv/venv1/Lib/site-packages/google/cloud/extended_operations_pb2.py +6 -4
  62. py2docfx/venv/venv1/Lib/site-packages/google/cloud/location/locations_pb2.py +18 -13
  63. py2docfx/venv/venv1/Lib/site-packages/google/gapic/metadata/gapic_metadata_pb2.py +31 -26
  64. py2docfx/venv/venv1/Lib/site-packages/google/logging/type/http_request_pb2.py +6 -4
  65. py2docfx/venv/venv1/Lib/site-packages/google/logging/type/log_severity_pb2.py +6 -3
  66. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc.py +2 -1
  67. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc_pb2.py +11 -10
  68. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2.py +20 -17
  69. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2_grpc.py +1 -2
  70. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto.py +2 -1
  71. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto_pb2.py +22 -19
  72. py2docfx/venv/venv1/Lib/site-packages/google/rpc/code_pb2.py +6 -3
  73. py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/attribute_context_pb2.py +20 -16
  74. py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/audit_context_pb2.py +7 -5
  75. py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.py +21 -19
  76. py2docfx/venv/venv1/Lib/site-packages/google/rpc/http_pb2.py +6 -3
  77. py2docfx/venv/venv1/Lib/site-packages/google/rpc/status_pb2.py +6 -4
  78. py2docfx/venv/venv1/Lib/site-packages/google/type/calendar_period_pb2.py +6 -3
  79. py2docfx/venv/venv1/Lib/site-packages/google/type/color_pb2.py +6 -4
  80. py2docfx/venv/venv1/Lib/site-packages/google/type/date_pb2.py +6 -3
  81. py2docfx/venv/venv1/Lib/site-packages/google/type/datetime_pb2.py +6 -4
  82. py2docfx/venv/venv1/Lib/site-packages/google/type/dayofweek_pb2.py +6 -3
  83. py2docfx/venv/venv1/Lib/site-packages/google/type/decimal_pb2.py +6 -3
  84. py2docfx/venv/venv1/Lib/site-packages/google/type/expr_pb2.py +6 -3
  85. py2docfx/venv/venv1/Lib/site-packages/google/type/fraction_pb2.py +6 -3
  86. py2docfx/venv/venv1/Lib/site-packages/google/type/interval_pb2.py +6 -4
  87. py2docfx/venv/venv1/Lib/site-packages/google/type/latlng_pb2.py +6 -3
  88. py2docfx/venv/venv1/Lib/site-packages/google/type/localized_text_pb2.py +6 -3
  89. py2docfx/venv/venv1/Lib/site-packages/google/type/money_pb2.py +6 -3
  90. py2docfx/venv/venv1/Lib/site-packages/google/type/month_pb2.py +6 -3
  91. py2docfx/venv/venv1/Lib/site-packages/google/type/phone_number_pb2.py +6 -3
  92. py2docfx/venv/venv1/Lib/site-packages/google/type/postal_address_pb2.py +6 -3
  93. py2docfx/venv/venv1/Lib/site-packages/google/type/quaternion_pb2.py +6 -3
  94. py2docfx/venv/venv1/Lib/site-packages/google/type/timeofday_pb2.py +6 -3
  95. py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +122 -201
  96. py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +84 -128
  97. py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +24 -38
  98. py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +44 -58
  99. py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +170 -254
  100. py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +8 -16
  101. py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +13 -49
  102. py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +41 -60
  103. py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +75 -145
  104. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +105 -193
  105. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_aix.py +2 -2
  106. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +27 -26
  107. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +16 -17
  108. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +5 -19
  109. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +153 -211
  110. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +0 -6
  111. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +22 -207
  112. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +9 -4
  113. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +8 -15
  114. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +104 -184
  115. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +28 -36
  116. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +240 -0
  117. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sunos.py +1 -1
  118. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +44 -50
  119. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -33
  120. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +8 -67
  121. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +32 -52
  122. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/METADATA +1 -1
  123. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/RECORD +125 -125
  124. py2docfx/venv/venv1/Lib/site-packages/psutil/_compat.py +0 -477
  125. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/WHEEL +0 -0
  126. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1996319.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  # Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
4
2
  # Use of this source code is governed by a BSD-style license that can be
5
3
  # found in the LICENSE file.
@@ -17,17 +15,16 @@ sensors) in Python. Supported platforms:
17
15
  - Sun Solaris
18
16
  - AIX
19
17
 
20
- Works with Python versions 2.7 and 3.6+.
18
+ Supported Python versions are cPython 3.6+ and PyPy.
21
19
  """
22
20
 
23
- from __future__ import division
24
-
25
21
  import collections
26
22
  import contextlib
27
23
  import datetime
28
24
  import functools
29
25
  import os
30
26
  import signal
27
+ import socket
31
28
  import subprocess
32
29
  import sys
33
30
  import threading
@@ -54,16 +51,16 @@ from ._common import CONN_NONE
54
51
  from ._common import CONN_SYN_RECV
55
52
  from ._common import CONN_SYN_SENT
56
53
  from ._common import CONN_TIME_WAIT
57
- from ._common import FREEBSD # NOQA
54
+ from ._common import FREEBSD
58
55
  from ._common import LINUX
59
56
  from ._common import MACOS
60
- from ._common import NETBSD # NOQA
57
+ from ._common import NETBSD
61
58
  from ._common import NIC_DUPLEX_FULL
62
59
  from ._common import NIC_DUPLEX_HALF
63
60
  from ._common import NIC_DUPLEX_UNKNOWN
64
- from ._common import OPENBSD # NOQA
61
+ from ._common import OPENBSD
65
62
  from ._common import OSX # deprecated alias
66
- from ._common import POSIX # NOQA
63
+ from ._common import POSIX
67
64
  from ._common import POWER_TIME_UNKNOWN
68
65
  from ._common import POWER_TIME_UNLIMITED
69
66
  from ._common import STATUS_DEAD
@@ -88,11 +85,6 @@ from ._common import ZombieProcess
88
85
  from ._common import debug
89
86
  from ._common import memoize_when_activated
90
87
  from ._common import wrap_numbers as _wrap_numbers
91
- from ._compat import PY3 as _PY3
92
- from ._compat import PermissionError
93
- from ._compat import ProcessLookupError
94
- from ._compat import SubprocessTimeoutExpired as _SubprocessTimeoutExpired
95
- from ._compat import long
96
88
 
97
89
 
98
90
  if LINUX:
@@ -101,24 +93,24 @@ if LINUX:
101
93
  PROCFS_PATH = "/proc"
102
94
 
103
95
  from . import _pslinux as _psplatform
104
- from ._pslinux import IOPRIO_CLASS_BE # NOQA
105
- from ._pslinux import IOPRIO_CLASS_IDLE # NOQA
106
- from ._pslinux import IOPRIO_CLASS_NONE # NOQA
107
- from ._pslinux import IOPRIO_CLASS_RT # NOQA
96
+ from ._pslinux import IOPRIO_CLASS_BE # noqa: F401
97
+ from ._pslinux import IOPRIO_CLASS_IDLE # noqa: F401
98
+ from ._pslinux import IOPRIO_CLASS_NONE # noqa: F401
99
+ from ._pslinux import IOPRIO_CLASS_RT # noqa: F401
108
100
 
109
101
  elif WINDOWS:
110
102
  from . import _pswindows as _psplatform
111
- from ._psutil_windows import ABOVE_NORMAL_PRIORITY_CLASS # NOQA
112
- from ._psutil_windows import BELOW_NORMAL_PRIORITY_CLASS # NOQA
113
- from ._psutil_windows import HIGH_PRIORITY_CLASS # NOQA
114
- from ._psutil_windows import IDLE_PRIORITY_CLASS # NOQA
115
- from ._psutil_windows import NORMAL_PRIORITY_CLASS # NOQA
116
- from ._psutil_windows import REALTIME_PRIORITY_CLASS # NOQA
117
- from ._pswindows import CONN_DELETE_TCB # NOQA
118
- from ._pswindows import IOPRIO_HIGH # NOQA
119
- from ._pswindows import IOPRIO_LOW # NOQA
120
- from ._pswindows import IOPRIO_NORMAL # NOQA
121
- from ._pswindows import IOPRIO_VERYLOW # NOQA
103
+ from ._psutil_windows import ABOVE_NORMAL_PRIORITY_CLASS # noqa: F401
104
+ from ._psutil_windows import BELOW_NORMAL_PRIORITY_CLASS # noqa: F401
105
+ from ._psutil_windows import HIGH_PRIORITY_CLASS # noqa: F401
106
+ from ._psutil_windows import IDLE_PRIORITY_CLASS # noqa: F401
107
+ from ._psutil_windows import NORMAL_PRIORITY_CLASS # noqa: F401
108
+ from ._psutil_windows import REALTIME_PRIORITY_CLASS # noqa: F401
109
+ from ._pswindows import CONN_DELETE_TCB # noqa: F401
110
+ from ._pswindows import IOPRIO_HIGH # noqa: F401
111
+ from ._pswindows import IOPRIO_LOW # noqa: F401
112
+ from ._pswindows import IOPRIO_NORMAL # noqa: F401
113
+ from ._pswindows import IOPRIO_VERYLOW # noqa: F401
122
114
 
123
115
  elif MACOS:
124
116
  from . import _psosx as _psplatform
@@ -128,8 +120,8 @@ elif BSD:
128
120
 
129
121
  elif SUNOS:
130
122
  from . import _pssunos as _psplatform
131
- from ._pssunos import CONN_BOUND # NOQA
132
- from ._pssunos import CONN_IDLE # NOQA
123
+ from ._pssunos import CONN_BOUND # noqa: F401
124
+ from ._pssunos import CONN_IDLE # noqa: F401
133
125
 
134
126
  # This is public writable API which is read from _pslinux.py and
135
127
  # _pssunos.py via sys.modules.
@@ -143,7 +135,8 @@ elif AIX:
143
135
  PROCFS_PATH = "/proc"
144
136
 
145
137
  else: # pragma: no cover
146
- raise NotImplementedError('platform %s is not supported' % sys.platform)
138
+ msg = f"platform {sys.platform} is not supported"
139
+ raise NotImplementedError(msg)
147
140
 
148
141
 
149
142
  # fmt: off
@@ -214,8 +207,8 @@ if hasattr(_psplatform.Process, "rlimit"):
214
207
  AF_LINK = _psplatform.AF_LINK
215
208
 
216
209
  __author__ = "Giampaolo Rodola'"
217
- __version__ = "6.1.1"
218
- version_info = tuple([int(num) for num in __version__.split('.')])
210
+ __version__ = "7.0.0"
211
+ version_info = tuple(int(num) for num in __version__.split('.'))
219
212
 
220
213
  _timer = getattr(time, 'monotonic', time.time)
221
214
  _TOTAL_PHYMEM = None
@@ -231,22 +224,19 @@ _SENTINEL = object()
231
224
  if int(__version__.replace('.', '')) != getattr(
232
225
  _psplatform.cext, 'version', None
233
226
  ):
234
- msg = "version conflict: %r C extension " % _psplatform.cext.__file__
227
+ msg = f"version conflict: {_psplatform.cext.__file__!r} C extension "
235
228
  msg += "module was built for another version of psutil"
236
229
  if hasattr(_psplatform.cext, 'version'):
237
- msg += " (%s instead of %s)" % (
238
- '.'.join([x for x in str(_psplatform.cext.version)]),
239
- __version__,
240
- )
230
+ v = ".".join(list(str(_psplatform.cext.version)))
231
+ msg += f" ({v} instead of {__version__})"
241
232
  else:
242
- msg += " (different than %s)" % __version__
243
- msg += "; you may try to 'pip uninstall psutil', manually remove %s" % (
244
- getattr(
245
- _psplatform.cext,
246
- "__file__",
247
- "the existing psutil install directory",
248
- )
233
+ msg += f" (different than {__version__})"
234
+ what = getattr(
235
+ _psplatform.cext,
236
+ "__file__",
237
+ "the existing psutil install directory",
249
238
  )
239
+ msg += f"; you may try to 'pip uninstall psutil', manually remove {what}"
250
240
  msg += " or clean the virtual env somehow, then reinstall"
251
241
  raise ImportError(msg)
252
242
 
@@ -282,12 +272,20 @@ def _pprint_secs(secs):
282
272
  return datetime.datetime.fromtimestamp(secs).strftime(fmt)
283
273
 
284
274
 
275
+ def _check_conn_kind(kind):
276
+ """Check net_connections()'s `kind` parameter."""
277
+ kinds = tuple(_common.conn_tmap)
278
+ if kind not in kinds:
279
+ msg = f"invalid kind argument {kind!r}; valid ones are: {kinds}"
280
+ raise ValueError(msg)
281
+
282
+
285
283
  # =====================================================================
286
284
  # --- Process class
287
285
  # =====================================================================
288
286
 
289
287
 
290
- class Process(object): # noqa: UP004
288
+ class Process:
291
289
  """Represents an OS process with the given PID.
292
290
  If PID is omitted current process PID (os.getpid()) is used.
293
291
  Raise NoSuchProcess if PID does not exist.
@@ -322,17 +320,14 @@ class Process(object): # noqa: UP004
322
320
  if pid is None:
323
321
  pid = os.getpid()
324
322
  else:
325
- if not _PY3 and not isinstance(pid, (int, long)):
326
- msg = "pid must be an integer (got %r)" % pid
327
- raise TypeError(msg)
328
323
  if pid < 0:
329
- msg = "pid must be a positive integer (got %s)" % pid
324
+ msg = f"pid must be a positive integer (got {pid})"
330
325
  raise ValueError(msg)
331
326
  try:
332
327
  _psplatform.cext.check_pid_range(pid)
333
- except OverflowError:
334
- msg = "process PID out of range (got %s)" % pid
335
- raise NoSuchProcess(pid, msg=msg)
328
+ except OverflowError as err:
329
+ msg = "process PID out of range"
330
+ raise NoSuchProcess(pid, msg=msg) from err
336
331
 
337
332
  self._pid = pid
338
333
  self._name = None
@@ -365,9 +360,8 @@ class Process(object): # noqa: UP004
365
360
  except NoSuchProcess:
366
361
  if not _ignore_nsp:
367
362
  msg = "process PID not found"
368
- raise NoSuchProcess(pid, msg=msg)
369
- else:
370
- self._gone = True
363
+ raise NoSuchProcess(pid, msg=msg) from None
364
+ self._gone = True
371
365
 
372
366
  def _get_ident(self):
373
367
  """Return a (pid, uid) tuple which is supposed to identify a
@@ -419,10 +413,10 @@ class Process(object): # noqa: UP004
419
413
  if self._create_time is not None:
420
414
  info['started'] = _pprint_secs(self._create_time)
421
415
 
422
- return "%s.%s(%s)" % (
416
+ return "{}.{}({})".format(
423
417
  self.__class__.__module__,
424
418
  self.__class__.__name__,
425
- ", ".join(["%s=%r" % (k, v) for k, v in info.items()]),
419
+ ", ".join([f"{k}={v!r}" for k, v in info.items()]),
426
420
  )
427
421
 
428
422
  __repr__ = __str__
@@ -556,12 +550,12 @@ class Process(object): # noqa: UP004
556
550
  valid_names = _as_dict_attrnames
557
551
  if attrs is not None:
558
552
  if not isinstance(attrs, (list, tuple, set, frozenset)):
559
- msg = "invalid attrs type %s" % type(attrs)
553
+ msg = f"invalid attrs type {type(attrs)}"
560
554
  raise TypeError(msg)
561
555
  attrs = set(attrs)
562
556
  invalid_names = attrs - valid_names
563
557
  if invalid_names:
564
- msg = "invalid attr name%s %s" % (
558
+ msg = "invalid attr name{} {}".format(
565
559
  "s" if len(invalid_names) > 1 else "",
566
560
  ", ".join(map(repr, invalid_names)),
567
561
  )
@@ -1049,7 +1043,7 @@ class Process(object): # noqa: UP004
1049
1043
  """
1050
1044
  blocking = interval is not None and interval > 0.0
1051
1045
  if interval is not None and interval < 0:
1052
- msg = "interval is not positive (got %r)" % interval
1046
+ msg = f"interval is not positive (got {interval!r})"
1053
1047
  raise ValueError(msg)
1054
1048
  num_cpus = cpu_count() or 1
1055
1049
 
@@ -1127,10 +1121,6 @@ class Process(object): # noqa: UP004
1127
1121
  """
1128
1122
  return self._proc.memory_info()
1129
1123
 
1130
- @_common.deprecated_method(replacement="memory_info")
1131
- def memory_info_ex(self):
1132
- return self.memory_info()
1133
-
1134
1124
  def memory_full_info(self):
1135
1125
  """This method returns the same information as memory_info(),
1136
1126
  plus, on some platform (Linux, macOS, Windows), also provides
@@ -1159,9 +1149,9 @@ class Process(object): # noqa: UP004
1159
1149
  """
1160
1150
  valid_types = list(_psplatform.pfullmem._fields)
1161
1151
  if memtype not in valid_types:
1162
- msg = "invalid memtype %r; valid types are %r" % (
1163
- memtype,
1164
- tuple(valid_types),
1152
+ msg = (
1153
+ f"invalid memtype {memtype!r}; valid types are"
1154
+ f" {tuple(valid_types)!r}"
1165
1155
  )
1166
1156
  raise ValueError(msg)
1167
1157
  fun = (
@@ -1178,7 +1168,7 @@ class Process(object): # noqa: UP004
1178
1168
  # we should never get here
1179
1169
  msg = (
1180
1170
  "can't calculate process memory percent because total physical"
1181
- " system memory is not positive (%r)" % (total_phymem)
1171
+ f" system memory is not positive ({total_phymem!r})"
1182
1172
  )
1183
1173
  raise ValueError(msg)
1184
1174
  return (value / float(total_phymem)) * 100
@@ -1203,11 +1193,11 @@ class Process(object): # noqa: UP004
1203
1193
  path = tupl[2]
1204
1194
  nums = tupl[3:]
1205
1195
  try:
1206
- d[path] = map(lambda x, y: x + y, d[path], nums)
1196
+ d[path] = list(map(lambda x, y: x + y, d[path], nums))
1207
1197
  except KeyError:
1208
1198
  d[path] = nums
1209
1199
  nt = _psplatform.pmmap_grouped
1210
- return [nt(path, *d[path]) for path in d] # NOQA
1200
+ return [nt(path, *d[path]) for path in d]
1211
1201
  else:
1212
1202
  nt = _psplatform.pmmap_ext
1213
1203
  return [nt(*x) for x in it]
@@ -1241,6 +1231,7 @@ class Process(object): # noqa: UP004
1241
1231
  | all | the sum of all the possible families and protocols |
1242
1232
  +------------+----------------------------------------------------+
1243
1233
  """
1234
+ _check_conn_kind(kind)
1244
1235
  return self._proc.net_connections(kind)
1245
1236
 
1246
1237
  @_common.deprecated_method(replacement="net_connections")
@@ -1254,7 +1245,9 @@ class Process(object): # noqa: UP004
1254
1245
  def _send_signal(self, sig):
1255
1246
  assert not self.pid < 0, self.pid
1256
1247
  self._raise_if_pid_reused()
1257
- if self.pid == 0:
1248
+
1249
+ pid, ppid, name = self.pid, self._ppid, self._name
1250
+ if pid == 0:
1258
1251
  # see "man 2 kill"
1259
1252
  msg = (
1260
1253
  "preventing sending signal to process with PID 0 as it "
@@ -1263,17 +1256,16 @@ class Process(object): # noqa: UP004
1263
1256
  )
1264
1257
  raise ValueError(msg)
1265
1258
  try:
1266
- os.kill(self.pid, sig)
1267
- except ProcessLookupError:
1268
- if OPENBSD and pid_exists(self.pid):
1259
+ os.kill(pid, sig)
1260
+ except ProcessLookupError as err:
1261
+ if OPENBSD and pid_exists(pid):
1269
1262
  # We do this because os.kill() lies in case of
1270
1263
  # zombie processes.
1271
- raise ZombieProcess(self.pid, self._name, self._ppid)
1272
- else:
1273
- self._gone = True
1274
- raise NoSuchProcess(self.pid, self._name)
1275
- except PermissionError:
1276
- raise AccessDenied(self.pid, self._name)
1264
+ raise ZombieProcess(pid, name, ppid) from err
1265
+ self._gone = True
1266
+ raise NoSuchProcess(pid, name) from err
1267
+ except PermissionError as err:
1268
+ raise AccessDenied(pid, name) from err
1277
1269
 
1278
1270
  def send_signal(self, sig):
1279
1271
  """Send a signal *sig* to process pre-emptively checking
@@ -1358,11 +1350,12 @@ class Process(object): # noqa: UP004
1358
1350
 
1359
1351
  # The valid attr names which can be processed by Process.as_dict().
1360
1352
  # fmt: off
1361
- _as_dict_attrnames = set(
1362
- [x for x in dir(Process) if not x.startswith('_') and x not in
1353
+ _as_dict_attrnames = {
1354
+ x for x in dir(Process) if not x.startswith("_") and x not in
1363
1355
  {'send_signal', 'suspend', 'resume', 'terminate', 'kill', 'wait',
1364
1356
  'is_running', 'as_dict', 'parent', 'parents', 'children', 'rlimit',
1365
- 'memory_info_ex', 'connections', 'oneshot'}])
1357
+ 'connections', 'oneshot'}
1358
+ }
1366
1359
  # fmt: on
1367
1360
 
1368
1361
 
@@ -1439,16 +1432,13 @@ class Popen(Process):
1439
1432
  try:
1440
1433
  return object.__getattribute__(self.__subproc, name)
1441
1434
  except AttributeError:
1442
- msg = "%s instance has no attribute '%s'" % (
1443
- self.__class__.__name__,
1444
- name,
1445
- )
1446
- raise AttributeError(msg)
1435
+ msg = f"{self.__class__!r} has no attribute {name!r}"
1436
+ raise AttributeError(msg) from None
1447
1437
 
1448
1438
  def wait(self, timeout=None):
1449
1439
  if self.__subproc.returncode is not None:
1450
1440
  return self.__subproc.returncode
1451
- ret = super(Popen, self).wait(timeout) # noqa
1441
+ ret = super().wait(timeout)
1452
1442
  self.__subproc.returncode = ret
1453
1443
  return ret
1454
1444
 
@@ -1525,7 +1515,7 @@ def process_iter(attrs=None, ad_value=None):
1525
1515
  remove(pid)
1526
1516
  while _pids_reused:
1527
1517
  pid = _pids_reused.pop()
1528
- debug("refreshing Process instance for reused PID %s" % pid)
1518
+ debug(f"refreshing Process instance for reused PID {pid}")
1529
1519
  remove(pid)
1530
1520
  try:
1531
1521
  ls = sorted(list(pmap.items()) + list(dict.fromkeys(new_pids).items()))
@@ -1542,7 +1532,7 @@ def process_iter(attrs=None, ad_value=None):
1542
1532
  _pmap = pmap
1543
1533
 
1544
1534
 
1545
- process_iter.cache_clear = lambda: _pmap.clear() # noqa
1535
+ process_iter.cache_clear = lambda: _pmap.clear() # noqa: PLW0108
1546
1536
  process_iter.cache_clear.__doc__ = "Clear process_iter() internal cache."
1547
1537
 
1548
1538
 
@@ -1586,9 +1576,7 @@ def wait_procs(procs, timeout=None, callback=None):
1586
1576
  def check_gone(proc, timeout):
1587
1577
  try:
1588
1578
  returncode = proc.wait(timeout=timeout)
1589
- except TimeoutExpired:
1590
- pass
1591
- except _SubprocessTimeoutExpired:
1579
+ except (TimeoutExpired, subprocess.TimeoutExpired):
1592
1580
  pass
1593
1581
  else:
1594
1582
  if returncode is not None or not proc.is_running():
@@ -1599,12 +1587,12 @@ def wait_procs(procs, timeout=None, callback=None):
1599
1587
  callback(proc)
1600
1588
 
1601
1589
  if timeout is not None and not timeout >= 0:
1602
- msg = "timeout must be a positive integer, got %s" % timeout
1590
+ msg = f"timeout must be a positive integer, got {timeout}"
1603
1591
  raise ValueError(msg)
1604
1592
  gone = set()
1605
1593
  alive = set(procs)
1606
1594
  if callback is not None and not callable(callback):
1607
- msg = "callback %r is not a callable" % callback
1595
+ msg = f"callback {callback!r} is not a callable"
1608
1596
  raise TypeError(msg)
1609
1597
  if timeout is not None:
1610
1598
  deadline = _timer() + timeout
@@ -1627,7 +1615,7 @@ def wait_procs(procs, timeout=None, callback=None):
1627
1615
  check_gone(proc, timeout)
1628
1616
  else:
1629
1617
  check_gone(proc, max_timeout)
1630
- alive = alive - gone # noqa PLR6104
1618
+ alive = alive - gone # noqa: PLR6104
1631
1619
 
1632
1620
  if alive:
1633
1621
  # Last attempt over processes survived so far.
@@ -1646,7 +1634,7 @@ def wait_procs(procs, timeout=None, callback=None):
1646
1634
 
1647
1635
  def cpu_count(logical=True):
1648
1636
  """Return the number of logical CPUs in the system (same as
1649
- os.cpu_count() in Python 3.4).
1637
+ os.cpu_count()).
1650
1638
 
1651
1639
  If *logical* is False return the number of physical cores only
1652
1640
  (e.g. hyper thread CPUs are excluded).
@@ -1804,7 +1792,7 @@ def cpu_percent(interval=None, percpu=False):
1804
1792
  tid = threading.current_thread().ident
1805
1793
  blocking = interval is not None and interval > 0.0
1806
1794
  if interval is not None and interval < 0:
1807
- msg = "interval is not positive (got %r)" % interval
1795
+ msg = f"interval is not positive (got {interval})"
1808
1796
  raise ValueError(msg)
1809
1797
 
1810
1798
  def calculate(t1, t2):
@@ -1864,7 +1852,7 @@ def cpu_times_percent(interval=None, percpu=False):
1864
1852
  tid = threading.current_thread().ident
1865
1853
  blocking = interval is not None and interval > 0.0
1866
1854
  if interval is not None and interval < 0:
1867
- msg = "interval is not positive (got %r)" % interval
1855
+ msg = f"interval is not positive (got {interval!r})"
1868
1856
  raise ValueError(msg)
1869
1857
 
1870
1858
  def calculate(t1, t2):
@@ -2202,6 +2190,7 @@ def net_connections(kind='inet'):
2202
2190
 
2203
2191
  On macOS this function requires root privileges.
2204
2192
  """
2193
+ _check_conn_kind(kind)
2205
2194
  return _psplatform.net_connections(kind)
2206
2195
 
2207
2196
 
@@ -2223,35 +2212,46 @@ def net_if_addrs():
2223
2212
  Note: you can have more than one address of the same family
2224
2213
  associated with each interface.
2225
2214
  """
2226
- has_enums = _PY3
2227
- if has_enums:
2228
- import socket
2229
2215
  rawlist = _psplatform.net_if_addrs()
2230
2216
  rawlist.sort(key=lambda x: x[1]) # sort by family
2231
2217
  ret = collections.defaultdict(list)
2232
2218
  for name, fam, addr, mask, broadcast, ptp in rawlist:
2233
- if has_enums:
2234
- try:
2235
- fam = socket.AddressFamily(fam)
2236
- except ValueError:
2237
- if WINDOWS and fam == -1:
2238
- fam = _psplatform.AF_LINK
2239
- elif (
2240
- hasattr(_psplatform, "AF_LINK")
2241
- and fam == _psplatform.AF_LINK
2242
- ):
2243
- # Linux defines AF_LINK as an alias for AF_PACKET.
2244
- # We re-set the family here so that repr(family)
2245
- # will show AF_LINK rather than AF_PACKET
2246
- fam = _psplatform.AF_LINK
2219
+ try:
2220
+ fam = socket.AddressFamily(fam)
2221
+ except ValueError:
2222
+ if WINDOWS and fam == -1:
2223
+ fam = _psplatform.AF_LINK
2224
+ elif (
2225
+ hasattr(_psplatform, "AF_LINK") and fam == _psplatform.AF_LINK
2226
+ ):
2227
+ # Linux defines AF_LINK as an alias for AF_PACKET.
2228
+ # We re-set the family here so that repr(family)
2229
+ # will show AF_LINK rather than AF_PACKET
2230
+ fam = _psplatform.AF_LINK
2231
+
2247
2232
  if fam == _psplatform.AF_LINK:
2248
2233
  # The underlying C function may return an incomplete MAC
2249
2234
  # address in which case we fill it with null bytes, see:
2250
2235
  # https://github.com/giampaolo/psutil/issues/786
2251
2236
  separator = ":" if POSIX else "-"
2252
2237
  while addr.count(separator) < 5:
2253
- addr += "%s00" % separator
2254
- ret[name].append(_common.snicaddr(fam, addr, mask, broadcast, ptp))
2238
+ addr += f"{separator}00"
2239
+
2240
+ nt = _common.snicaddr(fam, addr, mask, broadcast, ptp)
2241
+
2242
+ # On Windows broadcast is None, so we determine it via
2243
+ # ipaddress module.
2244
+ if WINDOWS and fam in {socket.AF_INET, socket.AF_INET6}:
2245
+ try:
2246
+ broadcast = _common.broadcast_addr(nt)
2247
+ except Exception as err: # noqa: BLE001
2248
+ debug(err)
2249
+ else:
2250
+ if broadcast is not None:
2251
+ nt._replace(broadcast=broadcast)
2252
+
2253
+ ret[name].append(nt)
2254
+
2255
2255
  return dict(ret)
2256
2256
 
2257
2257
 
@@ -2404,83 +2404,4 @@ def _set_debug(value):
2404
2404
  _psplatform.cext.set_debug(bool(value))
2405
2405
 
2406
2406
 
2407
- def test(): # pragma: no cover
2408
- from ._common import bytes2human
2409
- from ._compat import get_terminal_size
2410
-
2411
- today_day = datetime.date.today()
2412
- # fmt: off
2413
- templ = "%-10s %5s %5s %7s %7s %5s %6s %6s %6s %s"
2414
- attrs = ['pid', 'memory_percent', 'name', 'cmdline', 'cpu_times',
2415
- 'create_time', 'memory_info', 'status', 'nice', 'username']
2416
- print(templ % ("USER", "PID", "%MEM", "VSZ", "RSS", "NICE", # NOQA
2417
- "STATUS", "START", "TIME", "CMDLINE"))
2418
- # fmt: on
2419
- for p in process_iter(attrs, ad_value=None):
2420
- if p.info['create_time']:
2421
- ctime = datetime.datetime.fromtimestamp(p.info['create_time'])
2422
- if ctime.date() == today_day:
2423
- ctime = ctime.strftime("%H:%M")
2424
- else:
2425
- ctime = ctime.strftime("%b%d")
2426
- else:
2427
- ctime = ''
2428
- if p.info['cpu_times']:
2429
- cputime = time.strftime(
2430
- "%M:%S", time.localtime(sum(p.info['cpu_times']))
2431
- )
2432
- else:
2433
- cputime = ''
2434
-
2435
- user = p.info['username'] or ''
2436
- if not user and POSIX:
2437
- try:
2438
- user = p.uids()[0]
2439
- except Error:
2440
- pass
2441
- if user and WINDOWS and '\\' in user:
2442
- user = user.split('\\')[1]
2443
- user = user[:9]
2444
- vms = (
2445
- bytes2human(p.info['memory_info'].vms)
2446
- if p.info['memory_info'] is not None
2447
- else ''
2448
- )
2449
- rss = (
2450
- bytes2human(p.info['memory_info'].rss)
2451
- if p.info['memory_info'] is not None
2452
- else ''
2453
- )
2454
- memp = (
2455
- round(p.info['memory_percent'], 1)
2456
- if p.info['memory_percent'] is not None
2457
- else ''
2458
- )
2459
- nice = int(p.info['nice']) if p.info['nice'] else ''
2460
- if p.info['cmdline']:
2461
- cmdline = ' '.join(p.info['cmdline'])
2462
- else:
2463
- cmdline = p.info['name']
2464
- status = p.info['status'][:5] if p.info['status'] else ''
2465
-
2466
- line = templ % (
2467
- user[:10],
2468
- p.info['pid'],
2469
- memp,
2470
- vms,
2471
- rss,
2472
- nice,
2473
- status,
2474
- ctime,
2475
- cputime,
2476
- cmdline,
2477
- )
2478
- print(line[: get_terminal_size()[0]]) # NOQA
2479
-
2480
-
2481
- del memoize_when_activated, division
2482
- if sys.version_info[0] < 3:
2483
- del num, x # noqa
2484
-
2485
- if __name__ == "__main__":
2486
- test()
2407
+ del memoize_when_activated