Skip to content

Commit

Permalink
Remove dependency on six
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Feb 21, 2020
1 parent eaaabda commit 85a795f
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/diraccfg/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
import os
import re
import zipfile
import six
import threading


# Avoid using six as this file should be usable without any dependencies
try:
string_types = (basestring,)
except NameError:
string_types = (str,)


def S_ERROR(messageString=''):
return {'OK': False, 'Message': str(messageString)}

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

class ListDummy(object):
def fromChar(self, inputString, sepChar=","):
if not (isinstance(inputString, six.string_types)
and isinstance(sepChar, six.string_types)
if not (isinstance(inputString, string_types)
and isinstance(sepChar, string_types)
and sepChar): # to prevent getting an empty String as argument
return None

Expand Down Expand Up @@ -100,7 +106,7 @@ def createNewSection(self, sectionName, comment="", contents=False):
if not recDict:
return S_ERROR("Parent section does not exist %s" % sectionName)
parentSection = recDict['value']
if isinstance(parentSection, six.string_types):
if isinstance(parentSection, string_types):
raise KeyError("Entry %s doesn't seem to be a section" % recDict['key'])
return parentSection.createNewSection(recDict['levelsBelow'], comment, contents)
self.__addEntry(sectionName, comment)
Expand Down Expand Up @@ -145,7 +151,7 @@ def setOption(self, optionName, value, comment=""):
if not recDict:
return S_ERROR("Parent section does not exist %s" % optionName)
parentSection = recDict['value']
if isinstance(parentSection, six.string_types):
if isinstance(parentSection, string_types):
raise KeyError("Entry %s doesn't seem to be a section" % recDict['key'])
return parentSection.setOption(recDict['levelsBelow'], value, comment)
self.__addEntry(optionName, comment)
Expand Down Expand Up @@ -259,9 +265,9 @@ def listOptions(self, ordered=True):
:return: List with the option names
"""
if ordered:
return [sKey for sKey in self.__orderedList if isinstance(self.__dataDict[sKey], six.string_types)]
return [sKey for sKey in self.__orderedList if isinstance(self.__dataDict[sKey], string_types)]
else:
return [sKey for sKey in self.__dataDict.keys() if isinstance(self.__dataDict[sKey], six.string_types)]
return [sKey for sKey in self.__dataDict.keys() if isinstance(self.__dataDict[sKey], string_types)]

@gCFGSynchro
def listSections(self, ordered=True):
Expand All @@ -273,9 +279,9 @@ def listSections(self, ordered=True):
:return: List with the subsection names
"""
if ordered:
return [sKey for sKey in self.__orderedList if not isinstance(self.__dataDict[sKey], six.string_types)]
return [sKey for sKey in self.__orderedList if not isinstance(self.__dataDict[sKey], string_types)]
else:
return [sKey for sKey in self.__dataDict.keys() if not isinstance(self.__dataDict[sKey], six.string_types)]
return [sKey for sKey in self.__dataDict.keys() if not isinstance(self.__dataDict[sKey], string_types)]

@gCFGSynchro
def isSection(self, key):
Expand All @@ -291,11 +297,11 @@ def isSection(self, key):
if not keyDict:
return False
section = keyDict['value']
if isinstance(section, six.string_types):
if isinstance(section, string_types):
return False
secKey = keyDict['levelsBelow']
return section.isSection(secKey)
return key in self.__dataDict and not isinstance(self.__dataDict[key], six.string_types)
return key in self.__dataDict and not isinstance(self.__dataDict[key], string_types)

@gCFGSynchro
def isOption(self, key):
Expand All @@ -311,11 +317,11 @@ def isOption(self, key):
if not keyDict:
return False
section = keyDict['value']
if isinstance(section, six.string_types):
if isinstance(section, string_types):
return False
secKey = keyDict['levelsBelow']
return section.isOption(secKey)
return key in self.__dataDict and isinstance(self.__dataDict[key], six.string_types)
return key in self.__dataDict and isinstance(self.__dataDict[key], string_types)

def listAll(self):
"""
Expand Down Expand Up @@ -399,7 +405,7 @@ def getOption(self, opName, defaultValue=None):
return defaultValue
dataD = dataV

if not isinstance(dataV, six.string_types):
if not isinstance(dataV, string_types):
optionValue = defaultValue
else:
optionValue = dataV
Expand Down Expand Up @@ -465,7 +471,7 @@ def getAsDict(self, path=""):
if not reqDict:
return resVal
keyCfg = reqDict['value']
if isinstance(keyCfg, six.string_types):
if isinstance(keyCfg, string_types):
return resVal
return keyCfg.getAsDict()
for op in self.listOptions():
Expand Down

0 comments on commit 85a795f

Please sign in to comment.