def ValidateString(sourceText, languageID, dummyData=None):
    import localization
    if dummyData is None:
        dummyData = {
            eveLocalization.VARIABLE_TYPE.CHARACTER: 1,
            eveLocalization.VARIABLE_TYPE.NPCORGANIZATION: 1,
            eveLocalization.VARIABLE_TYPE.ITEM: 1,
            eveLocalization.VARIABLE_TYPE.LOCATION: 1,
            eveLocalization.VARIABLE_TYPE.CHARACTERLIST: [1],
            eveLocalization.VARIABLE_TYPE.MESSAGE: 1,
            eveLocalization.VARIABLE_TYPE.DATETIME: blue.os.GetWallclockTime(),
            eveLocalization.VARIABLE_TYPE.FORMATTEDTIME:
            blue.os.GetWallclockTime(),
            eveLocalization.VARIABLE_TYPE.TIMEINTERVAL: const.SEC,
            eveLocalization.VARIABLE_TYPE.NUMERIC: 99.9,
            eveLocalization.VARIABLE_TYPE.GENERIC: 'This is a test message.'
        }
    errors = []
    oldMethod = localization.LogError

    def ValidationLogError(*args):
        oldMethod(*args)
        errors.append(args)

    localization.LogError = ValidationLogError
    openCount = sourceText.count('{')
    closeCount = sourceText.count('}')
    if openCount != closeCount:
        return ["Mismatching brackets in string '" + unicode(sourceText) + "'"]
    try:
        tags = localization._Tokenize(sourceText)
    except Exception as e:
        return [
            "Exception occurred when attempting to tokenize string '" +
            unicode(sourceText) + "': " + repr(e)
        ]

    kwargs = {}
    for tag in tags.values():
        if tag['variableName'] and tag['variableType'] in dummyData:
            kwargs[tag['variableName']] = dummyData[tag['variableType']]
        if 'linkinfo' in tag['kwargs']:
            kwargs[tag['kwargs']['linkinfo']] = ('showinfo', 1)
        if 'quantity' in tag['kwargs']:
            kwargs[tag['kwargs']['quantity']] = 3

    result = sourceText
    try:
        result = eveLocalization.Parse(sourceText, languageID, tags, **kwargs)
    except Exception as e:
        errors = [
            "Exception occurred when attempting to validate string '" +
            unicode(sourceText) + "': " + repr(e) + repr(kwargs)
        ]

    localization.LogError = oldMethod
    if errors:
        return errors
    return result
def ValidateString(sourceText, languageID, dummyData = None):
    import localization
    if dummyData is None:
        dummyData = {eveLocalization.VARIABLE_TYPE.CHARACTER: 1,
         eveLocalization.VARIABLE_TYPE.NPCORGANIZATION: 1,
         eveLocalization.VARIABLE_TYPE.ITEM: 1,
         eveLocalization.VARIABLE_TYPE.LOCATION: 1,
         eveLocalization.VARIABLE_TYPE.CHARACTERLIST: [1],
         eveLocalization.VARIABLE_TYPE.MESSAGE: 1,
         eveLocalization.VARIABLE_TYPE.DATETIME: blue.os.GetWallclockTime(),
         eveLocalization.VARIABLE_TYPE.FORMATTEDTIME: blue.os.GetWallclockTime(),
         eveLocalization.VARIABLE_TYPE.TIMEINTERVAL: const.SEC,
         eveLocalization.VARIABLE_TYPE.NUMERIC: 99.9,
         eveLocalization.VARIABLE_TYPE.GENERIC: 'This is a test message.'}
    errors = []
    oldMethod = localization.LogError

    def ValidationLogError(*args):
        oldMethod(*args)
        errors.append(args)

    localization.LogError = ValidationLogError
    openCount = sourceText.count('{')
    closeCount = sourceText.count('}')
    if openCount != closeCount:
        return ["Mismatching brackets in string '" + unicode(sourceText) + "'"]
    try:
        tags = localization._Tokenize(sourceText)
    except Exception as e:
        return ["Exception occurred when attempting to tokenize string '" + unicode(sourceText) + "': " + repr(e)]

    kwargs = {}
    for tag in tags.values():
        if tag['variableName'] and tag['variableType'] in dummyData:
            kwargs[tag['variableName']] = dummyData[tag['variableType']]
        if 'linkinfo' in tag['kwargs']:
            kwargs[tag['kwargs']['linkinfo']] = ('showinfo', 1)
        if 'quantity' in tag['kwargs']:
            kwargs[tag['kwargs']['quantity']] = 3

    result = sourceText
    try:
        result = eveLocalization.Parse(sourceText, languageID, tags, **kwargs)
    except Exception as e:
        errors = ["Exception occurred when attempting to validate string '" + unicode(sourceText) + "': " + repr(e) + repr(kwargs)]

    localization.LogError = oldMethod
    if errors:
        return errors
    return result
