Skip to content

Commit 85a795f

Browse files
committed
Remove dependency on six
1 parent eaaabda commit 85a795f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/diraccfg/cfg.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
import os
88
import re
99
import zipfile
10-
import six
1110
import threading
1211

1312

13+
# Avoid using six as this file should be usable without any dependencies
14+
try:
15+
string_types = (basestring,)
16+
except NameError:
17+
string_types = (str,)
18+
19+
1420
def S_ERROR(messageString=''):
1521
return {'OK': False, 'Message': str(messageString)}
1622

@@ -21,8 +27,8 @@ def S_OK(value=''):
2127

2228
class ListDummy(object):
2329
def fromChar(self, inputString, sepChar=","):
24-
if not (isinstance(inputString, six.string_types)
25-
and isinstance(sepChar, six.string_types)
30+
if not (isinstance(inputString, string_types)
31+
and isinstance(sepChar, string_types)
2632
and sepChar): # to prevent getting an empty String as argument
2733
return None
2834

@@ -100,7 +106,7 @@ def createNewSection(self, sectionName, comment="", contents=False):
100106
if not recDict:
101107
return S_ERROR("Parent section does not exist %s" % sectionName)
102108
parentSection = recDict['value']
103-
if isinstance(parentSection, six.string_types):
109+
if isinstance(parentSection, string_types):
104110
raise KeyError("Entry %s doesn't seem to be a section" % recDict['key'])
105111
return parentSection.createNewSection(recDict['levelsBelow'], comment, contents)
106112
self.__addEntry(sectionName, comment)
@@ -145,7 +151,7 @@ def setOption(self, optionName, value, comment=""):
145151
if not recDict:
146152
return S_ERROR("Parent section does not exist %s" % optionName)
147153
parentSection = recDict['value']
148-
if isinstance(parentSection, six.string_types):
154+
if isinstance(parentSection, string_types):
149155
raise KeyError("Entry %s doesn't seem to be a section" % recDict['key'])
150156
return parentSection.setOption(recDict['levelsBelow'], value, comment)
151157
self.__addEntry(optionName, comment)
@@ -259,9 +265,9 @@ def listOptions(self, ordered=True):
259265
:return: List with the option names
260266
"""
261267
if ordered:
262-
return [sKey for sKey in self.__orderedList if isinstance(self.__dataDict[sKey], six.string_types)]
268+
return [sKey for sKey in self.__orderedList if isinstance(self.__dataDict[sKey], string_types)]
263269
else:
264-
return [sKey for sKey in self.__dataDict.keys() if isinstance(self.__dataDict[sKey], six.string_types)]
270+
return [sKey for sKey in self.__dataDict.keys() if isinstance(self.__dataDict[sKey], string_types)]
265271

266272
@gCFGSynchro
267273
def listSections(self, ordered=True):
@@ -273,9 +279,9 @@ def listSections(self, ordered=True):
273279
:return: List with the subsection names
274280
"""
275281
if ordered:
276-
return [sKey for sKey in self.__orderedList if not isinstance(self.__dataDict[sKey], six.string_types)]
282+
return [sKey for sKey in self.__orderedList if not isinstance(self.__dataDict[sKey], string_types)]
277283
else:
278-
return [sKey for sKey in self.__dataDict.keys() if not isinstance(self.__dataDict[sKey], six.string_types)]
284+
return [sKey for sKey in self.__dataDict.keys() if not isinstance(self.__dataDict[sKey], string_types)]
279285

280286
@gCFGSynchro
281287
def isSection(self, key):
@@ -291,11 +297,11 @@ def isSection(self, key):
291297
if not keyDict:
292298
return False
293299
section = keyDict['value']
294-
if isinstance(section, six.string_types):
300+
if isinstance(section, string_types):
295301
return False
296302
secKey = keyDict['levelsBelow']
297303
return section.isSection(secKey)
298-
return key in self.__dataDict and not isinstance(self.__dataDict[key], six.string_types)
304+
return key in self.__dataDict and not isinstance(self.__dataDict[key], string_types)
299305

300306
@gCFGSynchro
301307
def isOption(self, key):
@@ -311,11 +317,11 @@ def isOption(self, key):
311317
if not keyDict:
312318
return False
313319
section = keyDict['value']
314-
if isinstance(section, six.string_types):
320+
if isinstance(section, string_types):
315321
return False
316322
secKey = keyDict['levelsBelow']
317323
return section.isOption(secKey)
318-
return key in self.__dataDict and isinstance(self.__dataDict[key], six.string_types)
324+
return key in self.__dataDict and isinstance(self.__dataDict[key], string_types)
319325

320326
def listAll(self):
321327
"""
@@ -399,7 +405,7 @@ def getOption(self, opName, defaultValue=None):
399405
return defaultValue
400406
dataD = dataV
401407

402-
if not isinstance(dataV, six.string_types):
408+
if not isinstance(dataV, string_types):
403409
optionValue = defaultValue
404410
else:
405411
optionValue = dataV
@@ -465,7 +471,7 @@ def getAsDict(self, path=""):
465471
if not reqDict:
466472
return resVal
467473
keyCfg = reqDict['value']
468-
if isinstance(keyCfg, six.string_types):
474+
if isinstance(keyCfg, string_types):
469475
return resVal
470476
return keyCfg.getAsDict()
471477
for op in self.listOptions():

0 commit comments

Comments
 (0)