Пример #1
0
 def limit_to_decimal_digits(sender, event):
     if not Char.IsDigit(event.KeyChar) and \
             not Char.IsControl(event.KeyChar) and \
             not event.KeyChar == '.' and \
             not event.KeyChar == '-':
         event.Handled = True
     if event.KeyChar == '.' and '.' in sender.Text:
         event.Handled = True
Пример #2
0
def StripPunctuation(playerInputText, preserveQuotes):
    source = ""

    for chr in playerInputText:
        if not Char.IsPunctuation(chr) or (preserveQuotes and chr == '"'):
            source += chr

    return source
Пример #3
0
    def test_to_type_conversions(self):
        from System import Decimal, Double, Single
        from System import Int64, UInt64, Int32, UInt32, Int16, UInt16, Byte, SByte
        from System import Boolean, Char, DateTime, Object, Enum, DateTimeKind

        val = 1
        for i in [big(val), Int32(val)]:
            self.assertEqual(i.ToDecimal(self.p), val)
            self.assertIsInstance(i.ToDecimal(self.p), Decimal)
            self.assertEqual(i.ToDouble(self.p), val)
            self.assertIsInstance(i.ToDouble(self.p), Double)
            self.assertEqual(i.ToSingle(self.p), val)
            self.assertIsInstance(i.ToSingle(self.p), Single)
            self.assertEqual(i.ToInt64(self.p), val)
            self.assertIsInstance(i.ToInt64(self.p), Int64)
            self.assertEqual(i.ToUInt64(self.p), val)
            self.assertIsInstance(i.ToUInt64(self.p), UInt64)
            self.assertEqual(i.ToInt32(self.p), val)
            self.assertIsInstance(i.ToInt32(self.p), Int32)
            self.assertEqual(i.ToUInt32(self.p), val)
            self.assertIsInstance(i.ToUInt32(self.p), UInt32)
            self.assertEqual(i.ToInt16(self.p), val)
            self.assertIsInstance(i.ToInt16(self.p), Int16)
            self.assertEqual(i.ToUInt16(self.p), val)
            self.assertIsInstance(i.ToUInt16(self.p), UInt16)
            self.assertEqual(i.ToByte(self.p), val)
            self.assertIsInstance(i.ToByte(self.p), Byte)
            self.assertEqual(i.ToSByte(self.p), val)
            self.assertIsInstance(i.ToSByte(self.p), SByte)
            self.assertEqual(i.ToBoolean(self.p), val)
            self.assertIsInstance(i.ToBoolean(self.p), Boolean)
            self.assertEqual(i.ToChar(self.p), Char(val))
            self.assertEqual(i.ToString(self.p), str(val))
            self.assertRaisesRegex(TypeError,
                                   r"Invalid cast from '\w+' to 'DateTime'",
                                   i.ToDateTime, self.p)

            for t in [
                    Decimal, Double, Single, Int64, UInt64, Int32, UInt32,
                    Int16, UInt16, Byte, SByte, Boolean, Char, str
            ]:
                self.assertEqual(i.ToType(t, self.p), t(i))

            self.assertEqual(i.ToType(Object, self.p), i)
            self.assertIsInstance(i.ToType(Object, self.p), Object)
            self.assertRaisesRegex(TypeError,
                                   r"Invalid cast from '\w+' to 'DateTime'",
                                   i.ToType, DateTime, self.p)
            self.assertRaisesRegex(
                TypeError,
                r"Invalid cast from '[\w.]+' to 'System.DateTimeKind'\.",
                i.ToType, DateTimeKind, self.p)
            if not is_mono:
                self.assertRaisesRegex(
                    TypeError,
                    r"Unable to cast object of type '[\w.]+' to type 'System.Enum'\.",
                    i.ToType, Enum, self.p)
Пример #4
0
def db(p, addr, len=128, bytesPerLine=16):
    words = p.GetVirtualByteLen(addr, len)
    curr = 0
    while curr < len:
        Misc.WxColor(ConsoleColor.White, ConsoleColor.Black,
                     VIRTUAL_ADDRESS(addr + curr).xStr + " ")
        for c in range(0, bytesPerLine):
            Misc.WxColor(ConsoleColor.Green, ConsoleColor.Black,
                         words[curr + c].ToString("x2") + " ")
        for ch in range(0, bytesPerLine):
            myChar = Encoding.ASCII.GetString(words, curr + ch, 1)[0]
            if Char.IsLetterOrDigit(myChar) == False:
                myChar = " "
            Misc.WxColor(ConsoleColor.Cyan, ConsoleColor.Black, myChar + " ")
        Console.Write(Environment.NewLine)
        curr = curr + bytesPerLine
Пример #5
0
def IsProjectYearFolderName(folderName):
    return (len(folderName) == 2 and Char.IsDigit(folderName[0])
            and Char.IsDigit(folderName[1]))
