def validateUserRoomName(name):
    name = name.strip()
    if not name or len(unicode_from_utf8(name)[0]) not in xrange(CHANNEL_LIMIT.NAME_MIN_LENGTH, CHANNEL_LIMIT.NAME_MAX_LENGTH + 1):
        error = I18nError(MESSENGER.CLIENT_ERROR_LIMIT_CHANNEL_INVALID_LENGTH, int32Arg1=CHANNEL_LIMIT.NAME_MIN_LENGTH, int32Arg2=CHANNEL_LIMIT.NAME_MAX_LENGTH)
        return (name, error)
    else:
        return (name, None)
Example #2
0
 def getFormattedStrings(self, vInfoVO, vStatsVO, viStatsVO, ctx, fullPlayerName):
     format = self._findPlayerHTMLFormat(vInfoVO, ctx, self._ui.colorManager)
     unicodeStr, _ = unicode_from_utf8(fullPlayerName)
     if len(unicodeStr) > ctx.labelMaxLength:
         fullPlayerName = '{0}..'.format(normalized_unicode_trim(fullPlayerName, ctx.labelMaxLength - 2))
     fragsString = format % ' '
     if vStatsVO.frags or viStatsVO.equipmentKills:
         fragsString = format % str(vStatsVO.frags + viStatsVO.equipmentKills)
     pName = format % fullPlayerName
     frags = fragsString
     vName = format % vInfoVO.vehicleType.shortName
     scoreFormat = self._getHTMLString('textColorGold', self._ui.colorManager)
     regularFormat = self._getHTMLString('textColorFalloutRegular', self._ui.colorManager)
     highlightedDeaths = viStatsVO.stopRespawn
     deathsFormatStyle = 'textColorFalloutHighlightedDeaths' if highlightedDeaths else 'textColorFalloutRegularDeaths'
     deathsFormat = self._getHTMLString(deathsFormatStyle, self._ui.colorManager)
     scoreString = scoreFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.winPoints)
     if viStatsVO.deathCount > 0:
         deathsString = deathsFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.deathCount)
     else:
         deathsString = deathsFormat % ''
     damageString = regularFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.damageDealt + viStatsVO.equipmentDamage)
     if hasResourcePoints():
         specialPointsString = regularFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.resourceAbsorbed)
     else:
         flagsCaptured = viStatsVO.flagActions[FLAG_ACTION.CAPTURED]
         specialPointsString = regularFormat % BigWorld.wg_getNiceNumberFormat(flagsCaptured)
     return (pName,
      frags,
      vName,
      (scoreString,
       damageString,
       deathsString,
       specialPointsString))
 def sendPassword(self, value):
     pwdRange = xrange(CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH + 1)
     if value is None or len(unicode_from_utf8(value)[0]) not in pwdRange:
         SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDPASSWORD_MESSAGE, CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
     else:
         self.proto.channels.joinToChannel(self._channel.getID(), password=value)
         self.destroy()
Example #4
0
 def sendPassword(self, value):
     pwdRange = xrange(CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH + 1)
     if value is None or len(unicode_from_utf8(value)[0]) not in pwdRange:
         SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDPASSWORD_MESSAGE, CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
     else:
         self.proto.channels.joinToChannel(self._channel.getID(), password=value)
         self.destroy()
Example #5
0
    def onHandleMsg(self, msgID, msgType, body, jidFrom, pyGlooxTag):
        try:
            body, _ = unicode_from_utf8(body)
        except (UnicodeDecodeError, TypeError, ValueError):
            LOG_CURRENT_EXCEPTION()

        self.__handleEvent(GLOOX_EVENT.MESSAGE, msgID, msgType, body, ContactBareJID(jidFrom), pyGlooxTag)
Example #6
0
def validateContactNote(note):
    if not note:
        return ('', ClientContactError(CONTACT_ERROR_ID.NOTE_EMPTY))
    elif len(unicode_from_utf8(note)[0]) not in xrange(CONTACT_LIMIT.NOTE_MIN_CHARS_COUNT, CONTACT_LIMIT.NOTE_MAX_CHARS_COUNT + 1):
        return (note, ClientIntLimitError(LIMIT_ERROR_ID.NOTE_INVALID_LENGTH, CONTACT_LIMIT.NOTE_MIN_CHARS_COUNT, CONTACT_LIMIT.NOTE_MAX_CHARS_COUNT))
    else:
        return (note, None)
