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.
Files changed (146) hide show
  1. py2docfx/__main__.py +24 -15
  2. py2docfx/convert_prepare/environment.py +13 -10
  3. py2docfx/convert_prepare/generate_document.py +6 -6
  4. py2docfx/convert_prepare/get_source.py +7 -7
  5. py2docfx/convert_prepare/git.py +10 -13
  6. py2docfx/convert_prepare/install_package.py +2 -2
  7. py2docfx/convert_prepare/pack.py +7 -10
  8. py2docfx/convert_prepare/package_info.py +3 -3
  9. py2docfx/convert_prepare/pip_utils.py +12 -14
  10. py2docfx/convert_prepare/post_process/merge_toc.py +3 -2
  11. py2docfx/convert_prepare/sphinx_caller.py +34 -12
  12. py2docfx/convert_prepare/tests/test_environment.py +0 -3
  13. py2docfx/convert_prepare/tests/test_generate_document.py +4 -2
  14. py2docfx/convert_prepare/tests/test_get_source.py +22 -14
  15. py2docfx/convert_prepare/tests/test_pack.py +6 -3
  16. py2docfx/convert_prepare/tests/test_params.py +0 -1
  17. py2docfx/convert_prepare/tests/test_sphinx_caller.py +10 -8
  18. py2docfx/convert_prepare/tests/test_subpackage.py +1 -0
  19. py2docfx/docfx_yaml/build_finished.py +1 -1
  20. py2docfx/docfx_yaml/logger.py +56 -55
  21. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/authorization_code.py +1 -1
  22. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azd_cli.py +20 -14
  23. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_arc.py +1 -1
  24. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_cli.py +36 -14
  25. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/azure_powershell.py +1 -1
  26. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/chained.py +2 -2
  27. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +4 -3
  28. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +2 -2
  29. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/managed_identity.py +1 -1
  30. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/__init__.py +2 -0
  31. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/auth_code_redirect_handler.py +1 -1
  32. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/decorators.py +15 -7
  33. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +1 -1
  34. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/managed_identity_client.py +0 -1
  35. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_client.py +1 -1
  36. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_managed_identity_client.py +2 -1
  37. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/shared_token_cache.py +3 -3
  38. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/utils.py +17 -2
  39. py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
  40. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azd_cli.py +14 -11
  41. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/azure_cli.py +30 -12
  42. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +2 -2
  43. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +3 -3
  44. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/managed_identity.py +1 -1
  45. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/decorators.py +15 -7
  46. py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_internal/managed_identity_client.py +1 -1
  47. py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
  48. py2docfx/venv/venv1/Lib/site-packages/google/api/annotations_pb2.py +7 -4
  49. py2docfx/venv/venv1/Lib/site-packages/google/api/auth_pb2.py +6 -3
  50. py2docfx/venv/venv1/Lib/site-packages/google/api/backend_pb2.py +14 -7
  51. py2docfx/venv/venv1/Lib/site-packages/google/api/billing_pb2.py +6 -3
  52. py2docfx/venv/venv1/Lib/site-packages/google/api/client_pb2.py +47 -38
  53. py2docfx/venv/venv1/Lib/site-packages/google/api/config_change_pb2.py +6 -3
  54. py2docfx/venv/venv1/Lib/site-packages/google/api/consumer_pb2.py +6 -3
  55. py2docfx/venv/venv1/Lib/site-packages/google/api/context_pb2.py +6 -3
  56. py2docfx/venv/venv1/Lib/site-packages/google/api/control_pb2.py +6 -4
  57. py2docfx/venv/venv1/Lib/site-packages/google/api/distribution_pb2.py +7 -5
  58. py2docfx/venv/venv1/Lib/site-packages/google/api/documentation_pb2.py +6 -3
  59. py2docfx/venv/venv1/Lib/site-packages/google/api/endpoint_pb2.py +6 -3
  60. py2docfx/venv/venv1/Lib/site-packages/google/api/error_reason_pb2.py +6 -3
  61. py2docfx/venv/venv1/Lib/site-packages/google/api/field_behavior_pb2.py +8 -6
  62. py2docfx/venv/venv1/Lib/site-packages/google/api/field_info_pb2.py +6 -4
  63. py2docfx/venv/venv1/Lib/site-packages/google/api/http_pb2.py +7 -4
  64. py2docfx/venv/venv1/Lib/site-packages/google/api/httpbody_pb2.py +6 -4
  65. py2docfx/venv/venv1/Lib/site-packages/google/api/label_pb2.py +7 -4
  66. py2docfx/venv/venv1/Lib/site-packages/google/api/launch_stage_pb2.py +6 -3
  67. py2docfx/venv/venv1/Lib/site-packages/google/api/log_pb2.py +6 -4
  68. py2docfx/venv/venv1/Lib/site-packages/google/api/logging_pb2.py +6 -3
  69. py2docfx/venv/venv1/Lib/site-packages/google/api/metric_pb2.py +12 -9
  70. py2docfx/venv/venv1/Lib/site-packages/google/api/monitored_resource_pb2.py +15 -10
  71. py2docfx/venv/venv1/Lib/site-packages/google/api/monitoring_pb2.py +6 -3
  72. py2docfx/venv/venv1/Lib/site-packages/google/api/policy_pb2.py +7 -5
  73. py2docfx/venv/venv1/Lib/site-packages/google/api/quota_pb2.py +10 -7
  74. py2docfx/venv/venv1/Lib/site-packages/google/api/resource_pb2.py +7 -5
  75. py2docfx/venv/venv1/Lib/site-packages/google/api/routing_pb2.py +6 -4
  76. py2docfx/venv/venv1/Lib/site-packages/google/api/service_pb2.py +15 -12
  77. py2docfx/venv/venv1/Lib/site-packages/google/api/source_info_pb2.py +6 -4
  78. py2docfx/venv/venv1/Lib/site-packages/google/api/system_parameter_pb2.py +6 -3
  79. py2docfx/venv/venv1/Lib/site-packages/google/api/usage_pb2.py +6 -3
  80. py2docfx/venv/venv1/Lib/site-packages/google/api/visibility_pb2.py +7 -5
  81. py2docfx/venv/venv1/Lib/site-packages/google/cloud/extended_operations_pb2.py +6 -4
  82. py2docfx/venv/venv1/Lib/site-packages/google/cloud/location/locations_pb2.py +18 -13
  83. py2docfx/venv/venv1/Lib/site-packages/google/gapic/metadata/gapic_metadata_pb2.py +31 -26
  84. py2docfx/venv/venv1/Lib/site-packages/google/logging/type/http_request_pb2.py +6 -4
  85. py2docfx/venv/venv1/Lib/site-packages/google/logging/type/log_severity_pb2.py +6 -3
  86. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc.py +2 -1
  87. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_grpc_pb2.py +11 -10
  88. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2.py +20 -17
  89. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_pb2_grpc.py +1 -2
  90. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto.py +2 -1
  91. py2docfx/venv/venv1/Lib/site-packages/google/longrunning/operations_proto_pb2.py +22 -19
  92. py2docfx/venv/venv1/Lib/site-packages/google/rpc/code_pb2.py +6 -3
  93. py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/attribute_context_pb2.py +20 -16
  94. py2docfx/venv/venv1/Lib/site-packages/google/rpc/context/audit_context_pb2.py +7 -5
  95. py2docfx/venv/venv1/Lib/site-packages/google/rpc/error_details_pb2.py +21 -19
  96. py2docfx/venv/venv1/Lib/site-packages/google/rpc/http_pb2.py +6 -3
  97. py2docfx/venv/venv1/Lib/site-packages/google/rpc/status_pb2.py +6 -4
  98. py2docfx/venv/venv1/Lib/site-packages/google/type/calendar_period_pb2.py +6 -3
  99. py2docfx/venv/venv1/Lib/site-packages/google/type/color_pb2.py +6 -4
  100. py2docfx/venv/venv1/Lib/site-packages/google/type/date_pb2.py +6 -3
  101. py2docfx/venv/venv1/Lib/site-packages/google/type/datetime_pb2.py +6 -4
  102. py2docfx/venv/venv1/Lib/site-packages/google/type/dayofweek_pb2.py +6 -3
  103. py2docfx/venv/venv1/Lib/site-packages/google/type/decimal_pb2.py +6 -3
  104. py2docfx/venv/venv1/Lib/site-packages/google/type/expr_pb2.py +6 -3
  105. py2docfx/venv/venv1/Lib/site-packages/google/type/fraction_pb2.py +6 -3
  106. py2docfx/venv/venv1/Lib/site-packages/google/type/interval_pb2.py +6 -4
  107. py2docfx/venv/venv1/Lib/site-packages/google/type/latlng_pb2.py +6 -3
  108. py2docfx/venv/venv1/Lib/site-packages/google/type/localized_text_pb2.py +6 -3
  109. py2docfx/venv/venv1/Lib/site-packages/google/type/money_pb2.py +6 -3
  110. py2docfx/venv/venv1/Lib/site-packages/google/type/month_pb2.py +6 -3
  111. py2docfx/venv/venv1/Lib/site-packages/google/type/phone_number_pb2.py +6 -3
  112. py2docfx/venv/venv1/Lib/site-packages/google/type/postal_address_pb2.py +6 -3
  113. py2docfx/venv/venv1/Lib/site-packages/google/type/quaternion_pb2.py +6 -3
  114. py2docfx/venv/venv1/Lib/site-packages/google/type/timeofday_pb2.py +6 -3
  115. py2docfx/venv/venv1/Lib/site-packages/psutil/__init__.py +122 -201
  116. py2docfx/venv/venv1/Lib/site-packages/psutil/_common.py +84 -128
  117. py2docfx/venv/venv1/Lib/site-packages/psutil/_psaix.py +24 -38
  118. py2docfx/venv/venv1/Lib/site-packages/psutil/_psbsd.py +44 -58
  119. py2docfx/venv/venv1/Lib/site-packages/psutil/_pslinux.py +170 -254
  120. py2docfx/venv/venv1/Lib/site-packages/psutil/_psosx.py +8 -16
  121. py2docfx/venv/venv1/Lib/site-packages/psutil/_psposix.py +13 -49
  122. py2docfx/venv/venv1/Lib/site-packages/psutil/_pssunos.py +41 -60
  123. py2docfx/venv/venv1/Lib/site-packages/psutil/_pswindows.py +75 -145
  124. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/__init__.py +105 -193
  125. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_aix.py +2 -2
  126. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_bsd.py +27 -26
  127. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_connections.py +16 -17
  128. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_contracts.py +5 -19
  129. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_linux.py +153 -211
  130. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_memleaks.py +0 -6
  131. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_misc.py +22 -207
  132. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_osx.py +9 -4
  133. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_posix.py +8 -15
  134. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process.py +104 -184
  135. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_process_all.py +28 -36
  136. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_scripts.py +240 -0
  137. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_sunos.py +1 -1
  138. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_system.py +44 -50
  139. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_testutils.py +23 -33
  140. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_unicode.py +8 -67
  141. py2docfx/venv/venv1/Lib/site-packages/psutil/tests/test_windows.py +32 -52
  142. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/METADATA +1 -1
  143. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/RECORD +145 -145
  144. py2docfx/venv/venv1/Lib/site-packages/psutil/_compat.py +0 -477
  145. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/WHEEL +0 -0
  146. {py2docfx-0.1.11rc1981066.dist-info → py2docfx-0.1.11rc1997820.dist-info}/top_level.txt +0 -0
