@@ -111,7 +111,7 @@ Rsrc_GetResInfo(RsrcObject *r, PyObject *args)
111
111
short id ;
112
112
ResType type ;
113
113
Str255 name ;
114
- if (!PyArg_Parse (args , "() " ))
114
+ if (!PyArg_ParseTuple (args , "" ))
115
115
return NULL ;
116
116
GetResInfo (r -> h , & id , & type , name );
117
117
return Py_BuildValue ("(is#s#)" ,
@@ -125,7 +125,7 @@ Rsrc_AsBytes(RsrcObject *r, PyObject *args)
125
125
PyObject * rv ;
126
126
char * cp ;
127
127
128
- if (!PyArg_Parse (args , "(l) " , & len ))
128
+ if (!PyArg_ParseTuple (args , "l " , & len ))
129
129
return NULL ;
130
130
HLock (r -> h );
131
131
cp = (char * )* r -> h ;
@@ -140,7 +140,7 @@ Rsrc_AsString(RsrcObject *r, PyObject *args)
140
140
PyObject * rv ;
141
141
unsigned char * cp ;
142
142
143
- if (!PyArg_Parse (args , "() " ))
143
+ if (!PyArg_ParseTuple (args , "" ))
144
144
return NULL ;
145
145
HLock (r -> h );
146
146
cp = (unsigned char * )* r -> h ;
@@ -187,7 +187,7 @@ MacOS_GetResource(PyObject *self, PyObject *args)
187
187
ResType rt ;
188
188
int id ;
189
189
Handle h ;
190
- if (!PyArg_Parse (args , "( O&i) " , GetOSType , & rt , & id ))
190
+ if (!PyArg_ParseTuple (args , "O&i" , GetOSType , & rt , & id ))
191
191
return NULL ;
192
192
h = GetResource (rt , id );
193
193
return (PyObject * )Rsrc_FromHandle (h );
@@ -199,12 +199,65 @@ MacOS_GetNamedResource(PyObject *self, PyObject *args)
199
199
ResType rt ;
200
200
Str255 name ;
201
201
Handle h ;
202
- if (!PyArg_Parse (args , "( O&O&) " , GetOSType , & rt , GetStr255 , & name ))
202
+ if (!PyArg_ParseTuple (args , "O&O&" , GetOSType , & rt , GetStr255 , & name ))
203
203
return NULL ;
204
204
h = GetNamedResource (rt , name );
205
205
return (PyObject * )Rsrc_FromHandle (h );
206
206
}
207
207
208
+ /*----------------------------------------------------------------------*/
209
+ /* Miscellaneous File System Operations */
210
+
211
+ static PyObject *
212
+ MacOS_GetFileType (PyObject * self , PyObject * args )
213
+ {
214
+ Str255 name ;
215
+ FInfo info ;
216
+ PyObject * type , * creator , * res ;
217
+ OSErr err ;
218
+
219
+ if (!PyArg_ParseTuple (args , "O&" , GetStr255 , & name ))
220
+ return NULL ;
221
+ if ((err = GetFInfo (name , 0 , & info )) != noErr ) {
222
+ errno = err ;
223
+ PyErr_SetFromErrno (MacOS_Error );
224
+ return NULL ;
225
+ }
226
+ type = PyString_FromStringAndSize ((char * )& info .fdType , 4 );
227
+ creator = PyString_FromStringAndSize ((char * )& info .fdCreator , 4 );
228
+ res = Py_BuildValue ("OO" , type , creator );
229
+ DECREF (type );
230
+ DECREF (creator );
231
+ return res ;
232
+ }
233
+
234
+ static PyObject *
235
+ MacOS_SetFileType (PyObject * self , PyObject * args )
236
+ {
237
+ Str255 name ;
238
+ ResType type , creator ;
239
+ FInfo info ;
240
+ OSErr err ;
241
+
242
+ if (!PyArg_ParseTuple (args , "O&O&O&" ,
243
+ GetStr255 , & name , GetOSType , & type , GetOSType , & creator ))
244
+ return NULL ;
245
+ if ((err = GetFInfo (name , 0 , & info )) != noErr ) {
246
+ errno = err ;
247
+ PyErr_SetFromErrno (MacOS_Error );
248
+ return NULL ;
249
+ }
250
+ info .fdType = type ;
251
+ info .fdCreator = creator ;
252
+ if ((err = SetFInfo (name , 0 , & info )) != noErr ) {
253
+ errno = err ;
254
+ err_errno (MacOS_Error );
255
+ return NULL ;
256
+ }
257
+ Py_INCREF (Py_None );
258
+ return Py_None ;
259
+ }
260
+
208
261
/*----------------------------------------------------------------------*/
209
262
/* SoundChannel objects */
210
263
@@ -215,23 +268,13 @@ GetSndCommand(PyObject *v, SndCommand *pc)
215
268
int len ;
216
269
pc -> param1 = 0 ;
217
270
pc -> param2 = 0 ;
218
- if (PyArg_Parse (v , "h" , & pc -> cmd ))
219
- return 1 ;
220
- PyErr_Clear ();
221
- if (PyArg_Parse (v , "(h)" , & pc -> cmd ))
222
- return 1 ;
223
- PyErr_Clear ();
224
- if (PyArg_Parse (v , "(hh)" , & pc -> cmd , & pc -> param1 ))
225
- return 1 ;
226
- PyErr_Clear ();
227
- if (PyArg_Parse (v , "(hhl)" ,
228
- & pc -> cmd , & pc -> param1 , & pc -> param2 ))
229
- return 1 ;
230
- PyErr_Clear ();
231
- if (PyArg_Parse (v , "(hhs#);SndCommand arg must be 1-3 ints or 2 ints + string" ,
232
- & pc -> cmd , & pc -> param1 , & pc -> param2 , & len ))
233
- return 1 ;
234
- return 0 ;
271
+ if (PyTuple_Check (v )) {
272
+ if (PyArg_ParseTuple (v , "h|hl" , & pc -> cmd , & pc -> param1 , & pc -> param2 ))
273
+ return 1 ;
274
+ PyErr_Clear ();
275
+ return PyArg_ParseTuple (v , "hhs#" , & pc -> cmd , & pc -> param1 , & pc -> param2 , & len );
276
+ }
277
+ return PyArg_Parse (v , "h" , & pc -> cmd );
235
278
}
236
279
237
280
typedef struct {
@@ -277,7 +320,7 @@ SndCh_DisposeChannel(SndChObject *s, PyObject *args)
277
320
{
278
321
int quitNow = 1 ;
279
322
if (PyTuple_Size (args ) > 0 ) {
280
- if (!PyArg_Parse (args , "(i) " , & quitNow ))
323
+ if (!PyArg_ParseTuple (args , "i " , & quitNow ))
281
324
return NULL ;
282
325
}
283
326
SndCh_Cleanup (s , quitNow );
@@ -300,11 +343,8 @@ SndCh_SndPlay(SndChObject *s, PyObject *args)
300
343
{
301
344
RsrcObject * r ;
302
345
int async = 0 ;
303
- if (!PyArg_Parse (args , "(O!)" , RsrcType , & r )) {
304
- PyErr_Clear ();
305
- if (!PyArg_Parse (args , "(O&i)" , RsrcType , & r , & async ))
306
- return NULL ;
307
- }
346
+ if (!PyArg_ParseTuple (args , "O!|i" , RsrcType , & r , & async ))
347
+ return NULL ;
308
348
if (!SndCh_OK (s ))
309
349
return NULL ;
310
350
SndPlay (s -> chan , r -> h , async );
@@ -318,11 +358,8 @@ SndCh_SndDoCommand(SndChObject *s, PyObject *args)
318
358
SndCommand c ;
319
359
int noWait = 0 ;
320
360
OSErr err ;
321
- if (!PyArg_Parse (args , "(O&)" , GetSndCommand , & c )) {
322
- PyErr_Clear ();
323
- if (!PyArg_Parse (args , "(O&i)" , GetSndCommand , & c , & noWait ))
324
- return NULL ;
325
- }
361
+ if (!PyArg_ParseTuple (args , "O&|i" , GetSndCommand , & c , & noWait ))
362
+ return NULL ;
326
363
if (!SndCh_OK (s ))
327
364
return NULL ;
328
365
err = SndDoCommand (s -> chan , & c , noWait );
@@ -334,7 +371,7 @@ SndCh_SndDoImmediate(SndChObject *s, PyObject *args)
334
371
{
335
372
SndCommand c ;
336
373
OSErr err ;
337
- if (!PyArg_Parse (args , "(O&) " , GetSndCommand , & c ))
374
+ if (!PyArg_ParseTuple (args , "O& " , GetSndCommand , & c ))
338
375
return 0 ;
339
376
if (!SndCh_OK (s ))
340
377
return NULL ;
@@ -432,14 +469,8 @@ MacOS_SndNewChannel(PyObject *self, PyObject *args)
432
469
SndCallBackUPP userroutine = 0 ;
433
470
OSErr err ;
434
471
PyObject * res ;
435
- if (!PyArg_Parse (args , "(h)" , & synth )) {
436
- PyErr_Clear ();
437
- if (!PyArg_Parse (args , "(hl)" , & synth , & init )) {
438
- PyErr_Clear ();
439
- if (!PyArg_Parse (args , "(hlO)" , & synth , & init , & callback ))
440
- return NULL ;
441
- }
442
- }
472
+ if (!PyArg_ParseTuple (args , "h|lO" , & synth , & init , & callback ))
473
+ return NULL ;
443
474
if (callback != NULL ) {
444
475
p = NEW (cbinfo , 1 );
445
476
if (p == NULL )
@@ -472,7 +503,7 @@ MacOS_SndPlay(PyObject *self, PyObject *args)
472
503
{
473
504
RsrcObject * r ;
474
505
OSErr err ;
475
- if (!PyArg_Parse (args , "(O!) " , & RsrcType , & r ))
506
+ if (!PyArg_ParseTuple (args , "O! " , & RsrcType , & r ))
476
507
return NULL ;
477
508
err = SndPlay ((SndChannelPtr )NULL , r -> h , 0 );
478
509
return PyErr_Mac (MacOS_Error , (int )err );
@@ -484,7 +515,7 @@ MacOS_SndControl(PyObject *self, PyObject *args)
484
515
int id ;
485
516
SndCommand c ;
486
517
OSErr err ;
487
- if (!PyArg_Parse (args , "( iO&) " , & id , GetSndCommand , & c ))
518
+ if (!PyArg_ParseTuple (args , "iO&" , & id , GetSndCommand , & c ))
488
519
return NULL ;
489
520
err = SndControl (id , & c );
490
521
if (err )
@@ -495,6 +526,8 @@ MacOS_SndControl(PyObject *self, PyObject *args)
495
526
static PyMethodDef MacOS_Methods [] = {
496
527
{"GetResource" , MacOS_GetResource , 1 },
497
528
{"GetNamedResource" , MacOS_GetNamedResource , 1 },
529
+ {"GetFileType" , MacOS_GetFileType , 1 },
530
+ {"SetFileType" , MacOS_SetFileType , 1 },
498
531
{"SndNewChannel" , MacOS_SndNewChannel , 1 },
499
532
{"SndPlay" , MacOS_SndPlay , 1 },
500
533
{"SndControl" , MacOS_SndControl , 1 },
0 commit comments