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
0acb7f7a
Commit
0acb7f7a
authored
May 31, 1996
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Module to handle PYC resources
parent
31dd5c08
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
Mac/Lib/py_resource.py
Mac/Lib/py_resource.py
+76
-0
No files found.
Mac/Lib/py_resource.py
0 → 100644
View file @
0acb7f7a
"""Creation of PYC resources"""
import
os
import
Res
import
__builtin__
READ
=
1
WRITE
=
2
smAllScripts
=
-
3
def
Pstring
(
str
):
"""Return a pascal-style string from a python-style string"""
if
len
(
str
)
>
255
:
raise
ValueError
,
'String too large'
return
chr
(
len
(
str
))
+
str
def
create
(
dst
,
creator
=
'Pyth'
):
"""Create output file. Return handle and first id to use."""
try
:
os
.
unlink
(
dst
)
except
os
.
error
:
pass
Res
.
FSpCreateResFile
(
dst
,
creator
,
'rsrc'
,
smAllScripts
)
return
open
(
dst
)
def
open
(
dst
):
output
=
Res
.
FSpOpenResFile
(
dst
,
WRITE
)
Res
.
UseResFile
(
output
)
return
output
def
writemodule
(
name
,
id
,
data
,
type
=
'PYC '
):
"""Write pyc code to a PYC resource with given name and id."""
# XXXX Check that it doesn't exist
res
=
Res
.
Resource
(
data
)
res
.
AddResource
(
type
,
id
,
name
)
res
.
WriteResource
()
res
.
ReleaseResource
()
def
frompycfile
(
file
,
name
=
None
):
"""Copy one pyc file to the open resource file"""
if
name
==
None
:
d
,
name
=
os
.
path
.
split
(
file
)
name
=
name
[:
-
4
]
id
=
findfreeid
()
writemodule
(
name
,
id
,
__builtin__
.
open
(
file
,
'rb'
).
read
())
return
id
,
name
def
frompyfile
(
file
,
name
=
None
):
"""Compile python source file to pyc file and add to resource file"""
import
py_compile
py_compile
.
compile
(
file
)
file
=
file
+
'c'
return
frompycfile
(
file
,
name
)
# XXXX Note this is incorrect, it only handles one type and one file....
_firstfreeid
=
None
def
findfreeid
(
type
=
'PYC '
):
"""Find next free id-number for given resource type"""
global
_firstfreeid
if
_firstfreeid
==
None
:
Res
.
SetResLoad
(
0
)
highest
=
511
num
=
Res
.
Count1Resources
(
type
)
for
i
in
range
(
1
,
num
+
1
):
r
=
Res
.
Get1IndResource
(
type
,
i
)
id
,
d1
,
d2
=
r
.
GetResInfo
()
highest
=
max
(
highest
,
id
)
Res
.
SetResLoad
(
1
)
_firstfreeid
=
highest
+
1
id
=
_firstfreeid
_firstfreeid
=
_firstfreeid
+
1
return
id
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