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
@@ -5,7 +5,7 @@
5
5
  """Windows platform implementation."""
6
6
 
7
7
  import contextlib
8
- import errno
8
+ import enum
9
9
  import functools
10
10
  import os
11
11
  import signal
@@ -15,7 +15,6 @@ from collections import namedtuple
15
15
 
16
16
  from . import _common
17
17
  from ._common import ENCODING
18
- from ._common import ENCODING_ERRS
19
18
  from ._common import AccessDenied
20
19
  from ._common import NoSuchProcess
21
20
  from ._common import TimeoutExpired
@@ -27,11 +26,6 @@ from ._common import memoize
27
26
  from ._common import memoize_when_activated
28
27
  from ._common import parse_environ_block
29
28
  from ._common import usage_percent
30
- from ._compat import PY3
31
- from ._compat import long
32
- from ._compat import lru_cache
33
- from ._compat import range
34
- from ._compat import unicode
35
29
  from ._psutil_windows import ABOVE_NORMAL_PRIORITY_CLASS
36
30
  from ._psutil_windows import BELOW_NORMAL_PRIORITY_CLASS
37
31
  from ._psutil_windows import HIGH_PRIORITY_CLASS
@@ -54,14 +48,10 @@ except ImportError as err:
54
48
  msg = "this Windows version is too old (< Windows Vista); "
55
49
  msg += "psutil 3.4.2 is the latest version which supports Windows "
56
50
  msg += "2000, XP and 2003 server"
57
- raise RuntimeError(msg)
51
+ raise RuntimeError(msg) from err
58
52
  else:
59
53
  raise
60
54
 
61
- if PY3:
62
- import enum
63
- else:
64
- enum = None
65
55
 
66
56
  # process priority constants, import from __init__.py:
67
57
  # http://msdn.microsoft.com/en-us/library/ms686219(v=vs.85).aspx
@@ -88,11 +78,8 @@ CONN_DELETE_TCB = "DELETE_TCB"
88
78
  ERROR_PARTIAL_COPY = 299
89
79
  PYPY = '__pypy__' in sys.builtin_module_names
90
80
 
91
- if enum is None:
92
- AF_LINK = -1
93
- else:
94
- AddressFamily = enum.IntEnum('AddressFamily', {'AF_LINK': -1})
95
- AF_LINK = AddressFamily.AF_LINK
81
+ AddressFamily = enum.IntEnum('AddressFamily', {'AF_LINK': -1})
82
+ AF_LINK = AddressFamily.AF_LINK
96
83
 
