Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6dd561bd
Kaydet (Commit)
6dd561bd
authored
Ara 26, 2002
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Integrated macfsn into macfs, and made the Standard File calls return the
correct FSSpec implementations.
üst
315e9beb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
170 deletions
+140
-170
macfs.py
Mac/Lib/macfs.py
+140
-8
macfsn.py
Mac/Lib/macfsn.py
+0
-162
No files found.
Mac/Lib/macfs.py
Dosyayı görüntüle @
6dd561bd
...
...
@@ -2,6 +2,10 @@
macfs and MACFS.
"""
import
sys
import
struct
import
Carbon.Res
import
Carbon.File
import
Nav
# First step: ensure we also emulate the MACFS module, which contained
# all the constants
...
...
@@ -11,19 +15,19 @@ sys.modules['MACFS'] = sys.modules[__name__]
# Import all those constants
from
Carbon.Files
import
*
from
Carbon.Folders
import
*
# Another method:
from
Carbon.Folder
import
FindFolder
# For some obscure historical reason these are here too:
READ
=
1
WRITE
=
2
smAllScripts
=
-
3
import
Carbon.File
# The old name of the error object:
error
=
Carbon
.
File
.
Error
#
# The various objects macfs used to export. We override them here, because some
# of the method names are subtly different.
#
class
FSSpec
(
Carbon
.
File
.
FSSpec
):
def
as_fsref
(
self
):
return
FSRef
(
self
)
...
...
@@ -72,12 +76,14 @@ class Alias(Carbon.File.Alias):
return
FSSpec
(
fss
),
changed
from
Carbon.File
import
FInfo
# Backward-compatible type names:
FSSpecType
=
FSSpec
FSRefType
=
FSRef
AliasType
=
Alias
FInfoType
=
FInfo
# Global functions:
def
ResolveAliasFile
(
fss
,
chain
=
1
):
fss
,
isdir
,
isalias
=
Carbon
.
File
.
ResolveAliasFile
(
fss
,
chain
)
return
FSSpec
(
fss
),
isdir
,
isalias
...
...
@@ -94,5 +100,132 @@ def FindApplication(*args):
def
NewAliasMinimalFromFullPath
(
path
):
return
Alias
(
Carbon
.
File
.
NewAliasMinimalFromFullPath
(
path
,
''
,
''
))
# Finally, install nav services
import
macfsn
\ No newline at end of file
# Another global function:
from
Carbon.Folder
import
FindFolder
#
# Finally the old Standard File routine emulators.
#
_movablemodal
=
0
_curfolder
=
None
def
_mktypelist
(
typelist
):
# Workaround for OSX typeless files:
if
'TEXT'
in
typelist
and
not
'
\0\0\0\0
'
in
typelist
:
typelist
=
typelist
+
(
'
\0\0\0\0
'
,)
if
not
typelist
:
return
None
data
=
'Pyth'
+
struct
.
pack
(
"hh"
,
0
,
len
(
typelist
))
for
type
in
typelist
:
data
=
data
+
type
return
Carbon
.
Res
.
Handle
(
data
)
def
StandardGetFile
(
*
typelist
):
"""Ask for an input file, optionally specifying 4-char file types that are
allowable"""
return
apply
(
PromptGetFile
,
(
None
,)
+
typelist
)
def
PromptGetFile
(
prompt
,
*
typelist
):
"""Ask for an input file giving the user a prompt message. Optionally you can
specifying 4-char file types that are allowable"""
args
=
{}
flags
=
0x56
typehandle
=
_mktypelist
(
typelist
)
if
typehandle
:
args
[
'typeList'
]
=
typehandle
else
:
flags
=
flags
|
0x01
if
prompt
:
args
[
'message'
]
=
prompt
args
[
'preferenceKey'
]
=
'PyMC'
if
_movablemodal
:
args
[
'eventProc'
]
=
None
args
[
'dialogOptionFlags'
]
=
flags
_handleSetFolder
(
args
)
try
:
rr
=
Nav
.
NavChooseFile
(
args
)
good
=
1
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
good
=
0
fss
=
None
else
:
if
rr
.
selection
:
fss
=
FSSpec
(
rr
.
selection
[
0
])
else
:
fss
=
None
good
=
0
## if typehandle:
## typehandle.DisposeHandle()
return
fss
,
good
def
StandardPutFile
(
prompt
,
default
=
None
):
"""Ask the user for an output file, with a prompt. Optionally you cn supply a
default output filename"""
args
=
{}
flags
=
0x07
if
prompt
:
args
[
'message'
]
=
prompt
args
[
'preferenceKey'
]
=
'PyMC'
if
_movablemodal
:
args
[
'eventProc'
]
=
None
if
default
:
args
[
'savedFileName'
]
=
default
args
[
'dialogOptionFlags'
]
=
flags
_handleSetFolder
(
args
)
try
:
rr
=
Nav
.
NavPutFile
(
args
)
good
=
1
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
good
=
0
fss
=
None
else
:
fss
=
FSSpec
(
rr
.
selection
[
0
])
return
fss
,
good
def
SetFolder
(
folder
):
global
_curfolder
if
_curfolder
:
rv
=
_curfolder
else
:
rv
=
None
_curfolder
=
FSSpec
(
folder
)
return
rv
def
_handleSetFolder
(
args
):
global
_curfolder
if
not
_curfolder
:
return
import
aepack
fss
=
_curfolder
aedesc
=
aepack
.
pack
(
fss
)
args
[
'defaultLocation'
]
=
aedesc
_curfolder
=
None
def
GetDirectory
(
prompt
=
None
):
"""Ask the user to select a folder. Optionally you can give a prompt."""
args
=
{}
flags
=
0x17
if
prompt
:
args
[
'message'
]
=
prompt
args
[
'preferenceKey'
]
=
'PyMC'
if
_movablemodal
:
args
[
'eventProc'
]
=
None
args
[
'dialogOptionFlags'
]
=
flags
_handleSetFolder
(
args
)
try
:
rr
=
Nav
.
NavChooseFolder
(
args
)
good
=
1
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
good
=
0
fss
=
None
else
:
fss
=
FSSpec
(
rr
.
selection
[
0
])
return
fss
,
good
Mac/Lib/macfsn.py
deleted
100644 → 0
Dosyayı görüntüle @
315e9beb
"""StandardFile compatability module: implement macfs StandardFile
API calls with Navigation Services"""
import
macfs
import
struct
from
Carbon
import
Res
try
:
import
Nav
except
ImportError
:
Nav
=
None
_curfolder
=
None
_movablemodal
=
1
def
_mktypelist
(
typelist
):
# Workaround for OSX typeless files:
if
'TEXT'
in
typelist
and
not
'
\0\0\0\0
'
in
typelist
:
typelist
=
typelist
+
(
'
\0\0\0\0
'
,)
if
not
typelist
:
return
None
data
=
'Pyth'
+
struct
.
pack
(
"hh"
,
0
,
len
(
typelist
))
for
type
in
typelist
:
data
=
data
+
type
return
Res
.
Handle
(
data
)
def
_StandardGetFile
(
*
typelist
):
return
apply
(
_PromptGetFile
,
(
None
,)
+
typelist
)
def
_PromptGetFile
(
prompt
,
*
typelist
):
args
=
{}
flags
=
0x56
typehandle
=
_mktypelist
(
typelist
)
if
typehandle
:
args
[
'typeList'
]
=
typehandle
else
:
flags
=
flags
|
0x01
if
prompt
:
args
[
'message'
]
=
prompt
args
[
'preferenceKey'
]
=
'PyMC'
if
_movablemodal
:
args
[
'eventProc'
]
=
None
args
[
'dialogOptionFlags'
]
=
flags
_handleSetFolder
(
args
)
try
:
rr
=
Nav
.
NavChooseFile
(
args
)
good
=
1
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
good
=
0
fss
=
None
else
:
if
rr
.
selection
:
fss
=
rr
.
selection
[
0
]
else
:
fss
=
None
good
=
0
## if typehandle:
## typehandle.DisposeHandle()
return
fss
,
good
def
_StandardPutFile
(
prompt
,
default
=
None
):
args
=
{}
flags
=
0x07
if
prompt
:
args
[
'message'
]
=
prompt
args
[
'preferenceKey'
]
=
'PyMC'
if
_movablemodal
:
args
[
'eventProc'
]
=
None
if
default
:
args
[
'savedFileName'
]
=
default
args
[
'dialogOptionFlags'
]
=
flags
_handleSetFolder
(
args
)
try
:
rr
=
Nav
.
NavPutFile
(
args
)
good
=
1
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
good
=
0
fss
=
None
else
:
fss
=
rr
.
selection
[
0
]
return
fss
,
good
def
_SetFolder
(
folder
):
global
_curfolder
if
_curfolder
:
rv
=
_curfolder
else
:
rv
=
None
_curfolder
=
macfs
.
FSSpec
(
folder
)
return
rv
def
_handleSetFolder
(
args
):
global
_curfolder
if
not
_curfolder
:
return
import
aepack
fss
=
macfs
.
FSSpec
(
_curfolder
)
aedesc
=
aepack
.
pack
(
fss
)
args
[
'defaultLocation'
]
=
aedesc
_curfolder
=
None
def
_GetDirectory
(
prompt
=
None
):
args
=
{}
flags
=
0x17
if
prompt
:
args
[
'message'
]
=
prompt
args
[
'preferenceKey'
]
=
'PyMC'
if
_movablemodal
:
args
[
'eventProc'
]
=
None
args
[
'dialogOptionFlags'
]
=
flags
_handleSetFolder
(
args
)
try
:
rr
=
Nav
.
NavChooseFolder
(
args
)
good
=
1
except
Nav
.
error
,
arg
:
if
arg
[
0
]
!=
-
128
:
# userCancelledErr
raise
Nav
.
error
,
arg
good
=
0
fss
=
None
else
:
fss
=
rr
.
selection
[
0
]
return
fss
,
good
def
_install
():
macfs
.
StandardGetFile
=
StandardGetFile
macfs
.
PromptGetFile
=
PromptGetFile
macfs
.
StandardPutFile
=
StandardPutFile
macfs
.
SetFolder
=
SetFolder
macfs
.
GetDirectory
=
GetDirectory
if
Nav
and
Nav
.
NavServicesAvailable
():
StandardGetFile
=
_StandardGetFile
PromptGetFile
=
_PromptGetFile
StandardPutFile
=
_StandardPutFile
SetFolder
=
_SetFolder
GetDirectory
=
_GetDirectory
_install
()
else
:
from
macfs
import
StandardGetFile
,
PromptGetFile
,
StandardPutFile
,
SetFolder
,
GetDirectory
if
__name__
==
'__main__'
:
print
'Testing StandardGetFile'
fss
,
ok
=
StandardGetFile
()
print
'->'
,
fss
,
ok
print
'Testing StandardGetFile("TEXT")'
fss
,
ok
=
StandardGetFile
(
"TEXT"
)
print
'->'
,
fss
,
ok
print
'Testing PromptGetFile'
fss
,
ok
=
PromptGetFile
(
"prompt"
)
print
'->'
,
fss
,
ok
print
'Testing StandardPutFile("the prompt", "default")'
fss
,
ok
=
StandardPutFile
(
"the prompt"
,
"default"
)
print
'->'
,
fss
,
ok
print
'Testing GetDirectory("another prompt")'
fss
,
ok
=
GetDirectory
(
"Another prompt"
)
print
'->'
,
fss
,
ok
import
sys
sys
.
exit
(
1
)
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