@@ -22,8 +22,6 @@ from ._common import isfile_strict
22
22
  from ._common import memoize_when_activated
23
23
  from ._common import parse_environ_block
24
24
  from ._common import usage_percent
25
- from ._compat import PermissionError
26
- from ._compat import ProcessLookupError
27
25
 
28
26
 
29
27
  __extra__all__ = []
@@ -114,8 +112,7 @@ def virtual_memory():
114
112
  """System virtual memory as a namedtuple."""
115
113
  total, active, inactive, wired, free, speculative = cext.virtual_mem()
116
114
  # This is how Zabbix calculate avail and used mem:
117
- # https://github.com/zabbix/zabbix/blob/trunk/src/libs/zbxsysinfo/
118
- # osx/memory.c
115
+ # https://github.com/zabbix/zabbix/blob/master/src/libs/zbxsysinfo/osx/memory.c
119
116
  # Also see: https://github.com/giampaolo/psutil/issues/1277
120
117
  avail = inactive + free
121
118
  used = active + wired
@@ -345,15 +342,15 @@ def wrap_exceptions(fun):
345
342
 
346
343
  @functools.wraps(fun)
347
344
  def wrapper(self, *args, **kwargs):
345
+ pid, ppid, name = self.pid, self._ppid, self._name
348
346
  try:
