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
df9b6431
Commit
df9b6431
authored
Mar 13, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
major cleanup to fix Py3 code issues (found by 2to3 and 'python2.6 -3')
parent
fb4dc542
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
57 additions
and
66 deletions
+57
-66
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-3
Cython/Distutils/build_ext.py
Cython/Distutils/build_ext.py
+2
-2
Cython/Distutils/extension.py
Cython/Distutils/extension.py
+1
-1
Cython/Mac/MacSystem.py
Cython/Mac/MacSystem.py
+6
-6
Cython/Mac/TS_Misc_Suite.py
Cython/Mac/TS_Misc_Suite.py
+5
-5
Cython/Plex/DFA.py
Cython/Plex/DFA.py
+9
-9
Cython/Plex/Machines.py
Cython/Plex/Machines.py
+6
-9
Cython/Plex/Regexps.py
Cython/Plex/Regexps.py
+6
-7
Cython/Plex/Traditional.py
Cython/Plex/Traditional.py
+2
-2
Cython/Plex/Transitions.py
Cython/Plex/Transitions.py
+8
-13
Cython/Shadow.py
Cython/Shadow.py
+9
-9
No files found.
Cython/Compiler/Nodes.py
View file @
df9b6431
...
...
@@ -2,7 +2,7 @@
# Pyrex - Parse tree nodes
#
import
s
tring
,
s
ys
,
os
,
time
,
copy
import
sys
,
os
,
time
,
copy
import
Code
import
Builtin
...
...
@@ -1412,7 +1412,7 @@ class CFuncDefNode(FuncDefNode):
arg_decls
=
[
"void"
]
if
cname
is
None
:
cname
=
self
.
entry
.
func_cname
entity
=
type
.
function_header_code
(
cname
,
string
.
join
(
arg_decls
,
", "
))
entity
=
type
.
function_header_code
(
cname
,
', '
.
join
(
arg_decls
))
if
visibility
==
'public'
:
dll_linkage
=
"DL_EXPORT"
else
:
...
...
@@ -3790,7 +3790,7 @@ class WhileStatNode(LoopNode, StatNode):
def
ForStatNode
(
pos
,
**
kw
):
if
kw
.
has_key
(
'iterator'
)
:
if
'iterator'
in
kw
:
return
ForInStatNode
(
pos
,
**
kw
)
else
:
return
ForFromStatNode
(
pos
,
**
kw
)
...
...
Cython/Distutils/build_ext.py
View file @
df9b6431
...
...
@@ -7,7 +7,7 @@ building Cython extension modules."""
__revision__
=
"$Id:$"
import
sys
,
os
,
string
,
re
import
sys
,
os
,
re
from
types
import
*
from
distutils.core
import
Command
from
distutils.errors
import
*
...
...
@@ -72,7 +72,7 @@ class build_ext(_build_ext.build_ext):
self
.
pyrex_include_dirs
=
[]
elif
type
(
self
.
pyrex_include_dirs
)
is
StringType
:
self
.
pyrex_include_dirs
=
\
s
tring
.
split
(
self
.
pyrex_include_dirs
,
os
.
pathsep
)
s
elf
.
pyrex_include_dirs
.
split
(
os
.
pathsep
)
# finalize_options ()
def
build_extensions
(
self
):
...
...
Cython/Distutils/extension.py
View file @
df9b6431
...
...
@@ -5,7 +5,7 @@ Pyrex extension modules in setup scripts."""
__revision__
=
"$Id:$"
import
os
,
s
tring
,
s
ys
import
os
,
sys
from
types
import
*
import
distutils.extension
as
_Extension
...
...
Cython/Mac/MacSystem.py
View file @
df9b6431
...
...
@@ -2,7 +2,7 @@
# Pyrex -- Mac system interface
#
import
os
,
sys
,
string
import
os
,
sys
import
aetools
from
aetools
import
TalkTo
from
StdSuites.Standard_Suite
import
Standard_Suite_Events
as
Standard_Suite
...
...
@@ -57,8 +57,8 @@ def do_toolserver_command(command):
errn
,
stat
,
stdout
,
stderr
=
result
if
errn
:
raise
CCompilerError
(
"ToolServer error: %s"
%
errn
)
stdout
=
st
ring
.
replace
(
stdout
,
"
\
r
"
,
"
\
n
"
)
stderr
=
st
ring
.
replace
(
stderr
,
"
\
r
"
,
"
\
n
"
)
stdout
=
st
dout
.
replace
(
"
\
r
"
,
"
\
n
"
)
stderr
=
st
derr
.
replace
(
"
\
r
"
,
"
\
n
"
)
if
stdout
:
#print "<<< Begin ToolServer StdOut >>>"
sys
.
stderr
.
write
(
stdout
)
...
...
@@ -85,7 +85,7 @@ def c_compile(c_file):
command
=
"%s -opt %s -nomapcr -w off -r %s %s -o %s"
%
(
c_compiler
,
c_optimizations
,
string
.
join
(
include_options
),
' '
.
join
(
include_options
),
c_file
,
o_file
,
#e_file
...
...
@@ -106,9 +106,9 @@ def c_link_list(obj_files):
out_file
=
replace_suffix
(
obj_files
[
0
],
shared_lib_suffix
)
command
=
"%s -xm s -export all %s %s %s -o %s"
%
(
c_linker
,
string
.
join
(
obj_files
),
' '
.
join
(
obj_files
),
pythoncore
,
string
.
join
(
libraries
),
' '
.
join
(
libraries
),
out_file
)
stat
=
do_toolserver_command
(
command
)
if
stat
:
...
...
Cython/Mac/TS_Misc_Suite.py
View file @
df9b6431
...
...
@@ -20,7 +20,7 @@ class TS_Misc_Suite(object):
_code
=
'misc'
_subcode
=
'dosc'
if
_arguments
:
raise
TypeError
,
'No optional args expected'
if
_arguments
:
raise
TypeError
(
'No optional args expected'
)
_arguments
[
'----'
]
=
_object
...
...
@@ -35,15 +35,15 @@ class TS_Misc_Suite(object):
stat
=
0
stdout
=
""
stderr
=
""
if
_arguments
.
has_key
(
'errn'
)
:
if
'errn'
in
_arguments
:
errn
=
_arguments
[
'errn'
]
if
errn
:
errn
=
aetools
.
decodeerror
(
_arguments
)
if
_arguments
.
has_key
(
'stat'
)
:
if
'stat'
in
_arguments
:
stat
=
_arguments
[
'stat'
]
if
_arguments
.
has_key
(
'----'
)
:
if
'----'
in
_arguments
:
stdout
=
_arguments
[
'----'
]
if
_arguments
.
has_key
(
'diag'
)
:
if
'diag'
in
_arguments
:
stderr
=
_arguments
[
'diag'
]
return
(
errn
,
stat
,
stdout
,
stderr
)
...
...
Cython/Plex/DFA.py
View file @
df9b6431
...
...
@@ -29,18 +29,18 @@ 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
.
items
():
for
(
key
,
old_state
)
in
old_machine
.
initial_states
.
ite
rite
ms
():
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
# iterating over it. The iteration stops when closure is achieved.
for
new_state
in
new_machine
.
states
:
transitions
=
TransitionMap
()
for
old_state
in
state_map
.
new_to_old
(
new_state
)
.
keys
()
:
for
event
,
old_target_states
in
old_state
.
transitions
.
items
():
for
old_state
in
state_map
.
new_to_old
(
new_state
):
for
event
,
old_target_states
in
old_state
.
transitions
.
ite
rite
ms
():
if
event
and
old_target_states
:
transitions
.
add_set
(
event
,
set_epsilon_closure
(
old_target_states
))
for
event
,
old_states
in
transitions
.
items
():
for
event
,
old_states
in
transitions
.
ite
rite
ms
():
new_machine
.
add_transitions
(
new_state
,
event
,
state_map
.
old_to_new
(
old_states
))
if
debug
:
debug
.
write
(
"
\
n
===== State Mapping =====
\
n
"
)
...
...
@@ -53,8 +53,8 @@ def set_epsilon_closure(state_set):
closures of its member states.
"""
result
=
{}
for
state1
in
state_set
.
keys
()
:
for
state2
in
epsilon_closure
(
state1
)
.
keys
()
:
for
state1
in
state_set
:
for
state2
in
epsilon_closure
(
state1
):
result
[
state2
]
=
1
return
result
...
...
@@ -80,7 +80,7 @@ def add_to_epsilon_closure(state_set, state):
state_set
[
state
]
=
1
state_set_2
=
state
.
transitions
.
get_epsilon
()
if
state_set_2
:
for
state2
in
state_set_2
.
keys
()
:
for
state2
in
state_set_2
:
add_to_epsilon_closure
(
state_set
,
state2
)
class
StateMap
(
object
):
...
...
@@ -119,7 +119,7 @@ class StateMap(object):
def
highest_priority_action
(
self
,
state_set
):
best_action
=
None
best_priority
=
LOWEST_PRIORITY
for
state
in
state_set
.
keys
()
:
for
state
in
state_set
:
priority
=
state
.
action_priority
if
priority
>
best_priority
:
best_action
=
state
.
action
...
...
@@ -142,7 +142,7 @@ class StateMap(object):
Convert a set of states into a uniquified
sorted tuple suitable for use as a dictionary key.
"""
lst
=
state_set
.
keys
(
)
lst
=
list
(
state_set
)
lst
.
sort
()
return
tuple
(
lst
)
...
...
Cython/Plex/Machines.py
View file @
df9b6431
...
...
@@ -6,7 +6,6 @@
#
#=======================================================================
import
string
import
sys
from
sys
import
maxint
from
types
import
TupleType
...
...
@@ -54,7 +53,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
self
.
initial_states
.
items
():
for
(
name
,
state
)
in
self
.
initial_states
.
ite
rite
ms
():
file
.
write
(
" '%s': %d
\
n
"
%
(
name
,
state
.
number
))
for
s
in
self
.
states
:
s
.
dump
(
file
)
...
...
@@ -108,7 +107,6 @@ class Node(object):
return
"State %d"
%
self
.
number
def
dump
(
self
,
file
):
import
string
# Header
file
.
write
(
" State %d:
\
n
"
%
self
.
number
)
# Transitions
...
...
@@ -143,11 +141,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
.
items
():
for
name
,
old_state
in
old_machine
.
initial_states
.
ite
rite
ms
():
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
.
items
():
for
event
,
old_state_set
in
old_state
.
transitions
.
ite
rite
ms
():
if
old_state_set
:
new_state
[
event
]
=
old_to_new
[
old_state_set
.
keys
()[
0
]]
else
:
...
...
@@ -188,13 +186,12 @@ class FastMachine(object):
def
dump
(
self
,
file
):
file
.
write
(
"Plex.FastMachine:
\
n
"
)
file
.
write
(
" Initial states:
\
n
"
)
for
name
,
state
in
self
.
initial_states
.
items
():
for
name
,
state
in
self
.
initial_states
.
ite
rite
ms
():
file
.
write
(
" %s: %s
\
n
"
%
(
repr
(
name
),
state
[
'number'
]))
for
state
in
self
.
states
:
self
.
dump_state
(
state
,
file
)
def
dump_state
(
self
,
state
,
file
):
import
string
# Header
file
.
write
(
" State %d:
\
n
"
%
state
[
'number'
])
# Transitions
...
...
@@ -207,7 +204,7 @@ class FastMachine(object):
def
dump_transitions
(
self
,
state
,
file
):
chars_leading_to_state
=
{}
special_to_state
=
{}
for
(
c
,
s
)
in
state
.
items
():
for
(
c
,
s
)
in
state
.
ite
rite
ms
():
if
len
(
c
)
==
1
:
chars
=
chars_leading_to_state
.
get
(
id
(
s
),
None
)
if
chars
is
None
:
...
...
@@ -249,7 +246,7 @@ class FastMachine(object):
return
tuple
(
result
)
def
ranges_to_string
(
self
,
range_list
):
return
string
.
join
(
map
(
self
.
range_to_string
,
range_list
),
","
)
return
','
.
join
(
map
(
self
.
range_to_string
,
range_list
)
)
def
range_to_string
(
self
,
range_tuple
):
(
c1
,
c2
)
=
range_tuple
...
...
Cython/Plex/Regexps.py
View file @
df9b6431
...
...
@@ -7,7 +7,6 @@
#=======================================================================
import
array
import
string
import
types
from
sys
import
maxint
...
...
@@ -330,7 +329,7 @@ class Seq(RE):
match_bol
=
re
.
match_nl
or
(
match_bol
and
re
.
nullable
)
def
calc_str
(
self
):
return
"Seq(%s)"
%
string
.
join
(
map
(
str
,
self
.
re_list
),
","
)
return
"Seq(%s)"
%
','
.
join
(
map
(
str
,
self
.
re_list
)
)
class
Alt
(
RE
):
...
...
@@ -369,7 +368,7 @@ class Alt(RE):
re
.
build_machine
(
m
,
initial_state
,
final_state
,
0
,
nocase
)
def
calc_str
(
self
):
return
"Alt(%s)"
%
string
.
join
(
map
(
str
,
self
.
re_list
),
","
)
return
"Alt(%s)"
%
','
.
join
(
map
(
str
,
self
.
re_list
)
)
class
Rep1
(
RE
):
...
...
@@ -437,7 +436,7 @@ def Str1(s):
"""
Str1(s) is an RE which matches the literal string |s|.
"""
result
=
apply
(
Seq
,
tuple
(
map
(
Char
,
s
)))
result
=
Seq
(
*
tuple
(
map
(
Char
,
s
)))
result
.
str
=
"Str(%s)"
%
repr
(
s
)
return
result
...
...
@@ -449,8 +448,8 @@ def Str(*strs):
if
len
(
strs
)
==
1
:
return
Str1
(
strs
[
0
])
else
:
result
=
apply
(
Alt
,
tuple
(
map
(
Str1
,
strs
)))
result
.
str
=
"Str(%s)"
%
string
.
join
(
map
(
repr
,
strs
),
","
)
result
=
Alt
(
*
tuple
(
map
(
Str1
,
strs
)))
result
.
str
=
"Str(%s)"
%
','
.
join
(
map
(
repr
,
strs
)
)
return
result
def
Any
(
s
):
...
...
@@ -495,7 +494,7 @@ def Range(s1, s2 = None):
ranges
=
[]
for
i
in
range
(
0
,
len
(
s1
),
2
):
ranges
.
append
(
CodeRange
(
ord
(
s1
[
i
]),
ord
(
s1
[
i
+
1
])
+
1
))
result
=
apply
(
Alt
,
tuple
(
ranges
)
)
result
=
Alt
(
*
ranges
)
result
.
str
=
"Range(%s)"
%
repr
(
s1
)
return
result
...
...
Cython/Plex/Traditional.py
View file @
df9b6431
...
...
@@ -41,7 +41,7 @@ class REParser(object):
while
self
.
c
==
'|'
:
self
.
next
()
re_list
.
append
(
self
.
parse_seq
())
re
=
apply
(
Alt
,
tuple
(
re_list
)
)
re
=
Alt
(
*
re_list
)
return
re
def
parse_seq
(
self
):
...
...
@@ -49,7 +49,7 @@ class REParser(object):
re_list
=
[]
while
not
self
.
end
and
not
self
.
c
in
"|)"
:
re_list
.
append
(
self
.
parse_mod
())
return
apply
(
Seq
,
tuple
(
re_list
)
)
return
Seq
(
*
re_list
)
def
parse_mod
(
self
):
"""Parse a primitive regexp followed by *, +, ? modifiers."""
...
...
Cython/Plex/Transitions.py
View file @
df9b6431
...
...
@@ -6,7 +6,6 @@
#
from
copy
import
copy
import
string
from
sys
import
maxint
from
types
import
TupleType
...
...
@@ -89,10 +88,10 @@ class TransitionMap(object):
"""
return
self
.
special
.
get
(
''
,
none
)
def
items
(
self
,
def
ite
rite
ms
(
self
,
len
=
len
):
"""
Return the mapping as a
list
of ((code1, code2), state_set) and
Return the mapping as a
n iterable
of ((code1, code2), state_set) and
(special_event, state_set) pairs.
"""
result
=
[]
...
...
@@ -108,10 +107,10 @@ class TransitionMap(object):
result
.
append
(((
code0
,
code1
),
set
))
code0
=
code1
i
=
i
+
2
for
event
,
set
in
self
.
special
.
items
():
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
if
set
:
result
.
append
((
event
,
set
))
return
result
return
iter
(
result
)
# ------------------- Private methods --------------------
...
...
@@ -178,10 +177,10 @@ class TransitionMap(object):
map_strs
.
append
(
state_set_str
(
map
[
i
]))
i
=
i
+
1
special_strs
=
{}
for
event
,
set
in
self
.
special
.
items
():
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
special_strs
[
event
]
=
state_set_str
(
set
)
return
"[%s]+%s"
%
(
string
.
join
(
map_strs
,
","
),
','
.
join
(
map_strs
),
special_strs
)
...
...
@@ -200,7 +199,7 @@ class TransitionMap(object):
while
i
<
n
:
self
.
dump_range
(
map
[
i
],
map
[
i
+
2
],
map
[
i
+
1
],
file
)
i
=
i
+
2
for
event
,
set
in
self
.
special
.
items
():
for
event
,
set
in
self
.
special
.
ite
rite
ms
():
if
set
:
if
not
event
:
event
=
'empty'
...
...
@@ -243,11 +242,7 @@ class TransitionMap(object):
# set1[state] = 1
def
state_set_str
(
set
):
state_list
=
set
.
keys
()
str_list
=
[]
for
state
in
state_list
:
str_list
.
append
(
"S%d"
%
state
.
number
)
return
"[%s]"
%
string
.
join
(
str_list
,
","
)
return
"[%s]"
%
','
.
join
([
"S%d"
%
state
.
number
for
state
in
set
])
Cython/Shadow.py
View file @
df9b6431
...
...
@@ -57,12 +57,12 @@ class PointerType(CythonType):
def
__getitem__
(
self
,
ix
):
if
ix
<
0
:
raise
IndexError
,
"negative indexing not allowed in C"
raise
IndexError
(
"negative indexing not allowed in C"
)
return
self
.
_items
[
ix
]
def
__setitem__
(
self
,
ix
,
value
):
if
ix
<
0
:
raise
IndexError
,
"negative indexing not allowed in C"
raise
IndexError
(
"negative indexing not allowed in C"
)
self
.
_items
[
ix
]
=
cast
(
self
.
_basetype
,
value
)
class
ArrayType
(
PointerType
):
...
...
@@ -74,22 +74,22 @@ class ArrayType(PointerType):
class
StructType
(
CythonType
):
def
__init__
(
self
,
**
data
):
for
key
,
value
in
data
.
items
():
for
key
,
value
in
data
.
ite
rite
ms
():
setattr
(
self
,
key
,
value
)
def
__setattr__
(
self
,
key
,
value
):
if
key
in
self
.
_members
:
self
.
__dict__
[
key
]
=
cast
(
self
.
_members
[
key
],
value
)
else
:
raise
AttributeError
,
"Struct has no member '%s'"
%
key
raise
AttributeError
(
"Struct has no member '%s'"
%
key
)
class
UnionType
(
CythonType
):
def
__init__
(
self
,
**
data
):
if
len
(
data
)
>
0
:
raise
AttributeError
,
"Union can only store one field at a time."
for
key
,
value
in
data
.
items
():
raise
AttributeError
(
"Union can only store one field at a time."
)
for
key
,
value
in
data
.
ite
rite
ms
():
setattr
(
self
,
key
,
value
)
def
__setattr__
(
self
,
key
,
value
):
...
...
@@ -98,7 +98,7 @@ class UnionType(CythonType):
elif
key
in
self
.
_members
:
self
.
__dict__
=
{
key
:
cast
(
self
.
_members
[
key
],
value
)}
else
:
raise
AttributeError
,
"Union has no member '%s'"
%
key
raise
AttributeError
(
"Union has no member '%s'"
%
key
)
def
pointer
(
basetype
):
class
PointerInstance
(
PointerType
):
...
...
@@ -114,14 +114,14 @@ def array(basetype, n):
def
struct
(
**
members
):
class
StructInstance
(
StructType
):
_members
=
members
for
key
in
members
.
keys
()
:
for
key
in
members
:
setattr
(
StructInstance
,
key
,
None
)
return
StructInstance
def
union
(
**
members
):
class
UnionInstance
(
UnionType
):
_members
=
members
for
key
in
members
.
keys
()
:
for
key
in
members
:
setattr
(
UnionInstance
,
key
,
None
)
return
UnionInstance
...
...
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