Example #7
0
    def onHandleMsg(self, msgID, msgType, body, jidFrom, pyGlooxTag):
        try:
            body, _ = unicode_from_utf8(body)
        except (UnicodeDecodeError, TypeError, ValueError):
            LOG_CURRENT_EXCEPTION()

        self.__handleEvent(GLOOX_EVENT.MESSAGE, msgID, msgType, body, ContactBareJID(jidFrom), pyGlooxTag)
Example #8
0
 def getFormattedStrings(self, vInfoVO, vStatsVO, ctx, fullPlayerName):
     format = self.__findHTMLFormat(vInfoVO, ctx)
     unicodeStr, _ = unicode_from_utf8(fullPlayerName)
     if len(unicodeStr) > ctx.labelMaxLength:
         fullPlayerName = '{0}..'.format(normalized_unicode_trim(fullPlayerName, ctx.labelMaxLength - 2))
     fragsString = format % ' '
     if vStatsVO.frags:
         fragsString = format % str(vStatsVO.frags)
     return (format % fullPlayerName, fragsString, format % vInfoVO.vehicleType.shortName)
def validateContactNote(note):
    if not note:
        return ('', ClientContactError(CONTACT_ERROR_ID.NOTE_EMPTY))
    if len(unicode_from_utf8(note)[0]) not in xrange(
            CONTACT_LIMIT.NOTE_MIN_CHARS_COUNT,
            CONTACT_LIMIT.NOTE_MAX_CHARS_COUNT + 1):
        return (note,
                ClientIntLimitError(LIMIT_ERROR_ID.NOTE_INVALID_LENGTH,
                                    CONTACT_LIMIT.NOTE_MIN_CHARS_COUNT,
                                    CONTACT_LIMIT.NOTE_MAX_CHARS_COUNT))
    return (note, None)
def validateUserRoomPwd(password, isRetype = False):
    pwdRange = xrange(CHANNEL_LIMIT.PWD_MIN_LENGTH, CHANNEL_LIMIT.PWD_MAX_LENGTH + 1)
    if password is None or len(unicode_from_utf8(password)[0]) not in pwdRange:
        if isRetype:
            key = MESSENGER.CLIENT_ERROR_CHANNEL_RETYPE_INVALID
        else:
            key = MESSENGER.CLIENT_ERROR_CHANNEL_PASSWORD_INVALID
        error = I18nError(key, int32Arg1=CHANNEL_LIMIT.PWD_MIN_LENGTH, int32Arg2=CHANNEL_LIMIT.PWD_MAX_LENGTH)
        return ('', error)
    else:
        return (password, None)
Example #11
0
 def createChannel(self, name, userPassword, password, retype):
     name = name.strip()
     if name is None or len(unicode_from_utf8(name)[0]) not in xrange(CHANNEL_NAME_MIN_LENGTH, CHANNEL_NAME_MAX_LENGTH + 1):
         SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDNAME_MESSAGE, CHANNEL_NAME_MIN_LENGTH, CHANNEL_NAME_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
         return
     if userPassword:
         pwdRange = xrange(CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH + 1)
         if password is None or len(unicode_from_utf8(password)[0]) not in pwdRange:
             SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDPASSWORD_MESSAGE, CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
             return
         if retype is None or len(unicode_from_utf8(retype)[0]) not in pwdRange:
             SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_INVALIDRETYPEPASSWORD_MESSAGE, CHANNEL_PWD_MIN_LENGTH, CHANNEL_PWD_MAX_LENGTH, type=SystemMessages.SM_TYPE.Error)
             return
         if password != retype:
             SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_NOTEQUALSPASSWORDS_MESSAGE, type=SystemMessages.SM_TYPE.Error)
             return
     else:
         password = None
     result = self.proto.channels.createChannel(name, password)
     if result == CREATE_CHANNEL_RESULT.activeChannelLimitReached:
         SystemMessages.pushI18nMessage(MESSENGER.DIALOGS_CREATECHANNEL_ERRORS_ACTIVECHANNELLIMITREACHED_MESSAGE, type=SystemMessages.SM_TYPE.Error)
     self.destroy()
