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
Xavier Thompson
cython
Commits
c212735c
Commit
c212735c
authored
Mar 05, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modernise code a bit
parent
78c47d4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
18 deletions
+14
-18
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+14
-18
No files found.
Cython/Compiler/Code.py
View file @
c212735c
...
@@ -18,6 +18,8 @@ import operator
...
@@ -18,6 +18,8 @@ import operator
import
textwrap
import
textwrap
from
string
import
Template
from
string
import
Template
from
functools
import
partial
from
functools
import
partial
from
contextlib
import
closing
from
collections
import
defaultdict
try
:
try
:
import
hashlib
import
hashlib
...
@@ -164,15 +166,12 @@ class UtilityCodeBase(object):
...
@@ -164,15 +166,12 @@ class UtilityCodeBase(object):
{'C': comment}).match
{'C': comment}).match
match_type = re.compile('(.+)[.](proto|impl|init|cleanup)$').match
match_type = re.compile('(.+)[.](proto|impl|init|cleanup)$').match
f = Utils.open_source_file(filename, encoding='UTF-8')
with closing(Utils.open_source_file(filename, encoding='UTF-8')) as f:
try:
all_lines = f.readlines()
all_lines = f.readlines()
finally:
f.close()
utilities =
{}
utilities =
defaultdict(lambda: [None, None, {}])
lines = []
lines = []
tags =
{}
tags =
defaultdict(set)
utility = type = None
utility = type = None
begin_lineno = 0
begin_lineno = 0
...
@@ -192,10 +191,10 @@ class UtilityCodeBase(object):
...
@@ -192,10 +191,10 @@ class UtilityCodeBase(object):
name, type = mtype.groups()
name, type = mtype.groups()
else:
else:
type = 'impl'
type = 'impl'
utility = utilities
.setdefault(name, [None, None, {}])
utility = utilities
[name]
else:
else:
tags
.setdefault(m.group('tag'), set())
.add(m.group('value'))
tags
[m.group('tag')]
.add(m.group('value'))
lines.append('') # keep line number correct
lines.append('')
# keep line number correct
else:
else:
lines.append(rstrip(strip_comments(line)))
lines.append(rstrip(strip_comments(line)))
...
@@ -205,6 +204,7 @@ class UtilityCodeBase(object):
...
@@ -205,6 +204,7 @@ class UtilityCodeBase(object):
# Don't forget to add the last utility code
# Don't forget to add the last utility code
cls._add_utility(utility, type, lines, begin_lineno, tags)
cls._add_utility(utility, type, lines, begin_lineno, tags)
utilities = dict(utilities) # un-defaultdict-ify
cls._utility_cache[path] = utilities
cls._utility_cache[path] = utilities
return utilities
return utilities
...
@@ -230,11 +230,10 @@ class UtilityCodeBase(object):
...
@@ -230,11 +230,10 @@ class UtilityCodeBase(object):
global __loader__
global __loader__
loader = __loader__
loader = __loader__
archive = loader.archive
archive = loader.archive
fileobj = zipfile.ZipFile(archive)
with closing(zipfile.ZipFile(archive)) as fileobj:
listing = [ os.path.basename(name)
listing = [ os.path.basename(name)
for name in fileobj.namelist()
for name in fileobj.namelist()
if os.path.join(archive, name).startswith(utility_dir)]
if os.path.join(archive, name).startswith(utility_dir)]
fileobj.close()
files = [ os.path.join(utility_dir, filename)
files = [ os.path.join(utility_dir, filename)
for filename in listing
for filename in listing
if filename.startswith(prefix) ]
if filename.startswith(prefix) ]
...
@@ -1607,11 +1606,8 @@ class CCodeWriter(object):
...
@@ -1607,11 +1606,8 @@ class CCodeWriter(object):
path
=
os
.
path
.
join
(
include_dir
,
include_file
)
path
=
os
.
path
.
join
(
include_dir
,
include_file
)
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
tmp_path
=
'%s.tmp%s'
%
(
path
,
os
.
getpid
())
tmp_path
=
'%s.tmp%s'
%
(
path
,
os
.
getpid
())
f
=
Utils
.
open_new_file
(
tmp_path
)
with
closing
(
Utils
.
open_new_file
(
tmp_path
))
as
f
:
try
:
f
.
write
(
code
)
f
.
write
(
code
)
finally
:
f
.
close
()
os
.
rename
(
tmp_path
,
path
)
os
.
rename
(
tmp_path
,
path
)
code
=
'#include "%s"
\
n
'
%
path
code
=
'#include "%s"
\
n
'
%
path
self
.
put
(
code
)
self
.
put
(
code
)
...
...
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