Пример #6
0
    def test_char_new(self):
        from System import Char, Int32, UInt16

        self.assertEqual(Char(), '\x00')
        self.assertEqual(Char('a'), 'a')
        self.assertEqual(Char(ord('A')), 'A')
        self.assertEqual(Char(chr(65)), 'A')
        self.assertEqual(Char(UInt16(65)), 'A')
        self.assertEqual(Char(Int32(65)), 'A')
        self.assertEqual(Char(big(65)), 'A')
        self.assertEqual(Char('€'), '€')

        self.assertIsInstance(Char(), Char)
        self.assertIsInstance(Char('a'), Char)
        self.assertIsInstance(Char(65), Char)

        self.assertRaises(TypeError, Char, 'a', 'b')
        self.assertRaises(
            TypeError,
            Char,
            'ab',
        )
        self.assertRaises(TypeError, Char, '🐍')  # surrogate pair
        self.assertRaises(TypeError, Char, '\U0001F40D')  # surrogate pair
        self.assertEqual(Char('🐍'[0]), '\uD83D')  # high surrogate

        self.assertRaises(TypeError, Char.__new__, str)
        self.assertRaises(TypeError, Char.__new__, str, 'a')
        self.assertRaises(TypeError, Char.__new__, str, 65)
        self.assertRaises(TypeError, Char.__new__, int)
        self.assertRaises(TypeError, Char.__new__, int, 'a')
        self.assertRaises(TypeError, Char.__new__, int, 65)

        # ValueError would be OK too
        self.assertRaises(OverflowError, Char, -1)
        self.assertRaises(OverflowError, Char, 0x110000)
        self.assertRaises(OverflowError, Char, 0x10000)
Пример #7
0
    def test_bigint(self):
        from System import Int64, Boolean, Char, Double, Single, IConvertible
        from System.Numerics import BigInteger
        self.assertEqual(
            BigInteger.Add(
                big(1),
                99999999999999999999999999999999999999999999999999999999999),
            BigInteger.Subtract(
                100000000000000000000000000000000000000000000000000000000001,
                big(1)))
        self.assertEqual(BigInteger.Multiply(big(400), big(500)),
                         BigInteger.Divide(big(1000000), big(5)))
        self.assertEqual(BigInteger.Multiply(big(400), big(8)),
                         big(400) << big(3))
        self.assertEqual(BigInteger.Divide(big(400), big(8)),
                         big(400) >> big(3))
        self.assertEqual((big(400) << big(100)) >> big(100), big(400))
        self.assertEqual((-12345678987654321 << big(100)) >> big(100),
                         -12345678987654321)
        self.assertRaises(ValueError, lambda x, y: x >> y, big(400), -big(100))
        self.assertRaises(ValueError, lambda x, y: x << y, big(400), -big(100))
        self.assertRaises(ValueError, lambda x, y: x >> y, -12345678987654321,
                          -big(100))
        self.assertRaises(ValueError, lambda x, y: x << y, -12345678987654321,
                          -big(100))
        self.assertEqual(
            ~(~big(
                -123456781234567812345678123456781234567812345678123456781234567812345678
            )),
            -123456781234567812345678123456781234567812345678123456781234567812345678
        )
        self.assertEqual(
            ~big(
                -1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678
            ),
            -(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678
              + big(1)))
        self.assertTrue(
            big(-1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678
                ) ^
            (~big(
                -1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678
            )), -big(1))
        self.assertEqual(
            big(0xff00ff00) & (big(0x00ff00ff) | big(0xaabbaabb)),
            big(0xaa00aa00))
        self.assertEqual(
            big(-9999999999999999999999999999999999999999) %
            1000000000000000000, -(9999999999999999999999999999999999999999 %
                                   big(-1000000000000000000)))

        self.assertEqual(Int64(big(0x7fffffffffffffff)), 9223372036854775807)
        self.assertRaises(OverflowError, Int64, big(0x8000000000000000))

        self.assertEqual(Boolean(big(-0)), False)
        self.assertEqual(Boolean(big(int(-1212321.3213))), True)
        self.assertEqual(Boolean(big(1212321384892342394723947)), True)

        self.assertEqual(Char(big(0)), Char.MinValue)
        self.assertEqual(Char(big(65)), IConvertible.ToChar('A', self.p))
        self.assertEqual(Char(big(0xffff)), Char.MaxValue)
        self.assertRaises(OverflowError, Char, big(-1))

        self.assertEqual(Double(big(100)), 100.0)
        self.assertEqual(Single(big(100)), 100.0)
        self.assertEqual(Single(big(100)),
                         IConvertible.ToSingle(int(100.1213123), self.p))

        self.assertTrue(big(100) != 100.32)
        self.assertEqual(big(100), 100.0)

        self.assertTrue(100.32 != big(100))
        self.assertEqual(100.0, big(100))