Commit b58bb78d authored by Robert Bradshaw's avatar Robert Bradshaw

Default encoding test.

parent 1e81abf9
......@@ -2266,6 +2266,9 @@ class CPtrType(CPointerBaseType):
return self.base_type.same_as(other.base_type)
return False
def __ne__(self, other):
return not (self == other)
def __repr__(self):
return "<CPtrType %s>" % repr(self.base_type)
......
......@@ -57,16 +57,12 @@ static int __Pyx_init_sys_getdefaultencoding_not_ascii() {
} else {
char* normalized_encoding_c;
codecs = PyImport_ImportModule("codecs");
printf("codecs %p\n", codecs);
if (codecs == NULL) goto bad;
normalized_encoding = PyObject_CallMethod(codecs, (char*) (const char*) "lookup", (char*) (const char*) "O", default_encoding);
printf("normalized_encoding %p\n", normalized_encoding);
if (normalized_encoding == NULL) goto bad;
normalized_encoding_name = PyObject_GetAttrString(normalized_encoding, (char*) (const char*) "name");
printf("normalized_encoding_name %p\n", normalized_encoding_name);
if (normalized_encoding_name == NULL) goto bad;
normalized_encoding_c = PyBytes_AsString(normalized_encoding_name);
printf("normalized_encoding_c %s\n", normalized_encoding_c);
if (normalized_encoding_c == NULL) goto bad;
__Pyx_sys_getdefaultencoding_not_ascii = strcmp(normalized_encoding_c, "ascii");
if (!__Pyx_sys_getdefaultencoding_not_ascii) {
......@@ -84,7 +80,6 @@ static int __Pyx_init_sys_getdefaultencoding_not_ascii() {
}
}
}
printf("__Pyx_sys_getdefaultencoding_not_ascii %d\n", __Pyx_sys_getdefaultencoding_not_ascii);
Py_XDECREF(sys);
Py_XDECREF(default_encoding);
Py_XDECREF(codecs);
......
......@@ -50,6 +50,11 @@ cdef list l_f1 = s1
cdef list l_f2 = b1
cdef list l_f3 = u1
print <str>c1
print <str>c1[1:2]
print <unicode>c1
print <unicode>c1[1:2]
_ERRORS = u"""
26:20: Unicode literals do not support coercion to C types other than Py_UNICODE or Py_UCS4.
27:22: Unicode objects do not support coercion to C types.
......@@ -73,4 +78,9 @@ _ERRORS = u"""
45:19: Cannot assign type 'str object' to 'tuple object'
46:18: Cannot assign type 'unicode object' to 'tuple object'
47:18: Cannot assign type 'bytes object' to 'tuple object'
53:13: default encoding required for conversion from 'char *' to 'str object'
54:13: default encoding required for conversion from 'char *' to 'str object'
55:17: Cannot convert 'char*' to unicode implicitly, decoding required
56:17: default encoding required for conversion from 'char *' to 'unicode object'
"""
#cython: c_string_type = str
#cython: c_string_encoding = ascii
from libc.string cimport strcmp
def as_objects(char* ascii_data):
"""
>>> as_objects('abc')
'abc'
"""
assert isinstance(<object>ascii_data, str)
assert isinstance(<bytes>ascii_data, bytes)
assert isinstance(<str>ascii_data, str)
assert isinstance(<unicode>ascii_data, unicode)
return ascii_data
def from_object():
"""
>>> from_object()
"""
cdef bytes b = b"abc"
cdef str s = "abc"
cdef unicode u = u"abc"
assert strcmp(<char*>b, "abc") == 0
assert strcmp(<char*>s, "abc") == 0
assert strcmp(<char*>u, "abc") == 0
def slice_as_objects(char* ascii_data, int start, int end):
"""
>>> slice_as_objects('grok', 1, 3)
'ro'
"""
assert isinstance(<object>ascii_data[start:end], str)
assert isinstance(<bytes>ascii_data[start:end], bytes)
assert isinstance(<str>ascii_data[start:end], str)
assert isinstance(<unicode>ascii_data[start:end], unicode)
assert isinstance(<object>ascii_data[start:], str)
assert isinstance(<bytes>ascii_data[start:], bytes)
assert isinstance(<str>ascii_data[start:], str)
assert isinstance(<unicode>ascii_data[start:], unicode)
return ascii_data[start:end]
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