Example #12
0
def validateUserRoomPwd(password, isRetype=False):
    if not password:
        if isRetype:
            key = MESSENGER.CLIENT_ERROR_CHANNEL_PASSWORD_EMPTY
        else:
            key = MESSENGER.CLIENT_ERROR_CHANNEL_RETYPE_EMPTY
        return ('', I18nError(key))
    else:
        pwdRange = xrange(CHANNEL_LIMIT.PWD_MIN_LENGTH, CHANNEL_LIMIT.PWD_MAX_LENGTH + 1)
        if not isRetype and len(unicode_from_utf8(password)[0]) not in pwdRange:
            error = I18nError(MESSENGER.CLIENT_ERROR_LIMIT_PWD_INVALID_LENGTH, int32Arg1=CHANNEL_LIMIT.PWD_MIN_LENGTH, int32Arg2=CHANNEL_LIMIT.PWD_MAX_LENGTH)
            return ('', error)
        return (password, None)
Example #13
0
 def getFormattedStrings(self, vInfoVO, vStatsVO, viStatsVO, ctx,
                         fullPlayerName):
     format = self._findPlayerHTMLFormat(vInfoVO, ctx,
                                         self._ui.colorManager)
     unicodeStr, _ = unicode_from_utf8(fullPlayerName)
     if len(unicodeStr) > ctx.labelMaxLength:
         fullPlayerName = '{0}..'.format(
             normalized_unicode_trim(fullPlayerName,
                                     ctx.labelMaxLength - 2))
     fragsString = format % ' '
     if vStatsVO.frags:
         fragsString = format % str(vStatsVO.frags)
     return (format % fullPlayerName, fragsString,
             format % vInfoVO.vehicleType.shortName, ())
Example #14
0
 def getFormattedStrings(self, vInfoVO, vStatsVO, viStatsVO, ctx, fullPlayerName):
     padding = makeHtmlString('html_templates:battle', 'multiteamPadding', {})
     format = self._findPlayerHTMLFormat(vInfoVO, ctx, self._ui.colorManager)
     formatWithPadding = format + padding
     unicodeStr, _ = unicode_from_utf8(fullPlayerName)
     maxLabelLength = ctx.labelMaxLength
     isIGR = vInfoVO.player.isIGR()
     if isIGR:
         maxLabelLength = maxLabelLength - 2
     if len(unicodeStr) > maxLabelLength:
         fullPlayerName = '{0}..'.format(normalized_unicode_trim(fullPlayerName, maxLabelLength - 2))
     fragsString = formatWithPadding % ' '
     if vStatsVO.frags or viStatsVO.equipmentKills:
         fragsString = formatWithPadding % str(vStatsVO.frags + viStatsVO.equipmentKills)
     pName = format % fullPlayerName
     frags = fragsString
     vName = formatWithPadding % vInfoVO.vehicleType.shortName
     if isIGR:
         igrType = vInfoVO.player.igrType
         icon = makeHtmlString('html_templates:igr/iconSmall', 'premium' if igrType == IGR_TYPE.PREMIUM else 'basic')
         pName += icon
     pName += padding
     scoreFormat = self._getHTMLString('textColorGold', self._ui.colorManager) + padding
     regularFormat = self._getHTMLString('textColorFalloutRegular', self._ui.colorManager) + padding
     highlightedDeaths = viStatsVO.stopRespawn
     deathsFormatStyle = 'textColorFalloutHighlightedDeaths' if highlightedDeaths else 'textColorFalloutRegularDeaths'
     deathsFormat = self._getHTMLString(deathsFormatStyle, self._ui.colorManager) + padding
     scoreString = scoreFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.winPoints)
     if viStatsVO.deathCount > 0:
         deathsString = deathsFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.deathCount)
     else:
         deathsString = deathsFormat % ''
     damageString = regularFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.damageDealt + viStatsVO.equipmentDamage)
     if hasResourcePoints():
         specialPointsString = regularFormat % BigWorld.wg_getNiceNumberFormat(viStatsVO.resourceAbsorbed)
     else:
         flagsCaptured = viStatsVO.flagActions[FLAG_ACTION.CAPTURED]
         specialPointsString = regularFormat % BigWorld.wg_getNiceNumberFormat(flagsCaptured)
     return (pName,
      frags,
      vName,
      (scoreString,
       damageString,
       deathsString,
       specialPointsString))