349
347
  return fun(self, *args, **kwargs)
350
- except ProcessLookupError:
351
- if is_zombie(self.pid):
352
- raise ZombieProcess(self.pid, self._name, self._ppid)
353
- else:
354
- raise NoSuchProcess(self.pid, self._name)
355
- except PermissionError:
356
- raise AccessDenied(self.pid, self._name)
348
+ except ProcessLookupError as err:
349
+ if is_zombie(pid):
350
+ raise ZombieProcess(pid, name, ppid) from err
351
+ raise NoSuchProcess(pid, name) from err
352
+ except PermissionError as err:
353
+ raise AccessDenied(pid, name) from err
357
354
 
358
355
  return wrapper
359
356
 
@@ -502,11 +499,6 @@ class Process:
502
499
 
503
500
  @wrap_exceptions
504
501
  def net_connections(self, kind='inet'):
505
- if kind not in conn_tmap:
506
- raise ValueError(
507
- "invalid %r kind argument; choose between %s"
508
- % (kind, ', '.join([repr(x) for x in conn_tmap]))
509
- )
510
502
  families, types = conn_tmap[kind]
511
503
  rawlist = cext.proc_net_connections(self.pid, families, types)
512
504
  ret = []
@@ -4,10 +4,10 @@
4
4
 
