Skip to content

Commit 02db60a

Browse files
authored
Merge pull request #5926 from fstagni/80_fixes20
[8.0] Removing python2 support from RMS
2 parents c4f845f + 0b70512 commit 02db60a

File tree

10 files changed

+66
-94
lines changed

10 files changed

+66
-94
lines changed

src/DIRAC/ConfigurationSystem/private/TornadoRefresher.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from six import PY3
21
import time
32

43
from tornado import gen
@@ -74,13 +73,7 @@ def __refreshLoop(self):
7473
# Publish step is blocking so we have to run it in executor
7574
# If we are not doing it, when master try to ping we block the IOLoop
7675

77-
# When switching from python 2 to python 3, the following error occurs:
78-
# RuntimeError: There is no current event loop in thread..
79-
# The reason seems to be that asyncio.get_event_loop() is called in some thread other than the main thread,
80-
# asyncio only generates an event loop for the main thread.
81-
yield _IOLoop.current().run_in_executor(
82-
None, self.__AutoRefresh if PY3 else gen.coroutine(self.__AutoRefresh)
83-
)
76+
yield _IOLoop.current().run_in_executor(None, self.__AutoRefresh)
8477

8578
def __AutoRefresh(self):
8679
"""

src/DIRAC/Core/Tornado/Client/private/TornadoBaseClient.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import errno
2929
import os
3030
import requests
31-
import six
3231
import tempfile
3332
from http import HTTPStatus
3433

@@ -92,7 +91,7 @@ def __init__(self, serviceName, **kwargs):
9291
:param keepAliveLapse: Duration for keepAliveLapse (heartbeat like) (now managed by requests)
9392
"""
9493

95-
if not isinstance(serviceName, six.string_types):
94+
if not isinstance(serviceName, str):
9695
raise TypeError(
9796
"Service name expected to be a string. Received %s type %s" % (str(serviceName), type(serviceName))
9897
)

src/DIRAC/RequestManagementSystem/Client/File.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import datetime
1717
import os
1818
import json
19-
import six
2019

2120
from DIRAC import S_OK, S_ERROR
2221
from DIRAC.Core.Utilities.File import checkGuid
@@ -69,18 +68,11 @@ def __init__(self, fromDict=None):
6968
# because of the json initialization or not
7069
self.initialLoading = True
7170

72-
fromDict = (
73-
fromDict
74-
if isinstance(fromDict, dict)
75-
else json.loads(fromDict)
76-
if isinstance(fromDict, six.string_types)
77-
else {}
78-
)
71+
fromDict = fromDict if isinstance(fromDict, dict) else json.loads(fromDict) if isinstance(fromDict, str) else {}
7972

8073
for attrName, attrValue in fromDict.items():
8174
# The JSON module forces the use of UTF-8, which is not properly
8275
# taken into account in DIRAC.
83-
# One would need to replace all the '== str' with 'in six.string_types'
8476
# This is converting `unicode` to `str` and doesn't make sense in Python 3
8577
if attrValue:
8678
setattr(self, attrName, attrValue)
@@ -95,7 +87,7 @@ def LFN(self):
9587
@LFN.setter
9688
def LFN(self, value):
9789
"""lfn setter"""
98-
if not isinstance(value, six.string_types):
90+
if not isinstance(value, str):
9991
raise TypeError("LFN has to be a string!")
10092
if not os.path.isabs(value):
10193
raise ValueError("LFN should be an absolute path!")
@@ -110,7 +102,7 @@ def GUID(self):
110102
def GUID(self, value):
111103
"""GUID setter"""
112104
if value:
113-
if not isinstance(value, six.string_types):
105+
if not isinstance(value, str):
114106
raise TypeError("GUID should be a string!")
115107
if not checkGuid(value):
116108
raise ValueError("'%s' is not a valid GUID!" % str(value))

src/DIRAC/RequestManagementSystem/Client/Operation.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# pylint: disable=invalid-name
1616
import datetime
1717
import json
18-
import six
1918

2019
# # from DIRAC
2120
from DIRAC import S_OK, S_ERROR
@@ -24,7 +23,7 @@
2423

2524

