Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
776e7014
Commit
776e7014
authored
Feb 01, 2009
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify write_bytecode for importlib.
parent
20b56e1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
30 deletions
+7
-30
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+7
-30
No files found.
Lib/importlib/_bootstrap.py
View file @
776e7014
...
...
@@ -403,9 +403,8 @@ class _PyFileLoader(object):
return
open
(
source_path
,
encoding
=
encoding
).
read
()
@
check_name
def
write_bytecode
(
self
,
name
,
magic
,
timestamp
,
data
):
"""Write out 'data' for the specified module using the specific
timestamp, returning a boolean
def
write_bytecode
(
self
,
name
,
data
):
"""Write out 'data' for the specified module, returning a boolean
signifying if the write-out actually occurred.
Raises ImportError (just like get_source) if the specified module
...
...
@@ -418,8 +417,6 @@ class _PyFileLoader(object):
file
=
_fileio
.
_FileIO
(
bytecode_path
,
'w'
)
try
:
with
closing
(
file
)
as
bytecode_file
:
bytecode_file
.
write
(
magic
)
bytecode_file
.
write
(
marshal
.
_w_long
(
timestamp
))
bytecode_file
.
write
(
data
)
return
True
except
IOError
as
exc
:
...
...
@@ -430,29 +427,7 @@ class _PyFileLoader(object):
@
check_name
def
get_code
(
self
,
name
):
"""Return the code object for the module.
'self' must implement:
* read_bytecode(name:str) -> (int, int, bytes) or None
Return the magic number, timestamp, and bytecode for the
module. None is returned if not bytecode is available.
* source_mtime(name:str) -> int
Return the last modification time for the source of the module.
Returns None if their is no source.
* read_source(name:str) -> (bytes, str)
Return the source code for the module and the path to use in
the call to 'compile'. Not called if source_mtime returned
None.
* write_bytecode(name:str, magic:bytes, timestamp:int, data:str)
Write out bytecode for the module with the specified magic
number and timestamp. Not called if sys.dont_write_bytecode is
True.
"""
"""Return the code object for the module."""
# XXX Care enough to make sure this call does not happen if the magic
# number is bad?
source_timestamp
=
self
.
source_mtime
(
name
)
...
...
@@ -507,8 +482,10 @@ class _PyFileLoader(object):
code_object
=
compile
(
source
,
source_path
,
'exec'
,
dont_inherit
=
True
)
# Generate bytecode and write it out.
if
not
sys
.
dont_write_bytecode
:
data
=
marshal
.
dumps
(
code_object
)
self
.
write_bytecode
(
name
,
imp
.
get_magic
(),
source_timestamp
,
data
)
data
=
bytearray
(
imp
.
get_magic
())
data
.
extend
(
marshal
.
_w_long
(
source_timestamp
))
data
.
extend
(
marshal
.
dumps
(
code_object
))
self
.
write_bytecode
(
name
,
data
)
return
code_object
def
get_data
(
self
,
path
):
...
...
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