Example #3
0
    def UpdateTextCache(self, messagePerLanguage, metaDataPerLanguage,
                        labelsDict):
        for language in messagePerLanguage:
            LogInfo(
                'Preparing to update internal text and label cache. The sizes of new data dictionaries are: ',
                len(messagePerLanguage.get(language, {})), ', ',
                len(metaDataPerLanguage.get(language, {})))
            if eveLocalization.HasLanguage(language):
                newData = {}
                for messageID, text in messagePerLanguage.get(language,
                                                              {}).iteritems():
                    try:
                        metaData = None
                        ignore, metaData, ignore = eveLocalization.GetMessageDataByID(
                            messageID, language)
                    except KeyError:
                        sys.exc_clear()

                    try:
                        newData[messageID] = (text, metaData,
                                              localization._Tokenize(text))
                    except:
                        log.LogException()
                        continue

                try:
                    eveLocalization.LoadMessageData(language, newData)
                except:
                    log.LogException()
                    continue

        for language in metaDataPerLanguage:
            if eveLocalization.HasLanguage(language):
                for messageID, metaData in metaDataPerLanguage.get(
                        language, {}).iteritems():
                    try:
                        text, ignore, tokens = eveLocalization.GetMessageDataByID(
                            messageID, language)
                        eveLocalization.LoadMessageData(
                            language, {messageID: (text, metaData, tokens)})
                    except:
                        log.LogException()

        LogInfo('Updating label cache. New data size is ', len(labelsDict))
        for label, messageID in labelsDict.iteritems():
            self.languageLabels[label.encode('ascii')] = messageID
Example #4
0
    def UpdateTextCache(self, messagePerLanguage, metaDataPerLanguage, labelsDict):
        for language in messagePerLanguage:
            LogInfo('Preparing to update internal text and label cache. The sizes of new data dictionaries are: ', len(messagePerLanguage.get(language, {})), ', ', len(metaDataPerLanguage.get(language, {})))
            if eveLocalization.HasLanguage(language):
                newData = {}
                for messageID, text in messagePerLanguage.get(language, {}).iteritems():
                    try:
                        metaData = None
                        ignore, metaData, ignore = eveLocalization.GetMessageDataByID(messageID, language)
                    except KeyError:
                        sys.exc_clear()

                    try:
                        newData[messageID] = (text, metaData, localization._Tokenize(text))
                    except:
                        log.LogException()
                        continue

                try:
                    eveLocalization.LoadMessageData(language, newData)
                except:
                    log.LogException()
                    continue

        for language in metaDataPerLanguage:
            if eveLocalization.HasLanguage(language):
                for messageID, metaData in metaDataPerLanguage.get(language, {}).iteritems():
                    try:
                        text, ignore, tokens = eveLocalization.GetMessageDataByID(messageID, language)
                        eveLocalization.LoadMessageData(language, {messageID: (text, metaData, tokens)})
                    except:
                        log.LogException()

        LogInfo('Updating label cache. New data size is ', len(labelsDict))
        for label, messageID in labelsDict.iteritems():
            self.languageLabels[label.encode('ascii')] = messageID