Example #15
0
    def __prepareData(self, entryData):
        description = entryData.get('description')
        if description is not None:
            try:
                section = ResMgr.DataSection()
                section.createSectionFromString(encodeUtf8(description))
                _, section = findFirst(lambda (name, _): name == 'div', section.items())
                description, _ = unicode_from_utf8(section.asString)
                if len(description) > self.DESCRIPTION_MAX_LENGTH:
                    description = description[:self.DESCRIPTION_CUT_LENGTH] + self.DESCRIPTION_TAIL
            except Exception:
                LOG_ERROR('Invalid RSS entry description', entryData, description)
                LOG_CURRENT_EXCEPTION()
                return

        return {'id': entryData.get('id', str(uuid.uuid4())),
         'link': entryData.get('link'),
         'description': encodeUtf8(description)}
Example #16
0
    def __prepareData(self, entryData):
        description = entryData.get('description')
        if description is not None:
            try:
                section = ResMgr.DataSection()
                section.createSectionFromString(encodeUtf8(description))
                _, section = findFirst(lambda (name, _): name == 'div', section.items())
                description, _ = unicode_from_utf8(section.asString)
                if len(description) > self.DESCRIPTION_MAX_LENGTH:
                    description = description[:self.DESCRIPTION_CUT_LENGTH] + self.DESCRIPTION_TAIL
            except Exception:
                LOG_ERROR('Invalid RSS entry description', entryData, description)
                LOG_CURRENT_EXCEPTION()
                return

        return {'id': entryData.get('id', str(uuid.uuid4())),
         'link': entryData.get('link'),
         'description': encodeUtf8(description)}
Example #17
0
 def getFormattedStrings(self, vInfoVO, vStatsVO, viStatsVO, ctx,
                         fullPlayerName):
     format = self._findPlayerHTMLFormat(vInfoVO, ctx,
                                         self._ui.colorManager)
     unicodeStr, _ = unicode_from_utf8(fullPlayerName)
     if len(unicodeStr) > ctx.labelMaxLength:
         fullPlayerName = '{0}..'.format(
             normalized_unicode_trim(fullPlayerName,
                                     ctx.labelMaxLength - 2))
     fragsString = format % ' '
     if vStatsVO.frags or viStatsVO.equipmentKills:
         fragsString = format % str(vStatsVO.frags +
                                    viStatsVO.equipmentKills)
     pName = format % fullPlayerName
     frags = fragsString
     vName = format % vInfoVO.vehicleType.shortName
     scoreFormat = self._getHTMLString('textColorGold',
                                       self._ui.colorManager)
     regularFormat = self._getHTMLString('textColorFalloutRegular',
                                         self._ui.colorManager)
     highlightedDeaths = viStatsVO.stopRespawn
     deathsFormatStyle = 'textColorFalloutHighlightedDeaths' if highlightedDeaths else 'textColorFalloutRegularDeaths'
     deathsFormat = self._getHTMLString(deathsFormatStyle,
                                        self._ui.colorManager)
     scoreString = scoreFormat % BigWorld.wg_getNiceNumberFormat(
         viStatsVO.winPoints)
     if viStatsVO.deathCount > 0:
         deathsString = deathsFormat % BigWorld.wg_getNiceNumberFormat(
             viStatsVO.deathCount)
     else:
         deathsString = deathsFormat % ''
     damageString = regularFormat % BigWorld.wg_getNiceNumberFormat(
         viStatsVO.damageDealt + viStatsVO.equipmentDamage)
     if hasResourcePoints():
         specialPointsString = regularFormat % BigWorld.wg_getNiceNumberFormat(
             viStatsVO.resourceAbsorbed)
     else:
         flagsCaptured = viStatsVO.flagActions[FLAG_ACTION.CAPTURED]
         specialPointsString = regularFormat % BigWorld.wg_getNiceNumberFormat(
             flagsCaptured)
     return (pName, frags, vName, (scoreString, damageString, deathsString,
                                   specialPointsString))
Example #18
0
 def _trimLongName(self, name, maxLength):
     unicodeStr, _ = unicode_from_utf8(name)
     if len(unicodeStr) > maxLength:
         name = '{0}..'.format(normalized_unicode_trim(name, maxLength - 2))
     return name
Example #19
0
 def _trimLongName(self, name, maxLength):
     unicodeStr, _ = unicode_from_utf8(name)
     if len(unicodeStr) > maxLength:
         name = '{0}..'.format(normalized_unicode_trim(name, maxLength - 2))
     return name