Skip to content

Commit b13cca1

Browse files
committed
fix: remove all additional improvements
1 parent 35645d7 commit b13cca1

File tree

4 files changed

+11
-33
lines changed

4 files changed

+11
-33
lines changed

src/DIRAC/ConfigurationSystem/Client/ConfigurationClient.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
__RCSID__ = "$Id$"
66

7-
import six
7+
88
from base64 import b64encode, b64decode
99

1010
from DIRAC.Core.Tornado.Client.TornadoClient import TornadoClient
@@ -29,7 +29,7 @@ def getCompressedData(self):
2929
:rtype: str
3030
"""
3131
retVal = self.executeRPC("getCompressedData")
32-
if retVal["OK"] and isinstance(retVal["Value"], six.string_types):
32+
if retVal["OK"]:
3333
retVal["Value"] = b64decode(retVal["Value"])
3434
return retVal
3535

@@ -41,7 +41,7 @@ def getCompressedDataIfNewer(self, sClientVersion):
4141
:returns: Configuration data, if changed, compressed
4242
"""
4343
retVal = self.executeRPC("getCompressedDataIfNewer", sClientVersion)
44-
if retVal["OK"] and isinstance(retVal["Value"].get("data"), six.string_types):
44+
if retVal["OK"] and "data" in retVal["Value"]:
4545
retVal["Value"]["data"] = b64decode(retVal["Value"]["data"])
4646
return retVal
4747

@@ -51,7 +51,7 @@ def commitNewData(self, sData):
5151
5252
:param sData: Data to commit, you may call this method with CSAPI and Modificator
5353
"""
54-
return self.executeRPC("commitNewData", b64encode(sData) if six.PY2 else sData)
54+
return self.executeRPC("commitNewData", b64encode(sData))
5555

5656

5757
class ConfigurationClient(Client):

src/DIRAC/ConfigurationSystem/Service/TornadoConfigurationHandler.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
__RCSID__ = "$Id$"
1414

15-
import six
1615
from base64 import b64encode, b64decode
1716

1817
from DIRAC import S_OK, S_ERROR, gLogger
@@ -49,9 +48,8 @@ def export_getCompressedData(self):
4948
"""
5049
Returns the configuration
5150
"""
52-
# TODO: in 8.0 replace it to:
53-
# return S_OK(self.ServiceInterface.getCompressedConfigurationData())
54-
return S_OK(b64encode(self.ServiceInterface.getCompressedConfigurationData()).decode())
51+
sData = self.ServiceInterface.getCompressedConfigurationData()
52+
return S_OK(b64encode(sData))
5553

5654
def export_getCompressedDataIfNewer(self, sClientVersion):
5755
"""
@@ -62,9 +60,7 @@ def export_getCompressedDataIfNewer(self, sClientVersion):
6260
sVersion = self.ServiceInterface.getVersion()
6361
retDict = {"newestVersion": sVersion}
6462
if sClientVersion < sVersion:
65-
# TODO: in 8.0 replace it to:
66-
# retDict["data"] = self.ServiceInterface.getCompressedConfigurationData()
67-
retDict["data"] = b64encode(self.ServiceInterface.getCompressedConfigurationData()).decode()
63+
retDict["data"] = b64encode(self.ServiceInterface.getCompressedConfigurationData())
6864
return S_OK(retDict)
6965

7066
def export_publishSlaveServer(self, sURL):
@@ -83,9 +79,7 @@ def export_commitNewData(self, sData):
8379
credDict = self.getRemoteCredentials()
8480
if "DN" not in credDict or "username" not in credDict:
8581
return S_ERROR("You must be authenticated!")
86-
# TODO: in 8.0 remove it
87-
if isinstance(sData, six.string_types):
88-
sData = b64decode(sData)
82+
sData = b64decode(sData)
8983
return self.ServiceInterface.updateConfiguration(sData, credDict["username"])
9084

9185
def export_writeEnabled(self):

src/DIRAC/Core/Utilities/JEncode.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,6 @@ class DJSONEncoder(json.JSONEncoder):
9090
tuple, datetime, and any object inheriting from JSerializable
9191
"""
9292

93-
# TODO: remove it in 8.0
94-
def encode(self, obj):
95-
"""This method for backward compatability with python 2 code"""
96-
if six.PY2:
97-
# Json can't distinguish bytes or str in python 2, so it's trying to encode with utf-8/ascii
98-
try:
99-
# Let's leave this conversion for backward compatibility, although
100-
# it does not guarantee the return of the same data when decoding
101-
return super(DJSONEncoder, self).encode(obj)
102-
except UnicodeDecodeError as e:
103-
# If the encoding type does not match we have an exception
104-
# that json does not try to fix using default method
105-
obj = self.default(obj) # Let's use base64 in this case
106-
return super(DJSONEncoder, self).encode(obj)
107-
10893
def default(self, obj): # pylint: disable=method-hidden
10994
"""Add supports for datetime and JSerializable class to default json
11095
@@ -122,8 +107,9 @@ def default(self, obj): # pylint: disable=method-hidden
122107
# if the object inherits from JSJerializable, try to serialize it
123108
elif isinstance(obj, JSerializable):
124109
return obj._toJSON() # pylint: disable=protected-access
125-
# if the object a bytes, decode it
126-
elif isinstance(obj, bytes):
110+
# if the object a bytes and we're running with Python 3, encode it
111+
# Python 2's string type is too ambiguous to handle this correctly.
112+
elif six.PY3 and isinstance(obj, bytes):
127113
return {"__dCls": "b64", "obj": b64encode(obj).decode()}
128114
# otherwise, let the parent do
129115
return super(DJSONEncoder, self).default(obj)

src/DIRAC/Core/Utilities/test/Test_Encode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ def test_everyBaseTypeIsTested():
119119
for encodeFunc in g_dEncodeFunctions.values():
120120
testFuncName = ("test_BaseType_%s" % encodeFunc.__name__).replace("encode", "")
121121
globals()[testFuncName]
122-
# We forgot about binary types
123-
globals()["test_BaseType_Bytes"]
124122

125123

126124
def agnosticTestFunction(enc_dec_tuple, data):

0 commit comments

Comments
 (0)