Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
b58bb78d
Commit
b58bb78d
authored
Feb 20, 2013
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default encoding test.
parent
1e81abf9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
5 deletions
+56
-5
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+3
-0
Cython/Utility/TypeConversion.c
Cython/Utility/TypeConversion.c
+0
-5
tests/errors/string_assignments.pyx
tests/errors/string_assignments.pyx
+10
-0
tests/run/unicode_default_encoding.pyx
tests/run/unicode_default_encoding.pyx
+43
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
b58bb78d
...
...
@@ -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
)
...
...
Cython/Utility/TypeConversion.c
View file @
b58bb78d
...
...
@@ -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
);
...
...
tests/errors/string_assignments.pyx
View file @
b58bb78d
...
...
@@ -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'
"""
tests/run/unicode_default_encoding.pyx
0 → 100644
View file @
b58bb78d
#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
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment