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
671e6a53
Commit
671e6a53
authored
Dec 11, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better unicode/str handling for user-supplied code.
parent
33aca7ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
Cython/Build/Inline.py
Cython/Build/Inline.py
+12
-2
Cython/Build/Tests/TestInline.py
Cython/Build/Tests/TestInline.py
+1
-1
No files found.
Cython/Build/Inline.py
View file @
671e6a53
...
@@ -17,6 +17,16 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration
...
@@ -17,6 +17,16 @@ from Cython.Compiler.ParseTreeTransforms import CythonTransform, SkipDeclaration
from
Cython.Compiler.TreeFragment
import
parse_from_strings
from
Cython.Compiler.TreeFragment
import
parse_from_strings
from
Cython.Build.Dependencies
import
strip_string_literals
,
cythonize
from
Cython.Build.Dependencies
import
strip_string_literals
,
cythonize
# A utility function to convert user-supplied ASCII strings to unicode.
if
sys
.
version_info
[
0
]
<
3
:
def
to_unicode
(
s
):
if
not
isinstance
(
s
,
unicode
):
return
s
.
decode
(
'ascii'
)
else
:
return
s
else
:
to_unicode
=
lambda
x
:
x
_code_cache
=
{}
_code_cache
=
{}
...
@@ -28,11 +38,10 @@ class AllSymbols(CythonTransform, SkipDeclarations):
...
@@ -28,11 +38,10 @@ class AllSymbols(CythonTransform, SkipDeclarations):
self
.
names
.
add
(
node
.
name
)
self
.
names
.
add
(
node
.
name
)
def
unbound_symbols
(
code
,
context
=
None
):
def
unbound_symbols
(
code
,
context
=
None
):
code
=
to_unicode
(
code
)
if
context
is
None
:
if
context
is
None
:
context
=
Context
([],
default_options
)
context
=
Context
([],
default_options
)
from
Cython.Compiler.ParseTreeTransforms
import
AnalyseDeclarationsTransform
from
Cython.Compiler.ParseTreeTransforms
import
AnalyseDeclarationsTransform
if
isinstance
(
code
,
str
):
code
=
code
.
decode
(
'ascii'
)
tree
=
parse_from_strings
(
'(tree fragment)'
,
code
)
tree
=
parse_from_strings
(
'(tree fragment)'
,
code
)
for
phase
in
context
.
create_pipeline
(
pxd
=
False
):
for
phase
in
context
.
create_pipeline
(
pxd
=
False
):
if
phase
is
None
:
if
phase
is
None
:
...
@@ -90,6 +99,7 @@ def cython_inline(code,
...
@@ -90,6 +99,7 @@ def cython_inline(code,
**
kwds
):
**
kwds
):
if
get_type
is
None
:
if
get_type
is
None
:
get_type
=
lambda
x
:
'object'
get_type
=
lambda
x
:
'object'
code
=
to_unicode
(
code
)
code
,
literals
=
strip_string_literals
(
code
)
code
,
literals
=
strip_string_literals
(
code
)
code
=
strip_common_indent
(
code
)
code
=
strip_common_indent
(
code
)
ctx
=
Context
(
cython_include_dirs
,
default_options
)
ctx
=
Context
(
cython_include_dirs
,
default_options
)
...
...
Cython/Build/Tests/TestInline.py
View file @
671e6a53
...
@@ -12,7 +12,7 @@ test_kwds = dict(force=True, quiet=True)
...
@@ -12,7 +12,7 @@ test_kwds = dict(force=True, quiet=True)
global_value
=
100
global_value
=
100
class
Test
StripLiterals
(
CythonTest
):
class
Test
Inline
(
CythonTest
):
def
test_simple
(
self
):
def
test_simple
(
self
):
self
.
assertEquals
(
inline
(
"return 1+2"
,
**
test_kwds
),
3
)
self
.
assertEquals
(
inline
(
"return 1+2"
,
**
test_kwds
),
3
)
...
...
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