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
2d54692f
Commit
2d54692f
authored
Feb 17, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completely redone
parent
930b36b3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
0 deletions
+92
-0
Mac/MPW/Build
Mac/MPW/Build
+3
-0
Mac/mkapplet.py
Mac/mkapplet.py
+89
-0
No files found.
Mac/MPW/Build
0 → 100644
View file @
2d54692f
Make
{
1
}
-
f
MakeFile
>
Make
.
out
Set
Echo
1
Make
.
out
Mac/mkapplet.py
0 → 100644
View file @
2d54692f
"""Add a 'PYC ' resource named "__main__" to a resource file.
This first puts up a dialog asking for a Python source file ('TEXT'),
then one asking for an existing destination file ('APPL' or 'rsrc').
It compiles the Python source into a code object, marshals it into a string,
prefixes the string with a .pyc header, and turns it into a resource,
which is then written to the destination.
If the destination already contains a resource with the same name and type,
it is overwritten.
"""
import
marshal
import
imp
import
macfs
from
Res
import
*
# .pyc file (and 'PYC ' resource magic number)
MAGIC
=
imp
.
get_magic
()
# Complete specification of our resource
RESTYPE
=
'PYC '
RESID
=
128
RESNAME
=
'__main__'
# OpenResFile mode parameters
READ
=
1
WRITE
=
2
def
main
():
# Ask for source text
srcfss
,
ok
=
macfs
.
StandardGetFile
(
'TEXT'
)
if
not
ok
:
return
# Read the source and compile it
# (there's no point asking for a destination if it has a syntax error)
filename
=
srcfss
.
as_pathname
()
fp
=
open
(
filename
)
text
=
fp
.
read
()
fp
.
close
()
code
=
compile
(
text
,
filename
,
"exec"
)
# Ask for destination file
dstfss
,
ok
=
macfs
.
StandardGetFile
(
'APPL'
,
'rsrc'
)
if
not
ok
:
return
# Create the raw data for the resource from the code object
data
=
marshal
.
dumps
(
code
)
del
code
data
=
(
MAGIC
+
'
\
0
\
0
\
0
\
0
'
)
+
data
# Open the resource file
fnum
=
FSpOpenResFile
(
dstfss
.
as_pathname
(),
WRITE
)
# Delete any existing resource with name __main__ or number 128
try
:
res
=
Get1NamedResource
(
RESTYPE
,
RESNAME
)
res
.
RmveResource
()
except
Error
:
pass
try
:
res
=
Get1Resource
(
RESTYPE
,
RESID
)
res
.
RmveResource
()
except
Error
:
pass
# Create the resource and write it
res
=
Resource
(
data
)
res
.
AddResource
(
RESTYPE
,
RESID
,
RESNAME
)
# XXX Are the following two calls needed?
res
.
WriteResource
()
res
.
ReleaseResource
()
# Close the resource file
CloseResFile
(
fnum
)
if
__name__
==
'__main__'
:
main
()
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