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
38abf1b6
Commit
38abf1b6
authored
Jul 25, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make dict iteration compatible with Py2/Py3
parent
caa2fe39
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
78 additions
and
91 deletions
+78
-91
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+1
-1
Cython/Build/Inline.py
Cython/Build/Inline.py
+2
-3
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+8
-10
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+3
-5
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+2
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+1
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-10
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+6
-6
Cython/Compiler/Pipeline.py
Cython/Compiler/Pipeline.py
+2
-2
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+1
-1
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+2
-2
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+1
-1
Cython/Compiler/TypeSlots.py
Cython/Compiler/TypeSlots.py
+1
-1
Cython/Compiler/UtilityCode.py
Cython/Compiler/UtilityCode.py
+1
-1
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+1
-1
Cython/Debugger/Tests/test_libcython_in_gdb.py
Cython/Debugger/Tests/test_libcython_in_gdb.py
+1
-1
Cython/Debugger/libcython.py
Cython/Debugger/libcython.py
+10
-12
Cython/Debugger/libpython.py
Cython/Debugger/libpython.py
+9
-8
Cython/Distutils/extension.py
Cython/Distutils/extension.py
+1
-1
Cython/Plex/DFA.py
Cython/Plex/DFA.py
+3
-3
Cython/Plex/Machines.py
Cython/Plex/Machines.py
+5
-5
Cython/Plex/Transitions.py
Cython/Plex/Transitions.py
+3
-3
Cython/Tempita/_tempita.py
Cython/Tempita/_tempita.py
+6
-11
No files found.
Cython/Build/Dependencies.py
View file @
38abf1b6
...
...
@@ -878,7 +878,7 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, quiet=False, fo
if
exclude_failures
:
failed_modules
=
set
()
for
c_file
,
modules
in
modules_by_cfile
.
ite
rite
ms
():
for
c_file
,
modules
in
modules_by_cfile
.
items
():
if
not
os
.
path
.
exists
(
c_file
):
failed_modules
.
update
(
modules
)
elif
os
.
path
.
getsize
(
c_file
)
<
200
:
...
...
Cython/Build/Inline.py
View file @
38abf1b6
...
...
@@ -149,8 +149,7 @@ def cython_inline(code,
if
arg
is
cython_module
:
cimports
.
append
(
'
\
n
cimport cython as %s'
%
name
)
del
kwds
[
name
]
arg_names
=
kwds
.
keys
()
arg_names
.
sort
()
arg_names
=
sorted
(
kwds
)
arg_sigs
=
tuple
([(
get_type
(
kwds
[
arg
],
ctx
),
arg
)
for
arg
in
arg_names
])
key
=
orig_code
,
arg_sigs
,
sys
.
version_info
,
sys
.
executable
,
Cython
.
__version__
module_name
=
"_cython_inline_"
+
hashlib
.
md5
(
str
(
key
).
encode
(
'utf-8'
)).
hexdigest
()
...
...
@@ -282,7 +281,7 @@ except ImportError:
if
kwds
is
not
None
:
all
[
kwds
]
=
kwd_values
elif
kwd_values
:
raise
TypeError
(
"Unexpected keyword arguments: %s"
%
kwd_values
.
keys
(
))
raise
TypeError
(
"Unexpected keyword arguments: %s"
%
list
(
kwd_values
))
if
defaults
is
None
:
defaults
=
()
first_default
=
len
(
args
)
-
len
(
defaults
)
...
...
Cython/Compiler/Buffer.py
View file @
38abf1b6
...
...
@@ -49,25 +49,22 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
# For all buffers, insert extra variables in the scope.
# The variables are also accessible from the buffer_info
# on the buffer entry
bufvars
=
[
entry
for
name
,
entry
in
scope
.
entries
.
iteritems
()
if
entry
.
type
.
is_buffer
]
scope_items
=
scope
.
entries
.
items
()
bufvars
=
[
entry
for
name
,
entry
in
scope_items
if
entry
.
type
.
is_buffer
]
if
len
(
bufvars
)
>
0
:
bufvars
.
sort
(
key
=
lambda
entry
:
entry
.
name
)
self
.
buffers_exists
=
True
memviewslicevars
=
[
entry
for
name
,
entry
in
scope
.
entries
.
iteritems
()
if
entry
.
type
.
is_memoryviewslice
]
memviewslicevars
=
[
entry
for
name
,
entry
in
scope_items
if
entry
.
type
.
is_memoryviewslice
]
if
len
(
memviewslicevars
)
>
0
:
self
.
buffers_exists
=
True
for
(
name
,
entry
)
in
scope
.
entries
.
iteritems
()
:
for
(
name
,
entry
)
in
scope
_items
:
if
name
==
'memoryview'
and
isinstance
(
entry
.
utility_code_definition
,
CythonUtilityCode
):
self
.
using_memoryview
=
True
break
del
scope_items
if
isinstance
(
node
,
ModuleNode
)
and
len
(
bufvars
)
>
0
:
# for now...note that pos is wrong
...
...
@@ -143,13 +140,14 @@ def analyse_buffer_options(globalpos, env, posargs, dictargs, defaults=None, nee
if
defaults
is
None
:
defaults
=
buffer_defaults
posargs
,
dictargs
=
Interpreter
.
interpret_compiletime_options
(
posargs
,
dictargs
,
type_env
=
env
,
type_args
=
(
0
,
'dtype'
))
posargs
,
dictargs
=
Interpreter
.
interpret_compiletime_options
(
posargs
,
dictargs
,
type_env
=
env
,
type_args
=
(
0
,
'dtype'
))
if
len
(
posargs
)
>
buffer_positional_options_count
:
raise
CompileError
(
posargs
[
-
1
][
1
],
ERR_BUF_TOO_MANY
)
options
=
{}
for
name
,
(
value
,
pos
)
in
dictargs
.
ite
rite
ms
():
for
name
,
(
value
,
pos
)
in
dictargs
.
items
():
if
not
name
in
buffer_options
:
raise
CompileError
(
pos
,
ERR_BUF_OPTION_UNKNOWN
%
name
)
options
[
name
]
=
value
...
...
Cython/Compiler/Code.py
View file @
38abf1b6
...
...
@@ -774,9 +774,8 @@ class FunctionState(object):
error case.
"""
return [(cname, type)
for (type, manage_ref), freelist in self.temps_free.items()
if manage_ref
for cname in freelist]
for (type, manage_ref), freelist in self.temps_free.items() if manage_ref
for cname in freelist]
def start_collecting_temps(self):
"""
...
...
@@ -1303,8 +1302,7 @@ class GlobalState(object):
cleanup
.
putln
(
"Py_CLEAR(%s.method);"
%
cname
)
def
generate_string_constants
(
self
):
c_consts
=
[
(
len
(
c
.
cname
),
c
.
cname
,
c
)
for
c
in
self
.
string_const_index
.
values
()
]
c_consts
=
[(
len
(
c
.
cname
),
c
.
cname
,
c
)
for
c
in
self
.
string_const_index
.
values
()]
c_consts
.
sort
()
py_strings
=
[]
...
...
Cython/Compiler/FlowControl.py
View file @
38abf1b6
...
...
@@ -259,7 +259,7 @@ class ControlFlow(object):
for
entry
in
block
.
bounded
:
block
.
i_kill
|=
self
.
assmts
[
entry
].
bit
for
assmts
in
self
.
assmts
.
iter
values
():
for
assmts
in
self
.
assmts
.
values
():
self
.
entry_point
.
i_gen
|=
assmts
.
bit
self
.
entry_point
.
i_output
=
self
.
entry_point
.
i_gen
...
...
@@ -602,7 +602,7 @@ def check_definitions(flow, compiler_directives):
node
.
cf_maybe_null
=
False
# Find uninitialized references and cf-hints
for
node
,
entry
in
references
.
ite
rite
ms
():
for
node
,
entry
in
references
.
items
():
if
Uninitialized
in
node
.
cf_state
:
node
.
cf_maybe_null
=
True
if
not
entry
.
from_closure
and
len
(
node
.
cf_state
)
==
1
:
...
...
Cython/Compiler/ModuleNode.py
View file @
38abf1b6
...
...
@@ -413,7 +413,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
d
.
setdefault
(
cython_lineno
,
[]).
append
(
c_lineno
+
1
)
tb
.
start
(
'LineNumberMapping'
)
for
cython_lineno
,
c_linenos
in
sorted
(
d
.
ite
rite
ms
()):
for
cython_lineno
,
c_linenos
in
sorted
(
d
.
items
()):
attrs
=
{
'c_linenos'
:
' '
.
join
(
map
(
str
,
c_linenos
)),
'cython_lineno'
:
str
(
cython_lineno
),
...
...
Cython/Compiler/Nodes.py
View file @
38abf1b6
...
...
@@ -320,7 +320,6 @@ class Node(object):
else
:
return
repr
(
x
)
attrs
=
[(
key
,
value
)
for
key
,
value
in
self
.
__dict__
.
items
()
if
key
not
in
filter_out
]
if
len
(
attrs
)
==
0
:
return
"<%s (0x%x)>"
%
(
self
.
__class__
.
__name__
,
id
(
self
))
...
...
@@ -1945,8 +1944,7 @@ class FuncDefNode(StatNode, BlockNode):
# Clean up buffers -- this calls a Python function
# so need to save and restore error state
buffers_present
=
len
(
lenv
.
buffer_entries
)
>
0
memslice_entries
=
[
e
for
e
in
lenv
.
entries
.
itervalues
()
if
e
.
type
.
is_memoryviewslice
]
#memslice_entries = [e for e in lenv.entries.values() if e.type.is_memoryviewslice]
if
buffers_present
:
code
.
globalstate
.
use_utility_code
(
restore_exception_utility_code
)
code
.
putln
(
"{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;"
)
...
...
@@ -7405,7 +7403,7 @@ class FromCImportStatNode(StatNode):
env
.
add_imported_module
(
module_scope
)
for
pos
,
name
,
as_name
,
kind
in
self
.
imported_names
:
if
name
==
"*"
:
for
local_name
,
entry
in
module_scope
.
entries
.
items
(
):
for
local_name
,
entry
in
list
(
module_scope
.
entries
.
items
()
):
env
.
add_imported_entry
(
local_name
,
entry
,
pos
)
else
:
entry
=
module_scope
.
lookup
(
name
)
...
...
@@ -7668,7 +7666,7 @@ class ParallelStatNode(StatNode, ParallelNode):
else
:
self
.
kwargs
=
{}
for
kw
,
val
in
self
.
kwargs
.
ite
rite
ms
():
for
kw
,
val
in
self
.
kwargs
.
items
():
if
kw
not
in
self
.
valid_keyword_arguments
:
error
(
self
.
pos
,
"Invalid keyword argument: %s"
%
kw
)
else
:
...
...
@@ -7709,7 +7707,7 @@ class ParallelStatNode(StatNode, ParallelNode):
This should be called in a post-order fashion during the
analyse_expressions phase
"""
for
entry
,
(
pos
,
op
)
in
self
.
assignments
.
ite
rite
ms
():
for
entry
,
(
pos
,
op
)
in
self
.
assignments
.
items
():
if
self
.
is_prange
and
not
self
.
is_parallel
:
# closely nested prange in a with parallel block, disallow
...
...
@@ -7826,7 +7824,7 @@ class ParallelStatNode(StatNode, ParallelNode):
def
initialize_privates_to_nan
(
self
,
code
,
exclude
=
None
):
first
=
True
for
entry
,
(
op
,
lastprivate
)
in
self
.
privates
.
ite
rite
ms
():
for
entry
,
(
op
,
lastprivate
)
in
self
.
privates
.
items
():
if
not
op
and
(
not
exclude
or
entry
!=
exclude
):
invalid_value
=
entry
.
type
.
invalid_value
()
...
...
@@ -8088,7 +8086,7 @@ class ParallelStatNode(StatNode, ParallelNode):
c
=
self
.
begin_of_parallel_control_block_point
temp_count
=
0
for
entry
,
(
op
,
lastprivate
)
in
self
.
privates
.
ite
rite
ms
():
for
entry
,
(
op
,
lastprivate
)
in
self
.
privates
.
items
():
if
not
lastprivate
or
entry
.
type
.
is_pyobject
:
continue
...
...
@@ -8617,7 +8615,7 @@ class ParallelRangeNode(ParallelStatNode):
code
.
putln
(
"#ifdef _OPENMP"
)
code
.
put
(
"#pragma omp for"
)
for
entry
,
(
op
,
lastprivate
)
in
self
.
privates
.
ite
rite
ms
():
for
entry
,
(
op
,
lastprivate
)
in
self
.
privates
.
items
():
# Don't declare the index variable as a reduction
if
op
and
op
in
"+*-&^|"
and
entry
!=
self
.
target
.
entry
:
if
entry
.
type
.
is_pyobject
:
...
...
@@ -8737,7 +8735,7 @@ class CnameDecoratorNode(StatNode):
scope
.
scope_prefix
=
self
.
cname
+
"_"
for
name
,
entry
in
scope
.
entries
.
ite
rite
ms
():
for
name
,
entry
in
scope
.
entries
.
items
():
if
entry
.
func_cname
:
entry
.
func_cname
=
self
.
mangle
(
entry
.
cname
)
if
entry
.
pyfunc_cname
:
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
38abf1b6
...
...
@@ -647,7 +647,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
'cast'
,
'pointer'
,
'compiled'
,
'NULL'
,
'fused_type'
,
'parallel'
])
special_methods
.
update
(
unop_method_nodes
.
keys
()
)
special_methods
.
update
(
unop_method_nodes
)
valid_parallel_directives
=
set
([
"parallel"
,
...
...
@@ -934,7 +934,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
directives
=
self
.
_extract_directives
(
node
,
'function'
)
if
not
directives
:
return
node
for
name
,
value
in
directives
.
ite
rite
ms
():
for
name
,
value
in
directives
.
items
():
if
name
==
'locals'
:
node
.
directive_locals
=
value
elif
name
not
in
(
'final'
,
'staticmethod'
):
...
...
@@ -2888,11 +2888,11 @@ class DebugTransform(CythonTransform):
self
.
tb
.
start
(
'Globals'
)
entries
=
{}
for
k
,
v
in
node
.
scope
.
entries
.
ite
rite
ms
():
for
k
,
v
in
node
.
scope
.
entries
.
items
():
if
(
v
.
qualified_name
not
in
self
.
visited
and
not
v
.
name
.
startswith
(
'__pyx_'
)
and
not
v
.
type
.
is_cfunction
and
not
v
.
type
.
is_extension_type
):
v
.
name
.
startswith
(
'__pyx_'
)
and
not
v
.
type
.
is_cfunction
and
not
v
.
type
.
is_extension_type
):
entries
[
k
]
=
v
self
.
serialize_local_variables
(
entries
)
...
...
Cython/Compiler/Pipeline.py
View file @
38abf1b6
...
...
@@ -57,7 +57,7 @@ def generate_pyx_code_stage_factory(options, result):
def
inject_pxd_code_stage_factory
(
context
):
def
inject_pxd_code_stage
(
module_node
):
for
name
,
(
statlistnode
,
scope
)
in
context
.
pxds
.
ite
rite
ms
():
for
name
,
(
statlistnode
,
scope
)
in
context
.
pxds
.
items
():
module_node
.
merge_in
(
statlistnode
,
scope
)
return
module_node
return
inject_pxd_code_stage
...
...
@@ -66,7 +66,7 @@ def use_utility_code_definitions(scope, target, seen=None):
if
seen
is
None
:
seen
=
set
()
for
entry
in
scope
.
entries
.
iter
values
():
for
entry
in
scope
.
entries
.
values
():
if
entry
in
seen
:
continue
...
...
Cython/Compiler/PyrexTypes.py
View file @
38abf1b6
...
...
@@ -4123,7 +4123,7 @@ def merge_template_deductions(a, b):
if
a
is
None
or
b
is
None
:
return
None
all
=
a
for
param
,
value
in
b
.
ite
rite
ms
():
for
param
,
value
in
b
.
items
():
if
param
in
all
:
if
a
[
param
]
!=
b
[
param
]:
return
None
...
...
Cython/Compiler/Symtab.py
View file @
38abf1b6
...
...
@@ -344,7 +344,7 @@ class Scope(object):
def
merge_in
(
self
,
other
,
merge_unused
=
True
,
whitelist
=
None
):
# Use with care...
entries
=
[]
for
name
,
entry
in
other
.
entries
.
ite
rite
ms
():
for
name
,
entry
in
other
.
entries
.
items
():
if
not
whitelist
or
name
in
whitelist
:
if
entry
.
used
or
merge_unused
:
entries
.
append
((
name
,
entry
))
...
...
@@ -899,7 +899,7 @@ class BuiltinScope(Scope):
Scope
.
__init__
(
self
,
"__builtin__"
,
PreImportScope
(),
None
)
self
.
type_names
=
{}
for
name
,
definition
in
s
elf
.
builtin_entries
.
iteritems
(
):
for
name
,
definition
in
s
orted
(
self
.
builtin_entries
.
items
()
):
cname
,
type
=
definition
self
.
declare_var
(
name
,
type
,
None
,
cname
)
...
...
Cython/Compiler/TreeFragment.py
View file @
38abf1b6
...
...
@@ -219,7 +219,7 @@ class TreeFragment(object):
fmt_code
=
fmt
(
code
)
fmt_pxds
=
{}
for
key
,
value
in
pxds
.
ite
rite
ms
():
for
key
,
value
in
pxds
.
items
():
fmt_pxds
[
key
]
=
fmt
(
value
)
mod
=
t
=
parse_from_strings
(
name
,
fmt_code
,
fmt_pxds
,
level
=
level
,
initial_pos
=
initial_pos
)
if
level
is
None
:
...
...
Cython/Compiler/TypeSlots.py
View file @
38abf1b6
...
...
@@ -71,7 +71,7 @@ class Signature(object):
}
type_to_format_map
=
dict
(
(
type_
,
format_
)
for
format_
,
type_
in
format_map
.
ite
rite
ms
())
(
type_
,
format_
)
for
format_
,
type_
in
format_map
.
items
())
error_value_map
=
{
'O'
:
"NULL"
,
...
...
Cython/Compiler/UtilityCode.py
View file @
38abf1b6
...
...
@@ -186,7 +186,7 @@ class CythonUtilityCode(Code.UtilityCodeBase):
entries
.
pop
(
'__builtins__'
)
entries
.
pop
(
'__doc__'
)
for
name
,
entry
in
entries
.
ite
rite
ms
():
for
name
,
entry
in
entries
.
items
():
entry
.
utility_code_definition
=
self
entry
.
used
=
used
...
...
Cython/Compiler/Visitor.py
View file @
38abf1b6
...
...
@@ -249,7 +249,7 @@ class VisitorTransform(TreeVisitor):
"""
def
visitchildren
(
self
,
parent
,
attrs
=
None
):
result
=
self
.
_visitchildren
(
parent
,
attrs
)
for
attr
,
newnode
in
result
.
ite
rite
ms
():
for
attr
,
newnode
in
result
.
items
():
if
type
(
newnode
)
is
not
list
:
setattr
(
parent
,
attr
,
newnode
)
else
:
...
...
Cython/Debugger/Tests/test_libcython_in_gdb.py
View file @
38abf1b6
...
...
@@ -45,7 +45,7 @@ def print_on_call_decorator(func):
class
TraceMethodCallMeta
(
type
):
def
__init__
(
self
,
name
,
bases
,
dict
):
for
func_name
,
func
in
dict
.
ite
rite
ms
():
for
func_name
,
func
in
dict
.
items
():
if
inspect
.
isfunction
(
func
):
setattr
(
self
,
func_name
,
print_on_call_decorator
(
func
))
...
...
Cython/Debugger/libcython.py
View file @
38abf1b6
...
...
@@ -381,7 +381,7 @@ class CythonBase(object):
result
=
{}
seen
=
set
()
for
k
,
v
in
pyobject_dict
.
ite
rite
ms
():
for
k
,
v
in
pyobject_dict
.
items
():
result
[
k
.
proxyval
(
seen
)]
=
v
return
result
...
...
@@ -849,10 +849,10 @@ class CyBreak(CythonCommand):
def
complete
(
self
,
text
,
word
):
# Filter init-module functions (breakpoints can be set using
# modulename:linenumber).
names
=
[
n
for
n
,
L
in
self
.
cy
.
functions_by_name
.
ite
rite
ms
()
if
any
(
not
f
.
is_initmodule_function
for
f
in
L
)]
qnames
=
[
n
for
n
,
f
in
self
.
cy
.
functions_by_qualified_name
.
ite
rite
ms
()
if
not
f
.
is_initmodule_function
]
names
=
[
n
for
n
,
L
in
self
.
cy
.
functions_by_name
.
items
()
if
any
(
not
f
.
is_initmodule_function
for
f
in
L
)]
qnames
=
[
n
for
n
,
f
in
self
.
cy
.
functions_by_qualified_name
.
items
()
if
not
f
.
is_initmodule_function
]
if
parameters
.
complete_unqualified
:
all_names
=
itertools
.
chain
(
qnames
,
names
)
...
...
@@ -1142,7 +1142,7 @@ class CyLocals(CythonCommand):
local_cython_vars
=
cython_function
.
locals
max_name_length
=
len
(
max
(
local_cython_vars
,
key
=
len
))
for
name
,
cyvar
in
sorted
(
local_cython_vars
.
ite
rite
ms
(),
key
=
sortkey
):
for
name
,
cyvar
in
sorted
(
local_cython_vars
.
items
(),
key
=
sortkey
):
if
self
.
is_initialized
(
self
.
get_cython_function
(),
cyvar
.
name
):
value
=
gdb
.
parse_and_eval
(
cyvar
.
cname
)
if
not
value
.
is_optimized_out
:
...
...
@@ -1175,13 +1175,13 @@ class CyGlobals(CyLocals):
seen
=
set
()
print
(
'Python globals:'
)
for
k
,
v
in
sorted
(
global_python_dict
.
ite
rite
ms
(),
key
=
sortkey
):
for
k
,
v
in
sorted
(
global_python_dict
.
items
(),
key
=
sortkey
):
v
=
v
.
get_truncated_repr
(
libpython
.
MAX_OUTPUT_LEN
)
seen
.
add
(
k
)
print
(
' %-*s = %s'
%
(
max_name_length
,
k
,
v
))
print
(
'C globals:'
)
for
name
,
cyvar
in
sorted
(
module_globals
.
ite
rite
ms
(),
key
=
sortkey
):
for
name
,
cyvar
in
sorted
(
module_globals
.
items
(),
key
=
sortkey
):
if
name
not
in
seen
:
try
:
value
=
gdb
.
parse_and_eval
(
cyvar
.
cname
)
...
...
@@ -1204,10 +1204,8 @@ class EvaluateOrExecuteCodeMixin(object):
"Fill a remotely allocated dict with values from the Cython C stack"
cython_func
=
self
.
get_cython_function
()
for
name
,
cyvar
in
cython_func
.
locals
.
iteritems
():
if
(
cyvar
.
type
==
PythonObject
and
self
.
is_initialized
(
cython_func
,
name
)):
for
name
,
cyvar
in
cython_func
.
locals
.
items
():
if
cyvar
.
type
==
PythonObject
and
self
.
is_initialized
(
cython_func
,
name
):
try
:
val
=
gdb
.
parse_and_eval
(
cyvar
.
cname
)
except
RuntimeError
:
...
...
Cython/Debugger/libpython.py
View file @
38abf1b6
...
...
@@ -463,7 +463,7 @@ def _write_instance_repr(out, visited, name, pyop_attrdict, address):
if
isinstance
(
pyop_attrdict
,
PyDictObjectPtr
):
out
.
write
(
'('
)
first
=
True
for
pyop_arg
,
pyop_val
in
pyop_attrdict
.
ite
rite
ms
():
for
pyop_arg
,
pyop_val
in
pyop_attrdict
.
items
():
if
not
first
:
out
.
write
(
', '
)
first
=
False
...
...
@@ -483,8 +483,7 @@ class InstanceProxy(object):
def
__repr__
(
self
):
if
isinstance
(
self
.
attrdict
,
dict
):
kwargs
=
', '
.
join
(
"%s=%r"
%
(
arg
,
val
)
for
arg
,
val
in
self
.
attrdict
.
iteritems
())
kwargs
=
', '
.
join
(
"%s=%r"
%
(
arg
,
val
)
for
arg
,
val
in
self
.
attrdict
.
items
())
return
'<%s(%s) at remote 0x%x>'
%
(
self
.
cl_name
,
kwargs
,
self
.
address
)
else
:
...
...
@@ -693,7 +692,7 @@ class PyDictObjectPtr(PyObjectPtr):
def
iteritems
(
self
):
'''
Yields a sequence of (PyObjectPtr key, PyObjectPtr value) pairs,
analagous to dict.ite
rite
ms()
analagous to dict.items()
'''
for
i
in
safe_range
(
self
.
field
(
'ma_mask'
)
+
1
):
ep
=
self
.
field
(
'ma_table'
)
+
i
...
...
@@ -702,6 +701,8 @@ class PyDictObjectPtr(PyObjectPtr):
pyop_key
=
PyObjectPtr
.
from_pyobject_ptr
(
ep
[
'me_key'
])
yield
(
pyop_key
,
pyop_value
)
items
=
iteritems
def
proxyval
(
self
,
visited
):
# Guard against infinite loops:
if
self
.
as_address
()
in
visited
:
...
...
@@ -709,7 +710,7 @@ class PyDictObjectPtr(PyObjectPtr):
visited
.
add
(
self
.
as_address
())
result
=
{}
for
pyop_key
,
pyop_value
in
self
.
ite
rite
ms
():
for
pyop_key
,
pyop_value
in
self
.
items
():
proxy_key
=
pyop_key
.
proxyval
(
visited
)
proxy_value
=
pyop_value
.
proxyval
(
visited
)
result
[
proxy_key
]
=
proxy_value
...
...
@@ -724,7 +725,7 @@ class PyDictObjectPtr(PyObjectPtr):
out
.
write
(
'{'
)
first
=
True
for
pyop_key
,
pyop_value
in
self
.
ite
rite
ms
():
for
pyop_key
,
pyop_value
in
self
.
items
():
if
not
first
:
out
.
write
(
', '
)
first
=
False
...
...
@@ -924,7 +925,7 @@ class PyFrameObjectPtr(PyObjectPtr):
return
pyop_globals
=
self
.
pyop_field
(
'f_globals'
)
return
pyop_globals
.
iteritems
(
)
return
iter
(
pyop_globals
.
items
()
)
def
iter_builtins
(
self
):
'''
...
...
@@ -935,7 +936,7 @@ class PyFrameObjectPtr(PyObjectPtr):
return
pyop_builtins
=
self
.
pyop_field
(
'f_builtins'
)
return
pyop_builtins
.
iteritems
(
)
return
iter
(
pyop_builtins
.
items
()
)
def
get_var_by_name
(
self
,
name
):
'''
...
...
Cython/Distutils/extension.py
View file @
38abf1b6
...
...
@@ -45,7 +45,7 @@ class Extension(_Extension.Extension):
# Translate pyrex_X to cython_X for backwards compatibility.
had_pyrex_options
=
False
for
key
in
kw
.
keys
(
):
for
key
in
list
(
kw
):
if
key
.
startswith
(
'pyrex_'
):
had_pyrex_options
=
True
kw
[
'cython'
+
key
[
5
:]]
=
kw
.
pop
(
key
)
...
...
Cython/Plex/DFA.py
View file @
38abf1b6
...
...
@@ -32,7 +32,7 @@ def nfa_to_dfa(old_machine, debug=None):
# Seed the process using the initial states of the old machine.
# Make the corresponding new states into initial states of the new
# machine with the same names.
for
(
key
,
old_state
)
in
old_machine
.
initial_states
.
ite
rite
ms
():
for
(
key
,
old_state
)
in
old_machine
.
initial_states
.
items
():
new_state
=
state_map
.
old_to_new
(
epsilon_closure
(
old_state
))
new_machine
.
make_initial_state
(
key
,
new_state
)
# Tricky bit here: we add things to the end of this list while we're
...
...
@@ -40,10 +40,10 @@ def nfa_to_dfa(old_machine, debug=None):
for
new_state
in
new_machine
.
states
:
transitions
=
TransitionMap
()
for
old_state
in
state_map
.
new_to_old
(
new_state
):
for
event
,
old_target_states
in
old_state
.
transitions
.
ite
rite
ms
():
for
event
,
old_target_states
in
old_state
.
transitions
.
items
():
if
event
and
old_target_states
:
transitions
.
add_set
(
event
,
set_epsilon_closure
(
old_target_states
))
for
event
,
old_states
in
transitions
.
ite
rite
ms
():
for
event
,
old_states
in
transitions
.
items
():
new_machine
.
add_transitions
(
new_state
,
event
,
state_map
.
old_to_new
(
old_states
))
if
debug
:
debug
.
write
(
"
\
n
===== State Mapping =====
\
n
"
)
...
...
Cython/Plex/Machines.py
View file @
38abf1b6
...
...
@@ -59,7 +59,7 @@ class Machine(object):
file
.
write
(
"Plex.Machine:
\
n
"
)
if
self
.
initial_states
is
not
None
:
file
.
write
(
" Initial states:
\
n
"
)
for
(
name
,
state
)
in
s
elf
.
initial_states
.
iteritems
(
):
for
(
name
,
state
)
in
s
orted
(
self
.
initial_states
.
items
()
):
file
.
write
(
" '%s': %d
\
n
"
%
(
name
,
state
.
number
))
for
s
in
self
.
states
:
s
.
dump
(
file
)
...
...
@@ -150,11 +150,11 @@ class FastMachine(object):
for
old_state
in
old_machine
.
states
:
new_state
=
self
.
new_state
()
old_to_new
[
old_state
]
=
new_state
for
name
,
old_state
in
old_machine
.
initial_states
.
ite
rite
ms
():
for
name
,
old_state
in
old_machine
.
initial_states
.
items
():
initial_states
[
name
]
=
old_to_new
[
old_state
]
for
old_state
in
old_machine
.
states
:
new_state
=
old_to_new
[
old_state
]
for
event
,
old_state_set
in
old_state
.
transitions
.
ite
rite
ms
():
for
event
,
old_state_set
in
old_state
.
transitions
.
items
():
if
old_state_set
:
new_state
[
event
]
=
old_to_new
[
old_state_set
.
keys
()[
0
]]
else
:
...
...
@@ -195,7 +195,7 @@ class FastMachine(object):
def
dump
(
self
,
file
):
file
.
write
(
"Plex.FastMachine:
\
n
"
)
file
.
write
(
" Initial states:
\
n
"
)
for
name
,
state
in
s
elf
.
initial_states
.
iteritems
(
):
for
name
,
state
in
s
orted
(
self
.
initial_states
.
items
()
):
file
.
write
(
" %s: %s
\
n
"
%
(
repr
(
name
),
state
[
'number'
]))
for
state
in
self
.
states
:
self
.
dump_state
(
state
,
file
)
...
...
@@ -213,7 +213,7 @@ class FastMachine(object):
def
dump_transitions
(
self
,
state
,
file
):
chars_leading_to_state
=
{}
special_to_state
=
{}
for
(
c
,
s
)
in
state
.
ite
rite
ms
():
for
(
c
,
s
)
in
state
.
items
():
if
len
(
c
)
==
1
:
chars
=
chars_leading_to_state
.
get
(
id
(
s
),
None
)
if
chars
is
None
:
...
...
Cython/Plex/Transitions.py
View file @
38abf1b6
...
...
@@ -110,7 +110,7 @@ class TransitionMap(object):
result
.
append
(((
code0
,
code1
),
set
))
code0
=
code1
i
+=
2
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
for
event
,
set
in
self
.
special
.
items
():
if
set
:
result
.
append
((
event
,
set
))
return
iter
(
result
)
...
...
@@ -182,7 +182,7 @@ class TransitionMap(object):
map_strs
.
append
(
state_set_str
(
map
[
i
]))
i
+=
1
special_strs
=
{}
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
for
event
,
set
in
self
.
special
.
items
():
special_strs
[
event
]
=
state_set_str
(
set
)
return
"[%s]+%s"
%
(
','
.
join
(
map_strs
),
...
...
@@ -204,7 +204,7 @@ class TransitionMap(object):
while
i
<
n
:
self
.
dump_range
(
map
[
i
],
map
[
i
+
2
],
map
[
i
+
1
],
file
)
i
+=
2
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
for
event
,
set
in
self
.
special
.
items
():
if
set
:
if
not
event
:
event
=
'empty'
...
...
Cython/Tempita/_tempita.py
View file @
38abf1b6
...
...
@@ -202,7 +202,7 @@ class Template(object):
position=None, name=self.name)
templ = self.get_template(inherit_template, self)
self_ = TemplateObject(self.name)
for name, value in defs.ite
rite
ms():
for name, value in defs.items():
setattr(self_, name, value)
self_.body = body
ns = ns.copy()
...
...
@@ -391,7 +391,7 @@ def paste_script_template_renderer(content, vars, filename=None):
class bunch(dict):
def __init__(self, **kw):
for name, value in kw.ite
rite
ms():
for name, value in kw.items():
setattr(self, name, value)
def __setattr__(self, name, value):
...
...
@@ -413,12 +413,9 @@ class bunch(dict):
return dict.__getitem__(self, key)
def __repr__(self):
items = [
(k, v) for k, v in self.iteritems()]
items.sort()
return '
<%
s
%
s
>
' % (
self.__class__.__name__,
'
'.join(['
%
s
=%
r' % (k, v) for k, v in
items
]))
'
'.join(['
%
s
=%
r' % (k, v) for k, v in
sorted(self.items())
]))
############################################################
## HTML Templating
...
...
@@ -467,10 +464,8 @@ def url(v):
def attr(**kw):
kw = list(kw.iteritems())
kw.sort()
parts = []
for name, value in
kw
:
for name, value in
sorted(kw.items())
:
if value is None:
continue
if name.endswith('
_
'):
...
...
@@ -549,7 +544,7 @@ class TemplateDef(object):
values = {}
sig_args, var_args, var_kw, defaults = self._func_signature
extra_kw = {}
for name, value in kw.ite
rite
ms():
for name, value in kw.items():
if not var_kw and name not in sig_args:
raise TypeError(
'
Unexpected
argument
%
s
' % name)
...
...
@@ -572,7 +567,7 @@ class TemplateDef(object):
raise TypeError(
'
Extra
position
arguments
:
%
s
'
% '
,
'.join([repr(v) for v in args]))
for name, value_expr in defaults.ite
rite
ms():
for name, value_expr in defaults.items():
if name not in values:
values[name] = self._template._eval(
value_expr, self._ns, self._pos)
...
...
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