2625
########################################################################
27-
class Operation(object):
26+
class Operation:
2827
"""
2928
:param int OperationID: OperationID as read from DB backend
3029
:param int RequestID: parent RequestID
@@ -95,7 +94,7 @@ def __init__(self, fromDict=None):
9594
self.Type = None
9695
self._Catalog = None
9796

98-
if isinstance(fromDict, six.string_types):
97+
if isinstance(fromDict, str):
9998
fromDict = json.loads(fromDict)
10099
elif not isinstance(fromDict, dict):
101100
fromDict = {}
@@ -223,7 +222,7 @@ def Arguments(self):
223222

224223
@Arguments.setter
225224
def Arguments(self, value):
226-
if isinstance(value, six.text_type):
225+
if isinstance(value, str):
227226
value = value.encode()
228227
if not isinstance(value, bytes):
229228
raise TypeError("Arguments should be bytes!")
@@ -237,9 +236,9 @@ def Catalog(self):
237236
@Catalog.setter
238237
def Catalog(self, value):
239238
"""catalog setter"""
240-
if not isinstance(value, six.string_types + (list,)):
239+
if not isinstance(value, (str, list)):
241240
raise TypeError("wrong type for value")
242-
if isinstance(value, six.string_types):
241+
if isinstance(value, str):
243242
value = value.split(",")
244243

245244
value = ",".join(list(set([str(item).strip() for item in value if str(item).strip()])))
@@ -297,9 +296,9 @@ def CreationTime(self):
297296
@CreationTime.setter
298297
def CreationTime(self, value=None):
299298
"""creation time setter"""
300-
if not isinstance(value, (datetime.datetime,) + six.string_types):
299+
if not isinstance(value, (datetime.datetime, str)):
301300
raise TypeError("CreationTime should be a datetime.datetime!")
302-
if isinstance(value, six.string_types):
301+
if isinstance(value, str):
303302
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
304303
self._CreationTime = value
305304

@@ -311,9 +310,9 @@ def SubmitTime(self):
311310
@SubmitTime.setter
312311
def SubmitTime(self, value=None):
313312
"""submit time setter"""
314-
if not isinstance(value, (datetime.datetime,) + six.string_types):
313+
if not isinstance(value, (datetime.datetime, str)):
315314
raise TypeError("SubmitTime should be a datetime.datetime!")
316-
if isinstance(value, six.string_types):
315+
if isinstance(value, str):
317316
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
318317
self._SubmitTime = value
319318

@@ -325,9 +324,9 @@ def LastUpdate(self):
325324
@LastUpdate.setter
326325
def LastUpdate(self, value=None):
327326
"""last update setter"""
328-
if not isinstance(value, (datetime.datetime,) + six.string_types):
327+
if not isinstance(value, (datetime.datetime, str)):
329328
raise TypeError("LastUpdate should be a datetime.datetime!")
330-
if isinstance(value, six.string_types):
329+
if isinstance(value, str):
331330
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
332331
self._LastUpdate = value
333332
if self._parent:

src/DIRAC/RequestManagementSystem/Client/ReqClient.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
:synopsis: implementation of client for RequestDB using DISET framework
66
77
"""
8-
import six
98
import os
109
import time
1110
import random
@@ -257,7 +256,7 @@ def getRequestStatus(self, requestID):
257256
:param self: self reference
258257
:param int requestID: id of the request
259258
"""
260-
if isinstance(requestID, six.string_types):
259+
if isinstance(requestID, str):
261260
requestID = int(requestID)
262261
self.log.debug("getRequestStatus: attempting to get status for '%d' request." % requestID)
263262
requestStatus = self._getRPC().getRequestStatus(requestID)
@@ -502,7 +501,7 @@ def prettyPrint(mainItem, key="", offset=0):
502501
for item in mainItem:
503502
prettyPrint(item, offset=offset + 2)
504503
output += "%s%s\n" % (blanks, "]" if isinstance(mainItem, list) else ")")
505-
elif isinstance(mainItem, six.string_types):
504+
elif isinstance(mainItem, str):
506505
if "\n" in mainItem:
507506
prettyPrint(mainItem.strip("\n").split("\n"), offset=offset)
508507
else:

src/DIRAC/RequestManagementSystem/Client/Request.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# # imports
1616
import datetime
1717
import json
18-
import six
1918

2019
# # from DIRAC
2120
from DIRAC import S_OK, S_ERROR
@@ -26,7 +25,7 @@
2625

2726

2827
########################################################################
29-
class Request(object):
28+
class Request:
3029
"""
3130
:param int RequestID: requestID
3231
:param str Name: request' name
@@ -88,7 +87,7 @@ def __init__(self, fromDict=None):
8887

8988
self.__operations__ = []
9089

91-
if isinstance(fromDict, six.string_types):
90+
if isinstance(fromDict, str):
9291
fromDict = json.loads(fromDict)
9392
elif not isinstance(fromDict, dict):
9493
fromDict = {}
@@ -272,7 +271,7 @@ def SourceComponent(self):
272271