5
5
  """Routines common to all posix systems."""
6
6
 
7
+ import enum
7
8
  import glob
8
9
  import os
9
10
  import signal
10
- import sys
11
11
  import time
12
12
 
13
13
  from ._common import MACOS
@@ -15,25 +15,12 @@ from ._common import TimeoutExpired
15
15
  from ._common import memoize
16
16
  from ._common import sdiskusage
17
17
  from ._common import usage_percent
18
- from ._compat import PY3
19
- from ._compat import ChildProcessError
20
- from ._compat import FileNotFoundError
21
- from ._compat import InterruptedError
22
- from ._compat import PermissionError
23
- from ._compat import ProcessLookupError
24
- from ._compat import unicode
25
18
 
26
19
 
27
20
  if MACOS:
28
21
  from . import _psutil_osx
29
22
 
30
23
 
31
- if PY3:
32
- import enum
33
- else:
34
- enum = None
35
-
36
-
37
24
  __all__ = ['pid_exists', 'wait_pid', 'disk_usage', 'get_terminal_map']
38
25
 
39
26
 
@@ -59,23 +46,16 @@ def pid_exists(pid):
59
46
  return True
60
47
 
61
48
 
62
- # Python 3.5 signals enum (contributed by me ^^):
63
- # https://bugs.python.org/issue21076
64
- if enum is not None and hasattr(signal, "Signals"):
65
- Negsignal = enum.IntEnum(
66
- 'Negsignal', dict([(x.name, -x.value) for x in signal.Signals])
67
- )
68
-
69
- def negsig_to_enum(num):
70
- """Convert a negative signal value to an enum."""
71
- try:
72
- return Negsignal(num)
73
- except ValueError:
74
- return num
49
+ Negsignal = enum.IntEnum(
50
+ 'Negsignal', {x.name: -x.value for x in signal.Signals}
51
+ )
75
52
 
76
- else: # pragma: no cover
77
53
 
78
- def negsig_to_enum(num):
54
+ def negsig_to_enum(num):
55
+ """Convert a negative signal value to an enum."""
56
+ try:
57
+ return Negsignal(num)
58
+ except ValueError:
79
59
  return num
80
60
 
81
61
 
