def __applyMacros(self, value): if isinstance(value, _MacrosValue): macros = value.macros dictValue = value.dictValue simpleMacroses = macroses.getSyncMacroses() if macros in simpleMacroses: macrosKey = simpleMacroses[macros]() else: if macros == 'MACROS_DICT': value = {} for key, mValue in dictValue.iteritems(): value[key] = self.__applyMacros(mValue) return value raise SoftException( "Unsupported macros '{0}', not found in {1}".format( macros, simpleMacroses)) if macrosKey in dictValue: return self.__applyMacros(dictValue[macrosKey]) if 'default' in dictValue: return self.__applyMacros(dictValue['default']) raise SoftException( "Incorrect section in {0}, dict {1} with macros '{2}' should contains item '{3}' or 'default'" .format(GUI_SETTINGS_FILE_PATH, dictValue, macros, macrosKey)) return value
def __init__(self): super(URLMacros, self).__init__() self.__asyncMacroses = macroses.getAsyncMacroses() self.__syncMacroses = macroses.getSyncMacroses() macrosKeys = self.__syncMacroses.keys() macrosKeys.extend(self.__asyncMacroses.keys()) patterns = [] for macro in macrosKeys: patterns.append('\\%(macro)s\\(.*\\)|\\%(macro)s' % {'macro': self._getUserMacrosName(macro)}) self.__filter = re.compile('|'.join(patterns)) self.__argsFilter = re.compile('\\$(\\w*)(\\((.*)\\))?')
def __init__(self): """ Class of parser that replace macros to required value. """ super(URLMarcos, self).__init__() self.__asyncMacroses = macroses.getAsyncMacroses() self.__syncMacroses = macroses.getSyncMacroses() macrosKeys = self.__syncMacroses.keys() macrosKeys.extend(self.__asyncMacroses.keys()) patterns = [] for macro in macrosKeys: patterns.append('\\%(macro)s\\(.*\\)|\\%(macro)s' % {'macro': self._getUserMacrosName(macro)}) self.__filter = re.compile('|'.join(patterns)) self.__argsFilter = re.compile('\\$(\\w*)(\\((.*)\\))?')
def __init__(self, allowedMacroses=None): super(URLMacros, self).__init__() self.__asyncMacroses = macroses.getAsyncMacroses() self.__syncMacroses = macroses.getSyncMacroses() macrosKeys = self.__syncMacroses.keys() macrosKeys.extend(self.__asyncMacroses.keys()) if allowedMacroses is not None: macrosKeys = [ key for key in macrosKeys if key in allowedMacroses ] patterns = [] for macro in macrosKeys: patterns.append('\\%(macro)s\\(.*\\)|\\%(macro)s' % {'macro': self._getUserMacrosName(macro)}) self.__filter = re.compile('|'.join(patterns)) self.__argsFilter = re.compile('\\$(\\w*)(\\((.*)\\))?') return
def __applyMacros(self, value): if isinstance(value, _MacrosValue): macros = value.macros dictValue = value.dictValue simpleMacroses = macroses.getSyncMacroses() if macros in simpleMacroses: macrosKey = simpleMacroses[macros]() else: if macros == 'MACROS_DICT': value = {} for key, mValue in dictValue.iteritems(): value[key] = self.__applyMacros(mValue) return value raise AttributeError("Unsupported macros '{0}', not found in {1}".format(macros, simpleMacroses)) if macrosKey in dictValue or 'default' in dictValue: value = dictValue.get(macrosKey, None) or dictValue['default'] return self.__applyMacros(value) raise AttributeError("Incorrect section in {0}, dict {1} with macros '{2}' should contains item '{3}' or 'default'".format(GUI_SETTINGS_FILE_PATH, dictValue, macros, macrosKey)) return value