273272
@SourceComponent.setter
274273
def SourceComponent(self, value):
275-
if isinstance(value, six.text_type):
274+
if isinstance(value, str):
276275
value = value.encode()
277276
if not isinstance(value, bytes):
278277
raise TypeError("SourceComponent should be bytes!")
@@ -286,9 +285,9 @@ def CreationTime(self):
286285
@CreationTime.setter
287286
def CreationTime(self, value=None):
288287
"""creation time setter"""
289-
if not isinstance(value, (datetime.datetime,) + six.string_types):
288+
if not isinstance(value, (datetime.datetime, str)):
290289
raise TypeError("CreationTime should be a datetime.datetime!")
291-
if isinstance(value, six.string_types):
290+
if isinstance(value, str):
292291
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
293292
self._CreationTime = value
294293

@@ -300,9 +299,9 @@ def SubmitTime(self):
300299
@SubmitTime.setter
301300
def SubmitTime(self, value=None):
302301
"""submission time setter"""
303-
if not isinstance(value, (datetime.datetime,) + six.string_types):
302+
if not isinstance(value, (datetime.datetime, str)):
304303
raise TypeError("SubmitTime should be a datetime.datetime!")
305-
if isinstance(value, six.string_types):
304+
if isinstance(value, str):
306305
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
307306
self._SubmitTime = value
308307

@@ -314,9 +313,9 @@ def NotBefore(self):
314313
@NotBefore.setter
315314
def NotBefore(self, value=None):
316315
"""Setter for the NotBefore time"""
317-
if not isinstance(value, (type(None), datetime.datetime) + six.string_types):
316+
if not isinstance(value, (type(None), datetime.datetime, str)):
318317
raise TypeError("NotBefore should be a datetime.datetime!")
319-
if isinstance(value, six.string_types):
318+
if isinstance(value, str):
320319
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
321320
self._NotBefore = value
322321

@@ -340,9 +339,9 @@ def LastUpdate(self):
340339
@LastUpdate.setter
341340
def LastUpdate(self, value=None):
342341
"""last update setter"""
343-
if not isinstance(value, (datetime.datetime,) + six.string_types):
342+
if not isinstance(value, (datetime.datetime, str)):
344343
raise TypeError("LastUpdate should be a datetime.datetime!")
345-
if isinstance(value, six.string_types):
344+
if isinstance(value, str):
346345
value = datetime.datetime.strptime(value.split(".")[0], self._datetimeFormat)
347346
self._LastUpdate = value
348347

@@ -356,7 +355,7 @@ def Status(self):
356355
def Status(self, value):
357356
"""status setter"""
358357
if value not in Request.ALL_STATES:
359-
raise ValueError("Unknown status: %s" % str(value))
358+
raise ValueError(f"Unknown status: {value}")
360359

361360
# If the status moved to Failed or Done, update the lastUpdate time
362361
if value in ("Done", "Failed"):

src/DIRAC/RequestManagementSystem/Client/test/Test_Request.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import datetime
1212

13-
import six
14-
1513
from DIRAC.RequestManagementSystem.Client.Operation import Operation
1614
from DIRAC.RequestManagementSystem.Client.File import File
1715
from DIRAC.RequestManagementSystem.Client.Request import Request
@@ -22,7 +20,7 @@ def optimizeRequest(req, printOutput=None):
2220
from DIRAC import gLogger
2321

2422
if printOutput:
25-
if isinstance(printOutput, six.string_types):
23+
if isinstance(printOutput, str):
2624
gLogger.always("Request %s:" % printOutput)
2725
printRequest(req)
2826
gLogger.always("=========== Optimized ===============")

src/DIRAC/RequestManagementSystem/DB/RequestDB.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
1616
db holding Request, Operation and File
1717
"""
18-
import six
1918
import errno
2019
import random
2120

@@ -789,7 +788,7 @@ def getRequestIDsForJobs(self, jobIDs):
789788
self.log.debug("getRequestIDsForJobs: got %s jobIDs to check" % str(jobIDs))
790789
if not jobIDs:
791790
return S_ERROR("Must provide jobID list as argument.")
792-
if isinstance(jobIDs, six.integer_types):
791+
if isinstance(jobIDs, int):
793792
jobIDs = [jobIDs]
794793
jobIDs = set(jobIDs)
795794

@@ -820,7 +819,7 @@ def readRequestsForJobs(self, jobIDs=None):
820819
self.log.debug("readRequestForJobs: got %s jobIDs to check" % str(jobIDs))
821820
if not jobIDs:
822821
return S_ERROR("Must provide jobID list as argument.")
823-
if isinstance(jobIDs, six.integer_types):
822+
if isinstance(jobIDs, int):
824823
jobIDs = [jobIDs]
825824
jobIDs = set(jobIDs)
826825

0 commit comments

Comments
 (0)