@@ -139,7 +119,7 @@ def wait_pid(
139
119
  # can't determine its exit status code.
140
120
  while _pid_exists(pid):
141
121
  interval = sleep(interval)
142
- return
122
+ return None
143
123
  else:
144
124
  if retpid == 0:
145
125
  # WNOHANG flag was used and PID is still running.
@@ -171,7 +151,8 @@ def wait_pid(
171
151
  # continue
172
152
  else:
173
153
  # Should never happen.
174
- raise ValueError("unknown process exit status %r" % status)
154
+ msg = f"unknown process exit status {status!r}"
155
+ raise ValueError(msg)
175
156
 
176
157
 
177
158
  def disk_usage(path):
@@ -181,24 +162,7 @@ def disk_usage(path):
181
162
  total and used disk space whereas "free" and "percent" represent
182
163
  the "free" and "used percent" user disk space.
183
164
  """
184
- if PY3:
185
- st = os.statvfs(path)
186
- else: # pragma: no cover
187
- # os.statvfs() does not support unicode on Python 2:
188
- # - https://github.com/giampaolo/psutil/issues/416
189
- # - http://bugs.python.org/issue18695
190
- try:
191
- st = os.statvfs(path)
192
- except UnicodeEncodeError:
193
- if isinstance(path, unicode):
194
- try:
195
- path = path.encode(sys.getfilesystemencoding())
196
- except UnicodeEncodeError:
197
- pass
198
- st = os.statvfs(path)
199
- else:
200
- raise
201
-
165
+ st = os.statvfs(path)
202
166
  # Total space which is only available to root (unless changed
203
167
  # at system level).
204
168
  total = st.f_blocks * st.f_frsize
@@ -18,6 +18,7 @@ from . import _psposix
18
18
  from . import _psutil_posix as cext_posix
19
19
  from . import _psutil_sunos as cext
20
20
  from ._common import AF_INET6
21
+ from ._common import ENCODING
21
22
  from ._common import AccessDenied
22
23
  from ._common import NoSuchProcess
23
24
  from ._common import ZombieProcess
@@ -28,11 +29,6 @@ from ._common import memoize_when_activated
28
29
  from ._common import sockfam_to_enum
29
30
  from ._common import socktype_to_enum
30
31
  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
- from ._compat import b
36
32
 
37
33
 
38
34
  __extra__all__ = ["CONN_IDLE", "CONN_BOUND", "PROCFS_PATH"]
@@ -147,17 +143,17 @@ def swap_memory():
147
143
  p = subprocess.Popen(
148
144
  [
149
145
  '/usr/bin/env',
150
- 'PATH=/usr/sbin:/sbin:%s' % os.environ['PATH'],
146
+ f"PATH=/usr/sbin:/sbin:{os.environ['PATH']}",
151
147
  'swap',
152
148
  '-l',
153
149
  ],
154
150
  stdout=subprocess.PIPE,
155
151
  )
156
152
  stdout, _ = p.communicate()
157
- if PY3:
158
- stdout = stdout.decode(sys.stdout.encoding)
153
+ stdout = stdout.decode(sys.stdout.encoding)
159
154
  if p.returncode != 0:
160
- raise RuntimeError("'swap -l' failed (retcode=%s)" % p.returncode)
155
+ msg = f"'swap -l' failed (retcode={p.returncode})"
156
+ raise RuntimeError(msg)
161
157
 
162
158
  lines = stdout.strip().split('\n')[1:]
163
159
  if not lines:
@@ -244,7 +240,7 @@ def disk_partitions(all=False):
244
240
  continue
245
241
  except OSError as err:
246
242
  # https://github.com/giampaolo/psutil/issues/1674
247
- debug("skipping %r: %s" % (mountpoint, err))
243
+ debug(f"skipping {mountpoint!r}: {err}")
248
244
  continue
249
245
  ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
250
246
  retlist.append(ntuple)
@@ -265,14 +261,6 @@ def net_connections(kind, _pid=-1):
265
261
  connections (as opposed to connections opened by one process only).
266
262
  Only INET sockets are returned (UNIX are not).
267
263
  """
268
- cmap = _common.conn_tmap.copy()
269
- if _pid == -1:
270
- cmap.pop('unix', 0)
271
- if kind not in cmap:
272
- raise ValueError(
273
- "invalid %r kind argument; choose between %s"
274
- % (kind, ', '.join([repr(x) for x in cmap]))
275
- )
276
264
  families, types = _common.conn_tmap[kind]
277
265
  rawlist = cext.net_connections(_pid)
278
266
  ret = set()
@@ -346,7 +334,8 @@ def users():
346
334
 
347
335
  def pids():
348
336
  """Returns a list of PIDs currently running on the system."""
349
- return [int(x) for x in os.listdir(b(get_procfs_path())) if x.isdigit()]
337
+ path = get_procfs_path().encode(ENCODING)
338
+ return [int(x) for x in os.listdir(path) if x.isdigit()]
350
339
 
351
340
 
352
341
  def pid_exists(pid):
@@ -361,24 +350,23 @@ def wrap_exceptions(fun):
361
350
 
362
351
  @functools.wraps(fun)
363
352
  def wrapper(self, *args, **kwargs):
353
+ pid, ppid, name = self.pid, self._ppid, self._name
364
354
  try:
365
355
  return fun(self, *args, **kwargs)
366
- except (FileNotFoundError, ProcessLookupError):
356
+ except (FileNotFoundError, ProcessLookupError) as err:
367
357
  # ENOENT (no such file or directory) gets raised on open().
368
358
  # ESRCH (no such process) can get raised on read() if
369
359
  # process is gone in meantime.
370
- if not pid_exists(self.pid):
371
- raise NoSuchProcess(self.pid, self._name)
372
- else:
373
- raise ZombieProcess(self.pid, self._name, self._ppid)
374
- except PermissionError:
375
- raise AccessDenied(self.pid, self._name)
376
- except OSError:
377
- if self.pid == 0:
360
+ if not pid_exists(pid):
361
+ raise NoSuchProcess(pid, name) from err
362
+ raise ZombieProcess(pid, name, ppid) from err
363
+ except PermissionError as err:
364
+ raise AccessDenied(pid, name) from err
365
+ except OSError as err:
366
+ if pid == 0:
378
367
  if 0 in pids():
379
- raise AccessDenied(self.pid, self._name)
380
- else:
381
- raise
368
+ raise AccessDenied(pid, name) from err
369
+ raise
382
370
  raise
383
371
 
384
372
  return wrapper
@@ -399,7 +387,7 @@ class Process:
399
387
  """Raise NSP if the process disappeared on us."""
400
388
  # For those C function who do not raise NSP, possibly returning
401
389
  # incorrect or incomplete result.
402
- os.stat('%s/%s' % (self._procfs_path, self.pid))
390
+ os.stat(f"{self._procfs_path}/{self.pid}")
403
391
 
404
392
  def oneshot_enter(self):
405
393
  self._proc_name_and_args.cache_activate(self)
@@ -420,7 +408,7 @@ class Process:
420
408
  @memoize_when_activated
421
409
  def _proc_basic_info(self):
422
410
  if self.pid == 0 and not os.path.exists(
423
- '%s/%s/psinfo' % (self._procfs_path, self.pid)
411
+ f"{self._procfs_path}/{self.pid}/psinfo"
424
412
  ):
425
413
  raise AccessDenied(self.pid)
426
414
  ret = cext.proc_basic_info(self.pid, self._procfs_path)
@@ -440,9 +428,7 @@ class Process:
440
428
  @wrap_exceptions
441
429
  def exe(self):
442
430
  try:
443
- return os.readlink(
444
- "%s/%s/path/a.out" % (self._procfs_path, self.pid)
445
- )
431
+ return os.readlink(f"{self._procfs_path}/{self.pid}/path/a.out")
446
432
  except OSError:
447
433
  pass # continue and guess the exe name from the cmdline
448
434
  # Will be guessed later from cmdline but we want to explicitly
@@ -539,9 +525,7 @@ class Process:
539
525
  if tty != cext.PRNODEV:
540
526
  for x in (0, 1, 2, 255):
541
527
  try:
542
- return os.readlink(
543
- '%s/%d/path/%d' % (procfs_path, self.pid, x)
544
- )
528
+ return os.readlink(f"{procfs_path}/{self.pid}/path/{x}")
545
529
  except FileNotFoundError:
546
530
  hit_enoent = True
547
531
  continue
@@ -553,12 +537,12 @@ class Process:
553
537
  # /proc/PID/path/cwd may not be resolved by readlink() even if
554
538
  # it exists (ls shows it). If that's the case and the process
555
539
  # is still alive return None (we can return None also on BSD).
556
- # Reference: http://goo.gl/55XgO
540
+ # Reference: https://groups.google.com/g/comp.unix.solaris/c/tcqvhTNFCAs
557
541
  procfs_path = self._procfs_path
558
542
  try:
559
- return os.readlink("%s/%s/path/cwd" % (procfs_path, self.pid))
543
+ return os.readlink(f"{procfs_path}/{self.pid}/path/cwd")
560
544
  except FileNotFoundError:
561
- os.stat("%s/%s" % (procfs_path, self.pid)) # raise NSP or AD
545
+ os.stat(f"{procfs_path}/{self.pid}") # raise NSP or AD
562
546
  return ""
563
547
 
564
548
  @wrap_exceptions
@@ -580,7 +564,7 @@ class Process:
580
564
  def threads(self):
581
565
  procfs_path = self._procfs_path
582
566
  ret = []
583
- tids = os.listdir('%s/%d/lwp' % (procfs_path, self.pid))
567
+ tids = os.listdir(f"{procfs_path}/{self.pid}/lwp")
584
568
  hit_enoent = False
585
569
  for tid in tids:
586
570
  tid = int(tid)
@@ -588,7 +572,7 @@ class Process:
588
572
  utime, stime = cext.query_process_thread(
589
573
  self.pid, tid, procfs_path
590
574
  )
591
- except EnvironmentError as err:
575
+ except OSError as err:
592
576
  if err.errno == errno.EOVERFLOW and not IS_64_BIT:
593
577
  # We may get here if we attempt to query a 64bit process
594
578
  # with a 32bit python.
@@ -615,8 +599,8 @@ class Process:
615
599
  retlist = []
616
600
  hit_enoent = False
617
601
  procfs_path = self._procfs_path
618
- pathdir = '%s/%d/path' % (procfs_path, self.pid)
619
- for fd in os.listdir('%s/%d/fd' % (procfs_path, self.pid)):
602
+ pathdir = f"{procfs_path}/{self.pid}/path"
603
+ for fd in os.listdir(f"{procfs_path}/{self.pid}/fd"):
620
604
  path = os.path.join(pathdir, fd)
621
605
  if os.path.islink(path):
622
606
  try:
@@ -640,16 +624,16 @@ class Process:
640
624
  cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
641
625
  )
642
626
  stdout, stderr = p.communicate()
643
- if PY3:
644
- stdout, stderr = (
645
- x.decode(sys.stdout.encoding) for x in (stdout, stderr)
646
- )
627
+ stdout, stderr = (
628
+ x.decode(sys.stdout.encoding) for x in (stdout, stderr)
629
+ )
647
630
  if p.returncode != 0:
648
631
  if 'permission denied' in stderr.lower():
649
632
  raise AccessDenied(self.pid, self._name)
650
633
  if 'no such process' in stderr.lower():
651
634
  raise NoSuchProcess(self.pid, self._name)
652
- raise RuntimeError("%r command error\n%s" % (cmd, stderr))
635
+ msg = f"{cmd!r} command error\n{stderr}"
636
+ raise RuntimeError(msg)
653
637
 
654
638
  lines = stdout.split('\n')[2:]
655
639
  for i, line in enumerate(lines):
@@ -675,7 +659,7 @@ class Process:
675
659
  # is no longer there.
676
660
  if not ret:
677
661
  # will raise NSP if process is gone
678
- os.stat('%s/%s' % (self._procfs_path, self.pid))
662
+ os.stat(f"{self._procfs_path}/{self.pid}")
679
663
 
680
664
  # UNIX sockets
681
665
  if kind in {'all', 'unix'}:
@@ -691,9 +675,8 @@ class Process:
691
675
  @wrap_exceptions
692
676
  def memory_maps(self):
693
677
  def toaddr(start, end):
694
- return '%s-%s' % (
695
- hex(start)[2:].strip('L'),
696
- hex(end)[2:].strip('L'),
678
+ return "{}-{}".format(
679
+ hex(start)[2:].strip('L'), hex(end)[2:].strip('L')
697
680
  )
698
681
 
699
682
  procfs_path = self._procfs_path
@@ -718,9 +701,7 @@ class Process:
718
701
  addr = toaddr(addr, addrsize)
719
702
  if not name.startswith('['):
720
703
  try:
721
- name = os.readlink(
722
- '%s/%s/path/%s' % (procfs_path, self.pid, name)
723
- )
704
+ name = os.readlink(f"{procfs_path}/{self.pid}/path/{name}")
724
705
  except OSError as err:
725
706
  if err.errno == errno.ENOENT:
726
707
  # sometimes the link may not be resolved by
@@ -729,7 +710,7 @@ class Process:
729
710
  # unresolved link path.
730
711
  # This seems an inconsistency with /proc similar
731
712
  # to: http://goo.gl/55XgO
732
- name = '%s/%s/path/%s' % (procfs_path, self.pid, name)
713
+ name = f"{procfs_path}/{self.pid}/path/{name}"
733
714
  hit_enoent = True
734
715
  else:
735
716
  raise
@@ -740,7 +721,7 @@ class Process:
740
721
 
741
722
  @wrap_exceptions
742
723
  def num_fds(self):
743
- return len(os.listdir("%s/%s/fd" % (self._procfs_path, self.pid)))
724
+ return len(os.listdir(f"{self._procfs_path}/{self.pid}/fd"))
744
725
 
745
726
  @wrap_exceptions
746
727
  def num_ctx_switches(self):