コード例 #1
0
ファイル: NameCheck.py プロジェクト: n8x0b7T/Toontown-RTG
    def checkJapanese(name):
        asciiSpace = range(32, 33)
        asciiDigits = range(48, 64)
        hiragana = range(12353, 12448)
        katakana = range(12449, 12544)
        halfwidthKatakana = range(65381, 65440)
        halfwidthCharacter = set(asciiSpace + halfwidthKatakana)
        allowedUtf8 = set(asciiSpace + hiragana + katakana + halfwidthKatakana)

        te = TextEncoder()
        dc = 0.0

        for char in (ord(char) for char in te.decodeText(name)):
            if char not in allowedUtf8:
                if char in asciiDigits:
                    notify.info('name contains not allowed ascii digits')
                    return OTPLocalizer.NCNoDigits
                else:
                    notify.info('name contains not allowed utf8 char: 0x%04x' %
                                char)
                    return OTPLocalizer.NCBadCharacter % te.encodeWtext(
                        unichr(char))
            elif char in halfwidthCharacter:
                dc += 0.5
            else:
                dc += 1

        if dc < 2:
            notify.info('name is too short: %0.1f' % dc)
            return OTPLocalizer.NCTooShort
        elif dc > 8:
            notify.info(
                'name has been occupied more than eight display cells: %0.1f' %
                dc)
            return OTPLocalizer.NCGeneric
コード例 #2
0
ファイル: NameCheck.py プロジェクト: TTGhost/POTCOR-src
    def checkJapanese(name):
        asciiSpace = range(32, 33)
        asciiDigits = range(48, 64)
        hiragana = range(12353, 12448)
        katakana = range(12449, 12544)
        halfwidthKatakana = range(65381, 65440)
        halfwidthCharacter = set(asciiSpace + halfwidthKatakana)
        allowedUtf8 = set(asciiSpace + hiragana + katakana + halfwidthKatakana)

        te = TextEncoder()
        dc = 0.0

        for char in (ord(char) for char in te.decodeText(name)):
            if char not in allowedUtf8:
                if char in asciiDigits:
                    notify.info('name contains not allowed ascii digits')
                    return OTPLocalizer.NCNoDigits
                else:
                    notify.info('name contains not allowed utf8 char: 0x%04x' % char)
                    return OTPLocalizer.NCBadCharacter % te.encodeWtext(unichr(char))
            elif char in halfwidthCharacter:
                dc += 0.5
            else:
                dc += 1

        if dc < 2:
            notify.info('name is too short: %0.1f' % dc)
            return OTPLocalizer.NCTooShort
        elif dc > 8:
            notify.info('name has been occupied more than eight display cells: %0.1f' % dc)
            return OTPLocalizer.NCGeneric
コード例 #3
0
ファイル: NameCheck.py プロジェクト: satire6/Anesidora
    def checkJapanese(name):
        # Japan allows ASCII space, hiragana, katakana, and half-width katakana,
        # but, allows not ASCII and kanji(CJK) characters for a name
        # All Japanese characters are three-byte-encoded utf-8 characters from unicode
        # Reference: http://unicode.org/charts/
        asciiSpace = range(0x20, 0x21)
        asciiDigits = range(0x30, 0x40)
        hiragana = range(0x3041, 0x30A0)
        katakana = range(0x30A1, 0x3100)
        halfwidthKatakana = range(0xFF65, 0xFFA0)
        halfwidthCharacter = set(asciiSpace + halfwidthKatakana)
        allowedUtf8 = set(asciiSpace + hiragana + katakana + halfwidthKatakana)
        te = TextEncoder()
        dc = 0.0

        # Return None if name is OK, error string if name is not OK
        for char in (ord(char) for char in te.decodeText(name)):
            if char not in allowedUtf8:
                # Notify error string, if not allowed utf-8 character
                if char in asciiDigits:
                    notify.info('name contains not allowed ascii digits')
                    return OTPLocalizer.NCNoDigits
                else:
                    notify.info('name contains not allowed utf8 char: 0x%04x' %
                                char)
                    return OTPLocalizer.NCBadCharacter % te.encodeWtext(
                        unichr(char))
            else:
                # Restrict the number of characters, if three-byte-encoded utf-8 character
                # The full-width characters would fit into a single display cell,
                # and the half-width characters would fit two to a display cell
                if char in halfwidthCharacter:
                    dc += 0.5
                else:
                    dc += 1

        # Japan restricts the number of the characters, if occupied less then two display cell
        # and more then eight display cell.
        if (dc < 2):
            notify.info('name is too short: %0.1f' % dc)
            return OTPLocalizer.NCTooShort
        elif (dc > 8):
            notify.info(
                'name has been occupied more than eight display cells: %0.1f' %
                dc)
            return OTPLocalizer.NCGeneric