diff --git a/src/diraccfg/cfg.py b/src/diraccfg/cfg.py index a58246f..ff46089 100644 --- a/src/diraccfg/cfg.py +++ b/src/diraccfg/cfg.py @@ -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)} @@ -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 @@ -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) @@ -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) @@ -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): @@ -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): @@ -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): @@ -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): """ @@ -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 @@ -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():