97
84
  TCP_STATUSES = {
98
85
  cext.MIB_TCP_STATE_ESTAB: _common.CONN_ESTABLISHED,
@@ -110,32 +97,27 @@ TCP_STATUSES = {
110
97
  cext.PSUTIL_CONN_NONE: _common.CONN_NONE,
111
98
  }
112
99
 
113
- if enum is not None:
114
100
 
115
- class Priority(enum.IntEnum):
116
- ABOVE_NORMAL_PRIORITY_CLASS = ABOVE_NORMAL_PRIORITY_CLASS
117
- BELOW_NORMAL_PRIORITY_CLASS = BELOW_NORMAL_PRIORITY_CLASS
118
- HIGH_PRIORITY_CLASS = HIGH_PRIORITY_CLASS
119
- IDLE_PRIORITY_CLASS = IDLE_PRIORITY_CLASS
120
- NORMAL_PRIORITY_CLASS = NORMAL_PRIORITY_CLASS
121
- REALTIME_PRIORITY_CLASS = REALTIME_PRIORITY_CLASS
101
+ class Priority(enum.IntEnum):
102
+ ABOVE_NORMAL_PRIORITY_CLASS = ABOVE_NORMAL_PRIORITY_CLASS
103
+ BELOW_NORMAL_PRIORITY_CLASS = BELOW_NORMAL_PRIORITY_CLASS
104
+ HIGH_PRIORITY_CLASS = HIGH_PRIORITY_CLASS
105
+ IDLE_PRIORITY_CLASS = IDLE_PRIORITY_CLASS
106
+ NORMAL_PRIORITY_CLASS = NORMAL_PRIORITY_CLASS
107
+ REALTIME_PRIORITY_CLASS = REALTIME_PRIORITY_CLASS
122
108
 
123
- globals().update(Priority.__members__)
124
109
 
125
- if enum is None:
110
+ globals().update(Priority.__members__)
111
+
112
+
113
+ class IOPriority(enum.IntEnum):
126
114
  IOPRIO_VERYLOW = 0
127
115
  IOPRIO_LOW = 1
128
116
  IOPRIO_NORMAL = 2
129
117
  IOPRIO_HIGH = 3
130
- else:
131
118
 
132
- class IOPriority(enum.IntEnum):
133
- IOPRIO_VERYLOW = 0
134
- IOPRIO_LOW = 1
135
- IOPRIO_NORMAL = 2
136
- IOPRIO_HIGH = 3
137
119
 
138
- globals().update(IOPriority.__members__)
120
+ globals().update(IOPriority.__members__)
139
121
 
140
122
  pinfo_map = dict(
141
123
  num_handles=0,
@@ -199,7 +181,7 @@ pio = namedtuple('pio', ['read_count', 'write_count',
199
181
  # =====================================================================
200
182
 
201
183
 
202
- @lru_cache(maxsize=512)
184
+ @functools.lru_cache(maxsize=512)
203
185
  def convert_dos_path(s):
204
186
  r"""Convert paths using native DOS format like:
205
187
  "\Device\HarddiskVolume1\Windows\systemew\file.txt"
@@ -212,18 +194,6 @@ def convert_dos_path(s):
212
194
  return os.path.join(driveletter, remainder)
213
195
 
214
196
 
215
- def py2_strencode(s):
216
- """Encode a unicode string to a byte string by using the default fs
217
- encoding + "replace" error handler.
218
- """
219
- if PY3:
220
- return s
221
- if isinstance(s, str):
222
- return s
223
- else:
224
- return s.encode(ENCODING, ENCODING_ERRS)
225
-
226
-
227
197
  @memoize
228
198
  def getpagesize():
229
199
  return cext.getpagesize()
@@ -282,7 +252,7 @@ disk_io_counters = cext.disk_io_counters
282
252
 
283
253
  def disk_usage(path):
284
254
  """Return disk usage associated with path."""
285
- if PY3 and isinstance(path, bytes):
255
+ if isinstance(path, bytes):
286
256
  # XXX: do we want to use "strict"? Probably yes, in order
287
257
  # to fail immediately. After all we are accepting input here...
288
258
  path = path.decode(ENCODING, errors="strict")
@@ -367,7 +337,7 @@ def getloadavg():
367
337
 
368
338
  # Drop to 2 decimal points which is what Linux does
369
339
  raw_loads = cext.getloadavg()
370
- return tuple([round(load, 2) for load in raw_loads])
340
+ return tuple(round(load, 2) for load in raw_loads)
371
341
 
372
342
 
373
343
  # =====================================================================
@@ -379,11 +349,6 @@ def net_connections(kind, _pid=-1):
379
349
  """Return socket connections. If pid == -1 return system-wide
380
350
  connections (as opposed to connections opened by one process only).
381
351
  """
382
- if kind not in conn_tmap:
383
- raise ValueError(
384
- "invalid %r kind argument; choose between %s"
385
- % (kind, ', '.join([repr(x) for x in conn_tmap]))
386
- )
387
352
  families, types = conn_tmap[kind]
388
353
  rawlist = cext.net_connections(_pid, families, types)
389
354
  ret = set()
@@ -408,9 +373,6 @@ def net_if_stats():
408
373
  ret = {}
409
374
  rawdict = cext.net_if_stats()
410
375
  for name, items in rawdict.items():
411
- if not PY3:
412
- assert isinstance(name, unicode), type(name)
413
- name = py2_strencode(name)
414
376
  isup, duplex, speed, mtu = items
415
377
  if hasattr(_common, 'NicDuplex'):
416
378
  duplex = _common.NicDuplex(duplex)
@@ -422,18 +384,12 @@ def net_io_counters():
422
384
  """Return network I/O statistics for every network interface
423
385
  installed on the system as a dict of raw tuples.
424
386
  """
425
- ret = cext.net_io_counters()
426
- return dict([(py2_strencode(k), v) for k, v in ret.items()])
387
+ return cext.net_io_counters()
427
388
 
428
389
 
429
390
  def net_if_addrs():
430
391
  """Return the addresses associated to each NIC."""
431
- ret = []
432
- for items in cext.net_if_addrs():
433
- items = list(items)
434
- items[0] = py2_strencode(items[0])
435
- ret.append(items)
436
- return ret
392
+ return cext.net_if_addrs()
437
393
 
438
394
 
439
395
  # =====================================================================
@@ -489,7 +445,6 @@ def users():
489
445
  rawlist = cext.users()
490
446
  for item in rawlist:
491
447
  user, hostname, tstamp = item
492
- user = py2_strencode(user)
493
448
  nt = _common.suser(user, None, hostname, tstamp, None)
494
449
  retlist.append(nt)
495
450
  return retlist
@@ -503,7 +458,7 @@ def users():
503
458
  def win_service_iter():
504
459
  """Yields a list of WindowsService instances."""
505
460
  for name, display_name in cext.winservice_enumerate():
506
- yield WindowsService(py2_strencode(name), py2_strencode(display_name))
461
+ yield WindowsService(name, display_name)
507
462
 
508
463
 
509
464
  def win_service_get(name):
@@ -521,14 +476,11 @@ class WindowsService: # noqa: PLW1641
521
476
  self._display_name = display_name
522
477
 
523
478
  def __str__(self):
524
- details = "(name=%r, display_name=%r)" % (
525
- self._name,
526
- self._display_name,
527
- )
528
- return "%s%s" % (self.__class__.__name__, details)
479
+ details = f"(name={self._name!r}, display_name={self._display_name!r})"
480
+ return f"{self.__class__.__name__}{details}"
529
481
 
530
482
  def __repr__(self):
531
- return "<%s at %s>" % (self.__str__(), id(self))
483
+ return f"<{self.__str__()} at {id(self)}>"
532
484
 
533
485
  def __eq__(self, other):
534
486
  # Test for equality with another WindosService object based
@@ -547,10 +499,10 @@ class WindowsService: # noqa: PLW1641
547
499
  )
548
500
  # XXX - update _self.display_name?
549
501
  return dict(
550
- display_name=py2_strencode(display_name),
551
- binpath=py2_strencode(binpath),
552
- username=py2_strencode(username),
553
- start_type=py2_strencode(start_type),
502
+ display_name=display_name,
503
+ binpath=binpath,
504
+ username=username,
505
+ start_type=start_type,
554
506
  )
555
507
 
556
508
  def _query_status(self):
@@ -568,18 +520,18 @@ class WindowsService: # noqa: PLW1641
568
520
  try:
569
521
  yield
570
522
  except OSError as err:
523
+ name = self._name
571
524
  if is_permission_err(err):
572
525
  msg = (
573
- "service %r is not querable (not enough privileges)"
574
- % self._name
526
+ f"service {name!r} is not querable (not enough privileges)"
575
527
  )
576
- raise AccessDenied(pid=None, name=self._name, msg=msg)
528
+ raise AccessDenied(pid=None, name=name, msg=msg) from err
577
529
  elif err.winerror in {
578
530
  cext.ERROR_INVALID_NAME,
579
531
  cext.ERROR_SERVICE_DOES_NOT_EXIST,
580
532
  }:
581
- msg = "service %r does not exist" % self._name
582
- raise NoSuchProcess(pid=None, name=self._name, msg=msg)
533
+ msg = f"service {name!r} does not exist"
534
+ raise NoSuchProcess(pid=None, name=name, msg=msg) from err
583
535
  else:
584
536
  raise
585
537
 
@@ -628,7 +580,7 @@ class WindowsService: # noqa: PLW1641
628
580
 
629
581
  def description(self):
630
582
  """Service long description."""
631
- return py2_strencode(cext.winservice_query_descr(self.name()))
583
+ return cext.winservice_query_descr(self.name())
632
584
 
633
585
  # utils
634
586
 
@@ -696,12 +648,7 @@ ppid_map = cext.ppid_map # used internally by Process.children()
696
648
  def is_permission_err(exc):
697
649
  """Return True if this is a permission error."""
698
650
  assert isinstance(exc, OSError), exc
699
- if exc.errno in {errno.EPERM, errno.EACCES}:
700
- return True
701
- # On Python 2 OSError doesn't always have 'winerror'. Sometimes
702
- # it does, in which case the original exception was WindowsError
703
- # (which is a subclass of OSError).
704
- return getattr(exc, "winerror", -1) in {
651
+ return isinstance(exc, PermissionError) or exc.winerror in {
705
652
  cext.ERROR_ACCESS_DENIED,
706
653
  cext.ERROR_PRIVILEGE_NOT_HELD,
707
654
  }
@@ -712,7 +659,7 @@ def convert_oserror(exc, pid=None, name=None):
712
659
  assert isinstance(exc, OSError), exc
713
660
  if is_permission_err(exc):
714
661
  return AccessDenied(pid=pid, name=name)
715
- if exc.errno == errno.ESRCH:
662
+ if isinstance(exc, ProcessLookupError):
716
663
  return NoSuchProcess(pid=pid, name=name)
717
664
  raise exc
718
665
 
@@ -725,7 +672,7 @@ def wrap_exceptions(fun):
725
672
  try:
726
673
  return fun(self, *args, **kwargs)
727
674
  except OSError as err:
728
- raise convert_oserror(err, pid=self.pid, name=self._name)
675
+ raise convert_oserror(err, pid=self.pid, name=self._name) from err
729
676
 
730
677
  return wrapper
731
678
 
@@ -742,7 +689,7 @@ def retry_error_partial_copy(fun):
742
689
  for _ in range(times): # retries for roughly 1 second
743
690
  try:
744
691
  return fun(self, *args, **kwargs)
745
- except WindowsError as _:
692
+ except OSError as _:
746
693
  err = _
747
694
  if err.winerror == ERROR_PARTIAL_COPY:
748
695
  time.sleep(delay)
@@ -750,8 +697,8 @@ def retry_error_partial_copy(fun):
750
697
  continue
751
698
  raise
752
699
  msg = (
753
- "{} retried {} times, converted to AccessDenied as it's still"
754
- "returning {}".format(fun, times, err)
700
+ f"{fun} retried {times} times, converted to AccessDenied as it's "
701
+ f"still returning {err}"
755
702
  )
756
703
  raise AccessDenied(pid=self.pid, name=self._name, msg=msg)
757
704
 
@@ -805,17 +752,15 @@ class Process:
805
752
  if PYPY:
806
753
  try:
807
754
  exe = cext.proc_exe(self.pid)
808
- except WindowsError as err:
755
+ except OSError as err:
809
756
  # 24 = ERROR_TOO_MANY_OPEN_FILES. Not sure why this happens
810
757
  # (perhaps PyPy's JIT delaying garbage collection of files?).
811
758
  if err.errno == 24:
812
- debug("%r translated into AccessDenied" % err)
813
- raise AccessDenied(self.pid, self._name)
759
+ debug(f"{err!r} translated into AccessDenied")
760
+ raise AccessDenied(self.pid, self._name) from err
814
761
  raise
815
762
  else:
816
763
  exe = cext.proc_exe(self.pid)
817
- if not PY3:
818
- exe = py2_strencode(exe)
819
764
  if exe.startswith('\\'):
820
765
  return convert_dos_path(exe)
821
766
  return exe # May be "Registry", "MemCompression", ...
@@ -827,32 +772,26 @@ class Process:
827
772
  # PEB method detects cmdline changes but requires more
828
773
  # privileges: https://github.com/giampaolo/psutil/pull/1398
829
774
  try:
830
- ret = cext.proc_cmdline(self.pid, use_peb=True)
775
+ return cext.proc_cmdline(self.pid, use_peb=True)
831
776
  except OSError as err:
832
777
  if is_permission_err(err):
833
- ret = cext.proc_cmdline(self.pid, use_peb=False)
778
+ return cext.proc_cmdline(self.pid, use_peb=False)
834
779
  else:
835
780
  raise
836
781
  else:
837
- ret = cext.proc_cmdline(self.pid, use_peb=True)
838
- if PY3:
839
- return ret
840
- else:
841
- return [py2_strencode(s) for s in ret]
782
+ return cext.proc_cmdline(self.pid, use_peb=True)
842
783
 
843
784
  @wrap_exceptions
844
785
  @retry_error_partial_copy
845
786
  def environ(self):
846
- ustr = cext.proc_environ(self.pid)
847
- if ustr and not PY3:
848
- assert isinstance(ustr, unicode), type(ustr)
849
- return parse_environ_block(py2_strencode(ustr))
787
+ s = cext.proc_environ(self.pid)
788
+ return parse_environ_block(s)
850
789
 
851
790
  def ppid(self):
852
791
  try:
853
792
  return ppid_map()[self.pid]
854
793
  except KeyError:
855
- raise NoSuchProcess(self.pid, self._name)
794
+ raise NoSuchProcess(self.pid, self._name) from None
856
795
 
857
796
  def _get_raw_meminfo(self):
858
797
  try:
@@ -900,12 +839,10 @@ class Process:
900
839
  except OSError as err:
901
840
  # XXX - can't use wrap_exceptions decorator as we're
902
841
  # returning a generator; probably needs refactoring.
903
- raise convert_oserror(err, self.pid, self._name)
842
+ raise convert_oserror(err, self.pid, self._name) from err
904
843
  else:
905
844
  for addr, perm, path, rss in raw:
906
845
  path = convert_dos_path(path)
907
- if not PY3:
908
- path = py2_strencode(path)
909
846
  addr = hex(addr)
910
847
  yield (addr, perm, path, rss)
911
848
 
@@ -917,11 +854,7 @@ class Process:
917
854
  def send_signal(self, sig):
918
855
  if sig == signal.SIGTERM:
919
856
  cext.proc_kill(self.pid)
920
- # py >= 2.7
921
- elif sig in {
922
- getattr(signal, "CTRL_C_EVENT", object()),
923
- getattr(signal, "CTRL_BREAK_EVENT", object()),
924
- }:
857
+ elif sig in {signal.CTRL_C_EVENT, signal.CTRL_BREAK_EVENT}:
925
858
  os.kill(self.pid, sig)
926
859
  else:
927
860
  msg = (
@@ -946,9 +879,9 @@ class Process:
946
879
  # May also be None if OpenProcess() failed with
947
880
  # ERROR_INVALID_PARAMETER, meaning PID is already gone.
948
881
  exit_code = cext.proc_wait(self.pid, cext_timeout)
949
- except cext.TimeoutExpired:
882
+ except cext.TimeoutExpired as err:
950
883
  # WaitForSingleObject() returned WAIT_TIMEOUT. Just raise.
951
- raise TimeoutExpired(timeout, self.pid, self._name)
884
+ raise TimeoutExpired(timeout, self.pid, self._name) from err
952
885
  except cext.TimeoutAbandoned:
953
886
  # WaitForSingleObject() returned WAIT_ABANDONED, see:
954
887
  # https://github.com/giampaolo/psutil/issues/1224
@@ -978,7 +911,7 @@ class Process:
978
911
  if self.pid in {0, 4}:
979
912
  return 'NT AUTHORITY\\SYSTEM'
980
913
  domain, user = cext.proc_username(self.pid)
981
- return py2_strencode(domain) + '\\' + py2_strencode(user)
914
+ return f"{domain}\\{user}"
982
915
 
983
916
  @wrap_exceptions
984
917
  def create_time(self, fast_only=False):
@@ -1038,7 +971,7 @@ class Process:
1038
971
  # return a normalized pathname since the native C function appends
1039
972
  # "\\" at the and of the path
1040
973
  path = cext.proc_cwd(self.pid)
1041
- return py2_strencode(os.path.normpath(path))
974
+ return os.path.normpath(path)
1042
975
 
1043
976
  @wrap_exceptions
1044
977
  def open_files(self):
@@ -1050,12 +983,10 @@ class Process:
1050
983
  # Convert the first part in the corresponding drive letter
1051
984
  # (e.g. "C:\") by using Windows's QueryDosDevice()
1052
985
  raw_file_names = cext.proc_open_files(self.pid)
1053
- for _file in raw_file_names:
1054
- _file = convert_dos_path(_file)
1055
- if isfile_strict(_file):
1056
- if not PY3:
1057
- _file = py2_strencode(_file)
1058
- ntuple = _common.popenfile(_file, -1)
986
+ for file in raw_file_names:
987
+ file = convert_dos_path(file)
988
+ if isfile_strict(file):
989
+ ntuple = _common.popenfile(file, -1)
1059
990
  ret.add(ntuple)
1060
991
  return list(ret)
1061
992
 
@@ -1066,8 +997,7 @@ class Process:
1066
997
  @wrap_exceptions
1067
998
  def nice_get(self):
1068
999
  value = cext.proc_priority_get(self.pid)
1069
- if enum is not None:
1070
- value = Priority(value)
1000
+ value = Priority(value)
1071
1001
  return value
1072
1002
 
1073
1003
  @wrap_exceptions
@@ -1077,8 +1007,7 @@ class Process:
1077
1007
  @wrap_exceptions
1078
1008
  def ionice_get(self):
1079
1009
  ret = cext.proc_io_priority_get(self.pid)
1080
- if enum is not None:
1081
- ret = IOPriority(ret)
1010
+ ret = IOPriority(ret)
1082
1011
  return ret
1083
1012
 
1084
1013
  @wrap_exceptions
@@ -1087,12 +1016,13 @@ class Process:
1087
1016
  msg = "value argument not accepted on Windows"
1088
1017
  raise TypeError(msg)
1089
1018
  if ioclass not in {
1090
- IOPRIO_VERYLOW,
1091
- IOPRIO_LOW,
1092
- IOPRIO_NORMAL,
1093
- IOPRIO_HIGH,
1019
+ IOPriority.IOPRIO_VERYLOW,
1020
+ IOPriority.IOPRIO_LOW,
1021
+ IOPriority.IOPRIO_NORMAL,
1022
+ IOPriority.IOPRIO_HIGH,
1094
1023
  }:
1095
- raise ValueError("%s is not a valid priority" % ioclass)
1024
+ msg = f"{ioclass} is not a valid priority"
1025
+ raise ValueError(msg)
1096
1026
  cext.proc_io_priority_set(self.pid, ioclass)
1097
1027
 
1098
1028
  @wrap_exceptions
@@ -1134,7 +1064,8 @@ class Process:
1134
1064
  def cpu_affinity_set(self, value):
1135
1065
  def to_bitmask(ls):
1136
1066
  if not ls:
1137
- raise ValueError("invalid argument %r" % ls)
1067
+ msg = f"invalid argument {ls!r}"
1068
+ raise ValueError(msg)
1138
1069
  out = 0
1139
1070
  for b in ls:
1140
1071
  out |= 2**b
@@ -1146,12 +1077,11 @@ class Process:
1146
1077
  allcpus = list(range(len(per_cpu_times())))
1147
1078
  for cpu in value:
1148
1079
  if cpu not in allcpus:
1149
- if not isinstance(cpu, (int, long)):
1150
- raise TypeError(
1151
- "invalid CPU %r; an integer is required" % cpu
1152
- )
1153
- else:
1154
- raise ValueError("invalid CPU %r" % cpu)
1080
+ if not isinstance(cpu, int):
1081
+ msg = f"invalid CPU {cpu!r}; an integer is required"
1082
+ raise TypeError(msg)
1083
+ msg = f"invalid CPU {cpu!r}"
1084
+ raise ValueError(msg)
1155
1085
 
1156
1086
  bitmask = to_bitmask(value)
1157
1087
  cext.proc_cpu_affinity_set(self.pid, bitmask)