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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
b12402fc
Commit
b12402fc
authored
Feb 19, 2013
by
zaur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test unicode_slicing for compatibility between py2X/py3
parent
dcd7720a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
22 deletions
+102
-22
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-8
tests/run/unicode_slicing.pyx
tests/run/unicode_slicing.pyx
+98
-14
No files found.
Cython/Compiler/ExprNodes.py
View file @
b12402fc
...
...
@@ -3470,6 +3470,8 @@ class SliceIndexNode(ExprNode):
if
base_type
.
is_builtin_type
:
# slicing builtin types returns something of the same type
self
.
type
=
base_type
self
.
base
=
self
.
base
.
as_none_safe_node
(
"'NoneType' object is not subscriptable"
)
c_int
=
PyrexTypes
.
c_py_ssize_t_type
if
self
.
start
:
self
.
start
=
self
.
start
.
coerce_to
(
c_int
,
env
)
...
...
@@ -3486,10 +3488,6 @@ class SliceIndexNode(ExprNode):
error
(
self
.
pos
,
"Slicing is not currently supported for '%s'."
%
self
.
type
)
return
maybe_check
=
self
.
base
.
as_none_safe_node
(
"'NoneType' object is not slicable"
)
if
maybe_check
.
is_nonecheck
:
maybe_check
.
generate_result_code
(
code
)
base_result
=
self
.
base
.
result
()
result
=
self
.
result
()
...
...
@@ -9786,9 +9784,7 @@ class NoneCheckNode(CoercionNode):
code
.
putln
(
"if (unlikely(%s == Py_None)) {"
%
self
.
condition
())
in_nogil_context
=
getattr
(
self
,
"in_nogil_context"
,
False
)
if
in_nogil_context
:
if
self
.
in_nogil_context
:
code
.
put_ensure_gil
()
escape
=
StringEncoding
.
escape_byte_string
...
...
@@ -9804,7 +9800,7 @@ class NoneCheckNode(CoercionNode):
self
.
exception_type_cname
,
escape
(
self
.
exception_message
.
encode
(
'UTF-8'
))))
if
in_nogil_context
:
if
self
.
in_nogil_context
:
code
.
put_release_ensured_gil
()
code
.
putln
(
code
.
error_goto
(
self
.
pos
))
...
...
tests/run/unicode_slicing.pyx
View file @
b12402fc
# coding: utf-8
__doc__
=
u"""
>>> do_slice(u'abcdef', 2, 3)
(u'c', u'cdef', u'ab', u'abcdef', u'cdef', u'ab', u'abcdef')
>>> do_slice(u'abcdef', 0, 5)
(u'abcde', u'abcdef', u'', u'abcdef', u'abcdef', u'', u'abcdef')
>>> do_slice(u'aАbБcСdДeЕfФ', 2, 8)
(u'bБcСdД', u'bБcСdДeЕfФ', u'aА', u'aАbБcСdДeЕfФ', u'bБcСdДeЕfФ', u'aА', u'aАbБcСdДeЕfФ')
>>> do_slice(u'aАbБcСdДeЕfФ', 2, 8)
(u'bБcСdД', u'bБcСdДeЕfФ', u'aА', u'aАbБcСdДeЕfФ', u'bБcСdДeЕfФ', u'aА', u'aАbБcСdДeЕfФ')
>>> do_slice(u'АБСДЕФ', 2, 4)
(u'СД', u'СДЕФ', u'АБ', u'АБСДЕФ', u'СДЕФ', u'АБ', u'АБСДЕФ')
>>> do_slice(None, 2, 4)
>>> do_slice1(u'abcdef', 2, 3)
u'c'
>>> do_slice2(u'abcdef', 2, 3)
u'cdef'
>>> do_slice3(u'abcdef', 2, 3)
u'ab'
>>> do_slice4(u'abcdef', 2, 3)
u'abcdef'
>>> do_slice5(u'abcdef', 2, 3)
u'cdef'
>>> do_slice6(u'abcdef', 2, 3)
u'ab'
>>> do_slice7(u'abcdef', 2, 3)
u'abcdef'
>>> do_slice1(u'abcdef', 0, 5)
u'abcde'
>>> do_slice2(u'abcdef', 0, 5)
u'abcdef'
>>> do_slice3(u'abcdef', 0, 5)
u''
>>> do_slice4(u'abcdef', 0, 5)
u'abcdef'
>>> do_slice5(u'abcdef', 0, 5)
u'abcdef'
>>> do_slice6(u'abcdef', 0, 5)
u''
>>> do_slice7(u'abcdef', 0, 5)
u'abcdef'
>>> do_slice1(u'aАbБcСdДeЕfФ', 2, 8)
u'bБcСdД'
>>> do_slice2(u'aАbБcСdДeЕfФ', 2, 8)
u'bБcСdДeЕfФ'
>>> do_slice3(u'aАbБcСdДeЕfФ', 2, 8)
u'aА'
>>> do_slice4(u'aАbБcСdДeЕfФ', 2, 8)
u'aАbБcСdДeЕfФ'
>>> do_slice5(u'aАbБcСdДeЕfФ', 2, 8)
u'bБcСdДeЕfФ'
>>> do_slice6(u'aАbБcСdДeЕfФ', 2, 8)
u'aА'
>>> do_slice7(u'aАbБcСdДeЕfФ', 2, 8)
u'aАbБcСdДeЕfФ'
>>> do_slice1(u'АБСДЕФ', 2, 4)
u'СД'
>>> do_slice2(u'АБСДЕФ', 2, 4)
u'СДЕФ'
>>> do_slice3(u'АБСДЕФ', 2, 4)
u'АБ'
>>> do_slice4(u'АБСДЕФ', 2, 4)
u'АБСДЕФ'
>>> do_slice5(u'АБСДЕФ', 2, 4)
u'СДЕФ'
>>> do_slice6(u'АБСДЕФ', 2, 4)
u'АБ'
>>> do_slice7(u'АБСДЕФ', 2, 4)
u'АБСДЕФ'
>>> do_slice1(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not slicable
TypeError: 'NoneType' object is not subscriptable
>>> do_slice2(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
>>> do_slice3(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
>>> do_slice4(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
>>> do_slice5(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
>>> do_slice6(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
>>> do_slice7(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
"""
import
sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u"(u'"
,
u"('"
).
replace
(
u" u'"
,
u" '"
)
ss
=
"'"
else
:
ss
=
"u'"
def
do_slice1
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[
i
:
j
]
+
"'"
)
def
do_slice2
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[
i
:]
+
"'"
)
def
do_slice3
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[:
i
]
+
"'"
)
def
do_slice4
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[:]
+
"'"
)
def
do_slice5
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[
i
:
None
]
+
"'"
)
def
do_slice
(
unicode
s
,
int
i
,
int
j
):
return
s
[
i
:
j
],
s
[
i
:],
s
[:
i
],
s
[:],
s
[
i
:
None
],
s
[
None
:
i
],
s
[
None
:
None
]
def
do_slice
6
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[
None
:
i
]
+
"'"
)
def
do_slice7
(
unicode
s
,
int
i
,
int
j
):
print
(
ss
+
s
[
None
:
None
]
+
"'"
)
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