Skip to content

Commit 91f4904

Browse files
author
ronald.oussoren
committed
Fix for issue1594
git-svn-id: http://svn.python.org/projects/python/trunk@68156 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent a259cca commit 91f4904

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

Lib/test/test_macos.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,66 @@
33
import Carbon.File
44
from test import test_support
55
import os
6+
import subprocess
67

78
TESTFN2 = test_support.TESTFN + '2'
89

910
class TestMacOS(unittest.TestCase):
1011

12+
def testGetCreatorAndType(self):
13+
if not os.path.exists('/Developer/Tools/SetFile'):
14+
return
15+
16+
try:
17+
fp = open(test_support.TESTFN, 'w')
18+
fp.write('\n')
19+
fp.close()
20+
21+
subprocess.call(
22+
['/Developer/Tools/SetFile', '-t', 'ABCD', '-c', 'EFGH',
23+
test_support.TESTFN])
24+
25+
cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
26+
self.assertEquals(tp, 'ABCD')
27+
self.assertEquals(cr, 'EFGH')
28+
29+
finally:
30+
os.unlink(test_support.TESTFN)
31+
32+
def testSetCreatorAndType(self):
33+
if not os.path.exists('/Developer/Tools/GetFileInfo'):
34+
return
35+
36+
try:
37+
fp = open(test_support.TESTFN, 'w')
38+
fp.write('\n')
39+
fp.close()
40+
41+
MacOS.SetCreatorAndType(test_support.TESTFN,
42+
'ABCD', 'EFGH')
43+
44+
cr, tp = MacOS.GetCreatorAndType(test_support.TESTFN)
45+
self.assertEquals(cr, 'ABCD')
46+
self.assertEquals(tp, 'EFGH')
47+
48+
data = subprocess.Popen(["/Developer/Tools/GetFileInfo", test_support.TESTFN],
49+
stdout=subprocess.PIPE).communicate()[0]
50+
51+
tp = None
52+
cr = None
53+
for ln in data.splitlines():
54+
if ln.startswith('type:'):
55+
tp = ln.split()[-1][1:-1]
56+
if ln.startswith('creator:'):
57+
cr = ln.split()[-1][1:-1]
58+
59+
self.assertEquals(cr, 'ABCD')
60+
self.assertEquals(tp, 'EFGH')
61+
62+
finally:
63+
os.unlink(test_support.TESTFN)
64+
65+
1166
def testOpenRF(self):
1267
try:
1368
fp = open(test_support.TESTFN, 'w')

Mac/Modules/MacOS.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3030
#include <Carbon/Carbon.h>
3131
#include <ApplicationServices/ApplicationServices.h>
3232

33+
#include <arpa/inet.h> /* for ntohl, htonl */
34+
35+
3336
#ifndef HAVE_OSX105_SDK
3437
typedef SInt16 FSIORefNum;
3538
#endif
@@ -310,6 +313,10 @@ MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
310313
if ((err = FSpGetFInfo(&fss, &info)) != noErr) {
311314
return PyErr_Mac(MacOS_Error, err);
312315
}
316+
317+
info.fdCreator = ntohl(info.fdCreator);
318+
info.fdType = ntohl(info.fdType);
319+
313320
creator = PyString_FromStringAndSize(
314321
(char *)&info.fdCreator, 4);
315322
type = PyString_FromStringAndSize((char *)&info.fdType, 4);
@@ -341,6 +348,8 @@ MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
341348

342349
}
343350
finfo = (FileInfo*)&(cataloginfo.finderInfo);
351+
finfo->fileCreator = ntohl(finfo->fileCreator);
352+
finfo->fileType = ntohl(finfo->fileType);
344353
creator = PyString_FromStringAndSize((char*)&(finfo->fileCreator), 4);
345354
type = PyString_FromStringAndSize((char*)&(finfo->fileType), 4);
346355

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ Library
224224
- Issue #4730: Fixed the cPickle module to handle correctly astral characters
225225
when protocol 0 is used.
226226

227+
- Issue #1594: MacOS.GetCreatorAndType now always returns a big-endian result,
228+
to be consistent with Apple tools.
229+
227230
Tools/Demos
228231
-----------
229232

0 commit comments

Comments
 (0)