Commit 5de88b4b authored by John (J5) Palmieri's avatar John (J5) Palmieri
Browse files
parent f129b3db
......@@ -379,7 +379,32 @@ check_number_release:
break;
}
case GI_TYPE_TAG_UNICHAR:
/* TODO: check if it is a single valid utf8 character? */
{
Py_ssize_t size;
if (PyUnicode_Check (object)) {
size = PyUnicode_GET_SIZE (object);
#if PY_VERSION_HEX < 0x03000000
} else if (PyString_Check (object)) {
PyObject *pyuni = PyUnicode_FromEncodedObject (object, "UTF-8", "strict");
size = PyUnicode_GET_SIZE (pyuni);
Py_DECREF(pyuni);
#endif
} else {
PyErr_Format (PyExc_TypeError, "Must be string, not %s",
object->ob_type->tp_name);
retval = 0;
break;
}
if (size != 1) {
PyErr_Format (PyExc_TypeError, "Must be a one character string, not %i characters",
size);
retval = 0;
break;
}
break;
}
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME:
if (!PYGLIB_PyBaseString_Check (object) ) {
......
# -*- Mode: Python; py-indent-offset: 4 -*-
# coding=utf-8
# vim: tabstop=4 shiftwidth=4 expandtab
import unittest
......@@ -13,6 +14,13 @@ from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Regress as Everything
if sys.version_info < (3, 0):
UNICHAR = "\xe2\x99\xa5"
PY2_UNICODE_UNICHAR = unicode(UNICHAR, 'UTF-8')
else:
UNICHAR = "♥"
class TestEverything(unittest.TestCase):
def test_cairo_context(self):
......@@ -50,8 +58,13 @@ class TestEverything(unittest.TestCase):
def test_unichar(self):
self.assertEquals("c", Everything.test_unichar("c"))
self.assertEquals("", Everything.test_unichar(""))
self.assertEquals("\xe2\x99\xa5", Everything.test_unichar("\xe2\x99\xa5"))
if sys.version_info < (3, 0):
self.assertEquals(UNICHAR, Everything.test_unichar(PY2_UNICODE_UNICHAR))
self.assertEquals(UNICHAR, Everything.test_unichar(UNICHAR))
self.assertRaises(TypeError, Everything.test_unichar, "")
self.assertRaises(TypeError, Everything.test_unichar, "morethanonechar")
def test_floating(self):
Everything.TestFloating()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment