Changeset 391 for python/trunk/Mac/Modules/launch
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Mac/Modules/launch/_Launchmodule.c
r2 r391 10 10 /* Macro to test whether a weak-loaded CFM function exists */ 11 11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ 12 13 14 12 PyErr_SetString(PyExc_NotImplementedError, \ 13 "Not available in this shared library/OS version"); \ 14 return NULL; \ 15 15 }} while(0) 16 16 … … 28 28 OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec) 29 29 { 30 31 32 33 34 30 if (v == Py_None) { 31 *spec = NULL; 32 return 1; 33 } 34 return CFStringRefObj_Convert(v, spec); 35 35 } 36 36 … … 38 38 OptCFStringRefObj_New(CFStringRef it) 39 39 { 40 41 42 43 44 40 if (it == NULL) { 41 Py_INCREF(Py_None); 42 return Py_None; 43 } 44 return CFStringRefObj_New(it); 45 45 } 46 46 … … 52 52 { 53 53 #ifndef __LP64__ 54 55 56 57 58 59 60 54 return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}", 55 "flags", it->flags, 56 "filetype", PyMac_BuildOSType, it->filetype, 57 "creator", PyMac_BuildOSType, it->creator, 58 "extension", OptCFStringRefObj_New, it->extension, 59 "iconFileName", OptCFStringRefObj_New, it->iconFileName, 60 "kindID", it->kindID); 61 61 #else 62 63 64 65 66 62 return Py_BuildValue("{s:is:O&s:O&s:O&}", 63 "flags", it->flags, 64 "filetype", PyMac_BuildOSType, it->filetype, 65 "creator", PyMac_BuildOSType, it->creator, 66 "extension", OptCFStringRefObj_New, it->extension); 67 67 #endif 68 68 } … … 72 72 static PyObject *Launch_LSCopyItemInfoForRef(PyObject *_self, PyObject *_args) 73 73 { 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 74 PyObject *_res = NULL; 75 OSStatus _err; 76 FSRef inItemRef; 77 LSRequestedInfo inWhichInfo; 78 LSItemInfoRecord outItemInfo; 79 if (!PyArg_ParseTuple(_args, "O&l", 80 PyMac_GetFSRef, &inItemRef, 81 &inWhichInfo)) 82 return NULL; 83 _err = LSCopyItemInfoForRef(&inItemRef, 84 inWhichInfo, 85 &outItemInfo); 86 if (_err != noErr) return PyMac_Error(_err); 87 _res = Py_BuildValue("O&", 88 LSItemInfoRecord_New, &outItemInfo); 89 return _res; 90 90 } 91 91 92 92 static PyObject *Launch_LSCopyItemInfoForURL(PyObject *_self, PyObject *_args) 93 93 { 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 94 PyObject *_res = NULL; 95 OSStatus _err; 96 CFURLRef inURL; 97 LSRequestedInfo inWhichInfo; 98 LSItemInfoRecord outItemInfo; 99 if (!PyArg_ParseTuple(_args, "O&l", 100 CFURLRefObj_Convert, &inURL, 101 &inWhichInfo)) 102 return NULL; 103 _err = LSCopyItemInfoForURL(inURL, 104 inWhichInfo, 105 &outItemInfo); 106 if (_err != noErr) return PyMac_Error(_err); 107 _res = Py_BuildValue("O&", 108 LSItemInfoRecord_New, &outItemInfo); 109 return _res; 110 110 } 111 111 112 112 static PyObject *Launch_LSGetExtensionInfo(PyObject *_self, PyObject *_args) 113 113 { 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 114 PyObject *_res = NULL; 115 OSStatus _err; 116 UniChar *inNameLen__in__; 117 UniCharCount inNameLen__len__; 118 int inNameLen__in_len__; 119 UniCharCount outExtStartIndex; 120 if (!PyArg_ParseTuple(_args, "u#", 121 &inNameLen__in__, &inNameLen__in_len__)) 122 return NULL; 123 inNameLen__len__ = inNameLen__in_len__; 124 _err = LSGetExtensionInfo(inNameLen__len__, inNameLen__in__, 125 &outExtStartIndex); 126 if (_err != noErr) return PyMac_Error(_err); 127 _res = Py_BuildValue("l", 128 outExtStartIndex); 129 return _res; 130 130 } 131 131 132 132 static PyObject *Launch_LSCopyDisplayNameForRef(PyObject *_self, PyObject *_args) 133 133 { 134 135 136 137 138 139 140 141 142 143 144 145 146 134 PyObject *_res = NULL; 135 OSStatus _err; 136 FSRef inRef; 137 CFStringRef outDisplayName; 138 if (!PyArg_ParseTuple(_args, "O&", 139 PyMac_GetFSRef, &inRef)) 140 return NULL; 141 _err = LSCopyDisplayNameForRef(&inRef, 142 &outDisplayName); 143 if (_err != noErr) return PyMac_Error(_err); 144 _res = Py_BuildValue("O&", 145 CFStringRefObj_New, outDisplayName); 146 return _res; 147 147 } 148 148 149 149 static PyObject *Launch_LSCopyDisplayNameForURL(PyObject *_self, PyObject *_args) 150 150 { 151 152 153 154 155 156 157 158 159 160 161 162 163 151 PyObject *_res = NULL; 152 OSStatus _err; 153 CFURLRef inURL; 154 CFStringRef outDisplayName; 155 if (!PyArg_ParseTuple(_args, "O&", 156 CFURLRefObj_Convert, &inURL)) 157 return NULL; 158 _err = LSCopyDisplayNameForURL(inURL, 159 &outDisplayName); 160 if (_err != noErr) return PyMac_Error(_err); 161 _res = Py_BuildValue("O&", 162 CFStringRefObj_New, outDisplayName); 163 return _res; 164 164 } 165 165 166 166 static PyObject *Launch_LSSetExtensionHiddenForRef(PyObject *_self, PyObject *_args) 167 167 { 168 169 170 171 172 173 174 175 176 177 178 179 180 181 168 PyObject *_res = NULL; 169 OSStatus _err; 170 FSRef inRef; 171 Boolean inHide; 172 if (!PyArg_ParseTuple(_args, "O&b", 173 PyMac_GetFSRef, &inRef, 174 &inHide)) 175 return NULL; 176 _err = LSSetExtensionHiddenForRef(&inRef, 177 inHide); 178 if (_err != noErr) return PyMac_Error(_err); 179 Py_INCREF(Py_None); 180 _res = Py_None; 181 return _res; 182 182 } 183 183 184 184 static PyObject *Launch_LSSetExtensionHiddenForURL(PyObject *_self, PyObject *_args) 185 185 { 186 187 188 189 190 191 192 193 194 195 196 197 198 199 186 PyObject *_res = NULL; 187 OSStatus _err; 188 CFURLRef inURL; 189 Boolean inHide; 190 if (!PyArg_ParseTuple(_args, "O&b", 191 CFURLRefObj_Convert, &inURL, 192 &inHide)) 193 return NULL; 194 _err = LSSetExtensionHiddenForURL(inURL, 195 inHide); 196 if (_err != noErr) return PyMac_Error(_err); 197 Py_INCREF(Py_None); 198 _res = Py_None; 199 return _res; 200 200 } 201 201 202 202 static PyObject *Launch_LSCopyKindStringForRef(PyObject *_self, PyObject *_args) 203 203 { 204 205 206 207 208 209 210 211 212 213 214 215 216 204 PyObject *_res = NULL; 205 OSStatus _err; 206 FSRef inFSRef; 207 CFStringRef outKindString; 208 if (!PyArg_ParseTuple(_args, "O&", 209 PyMac_GetFSRef, &inFSRef)) 210 return NULL; 211 _err = LSCopyKindStringForRef(&inFSRef, 212 &outKindString); 213 if (_err != noErr) return PyMac_Error(_err); 214 _res = Py_BuildValue("O&", 215 CFStringRefObj_New, outKindString); 216 return _res; 217 217 } 218 218 219 219 static PyObject *Launch_LSCopyKindStringForURL(PyObject *_self, PyObject *_args) 220 220 { 221 222 223 224 225 226 227 228 229 230 231 232 233 221 PyObject *_res = NULL; 222 OSStatus _err; 223 CFURLRef inURL; 224 CFStringRef outKindString; 225 if (!PyArg_ParseTuple(_args, "O&", 226 CFURLRefObj_Convert, &inURL)) 227 return NULL; 228 _err = LSCopyKindStringForURL(inURL, 229 &outKindString); 230 if (_err != noErr) return PyMac_Error(_err); 231 _res = Py_BuildValue("O&", 232 CFStringRefObj_New, outKindString); 233 return _res; 234 234 } 235 235 236 236 static PyObject *Launch_LSGetApplicationForItem(PyObject *_self, PyObject *_args) 237 237 { 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 238 PyObject *_res = NULL; 239 OSStatus _err; 240 FSRef inItemRef; 241 LSRolesMask inRoleMask; 242 FSRef outAppRef; 243 CFURLRef outAppURL; 244 if (!PyArg_ParseTuple(_args, "O&l", 245 PyMac_GetFSRef, &inItemRef, 246 &inRoleMask)) 247 return NULL; 248 _err = LSGetApplicationForItem(&inItemRef, 249 inRoleMask, 250 &outAppRef, 251 &outAppURL); 252 if (_err != noErr) return PyMac_Error(_err); 253 _res = Py_BuildValue("O&O&", 254 PyMac_BuildFSRef, &outAppRef, 255 CFURLRefObj_New, outAppURL); 256 return _res; 257 257 } 258 258 259 259 static PyObject *Launch_LSGetApplicationForInfo(PyObject *_self, PyObject *_args) 260 260 { 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 261 PyObject *_res = NULL; 262 OSStatus _err; 263 OSType inType; 264 OSType inCreator; 265 CFStringRef inExtension; 266 LSRolesMask inRoleMask; 267 FSRef outAppRef; 268 CFURLRef outAppURL; 269 if (!PyArg_ParseTuple(_args, "O&O&O&l", 270 PyMac_GetOSType, &inType, 271 PyMac_GetOSType, &inCreator, 272 OptCFStringRefObj_Convert, &inExtension, 273 &inRoleMask)) 274 return NULL; 275 _err = LSGetApplicationForInfo(inType, 276 inCreator, 277 inExtension, 278 inRoleMask, 279 &outAppRef, 280 &outAppURL); 281 if (_err != noErr) return PyMac_Error(_err); 282 _res = Py_BuildValue("O&O&", 283 PyMac_BuildFSRef, &outAppRef, 284 CFURLRefObj_New, outAppURL); 285 return _res; 286 286 } 287 287 288 288 static PyObject *Launch_LSGetApplicationForURL(PyObject *_self, PyObject *_args) 289 289 { 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 290 PyObject *_res = NULL; 291 OSStatus _err; 292 CFURLRef inURL; 293 LSRolesMask inRoleMask; 294 FSRef outAppRef; 295 CFURLRef outAppURL; 296 if (!PyArg_ParseTuple(_args, "O&l", 297 CFURLRefObj_Convert, &inURL, 298 &inRoleMask)) 299 return NULL; 300 _err = LSGetApplicationForURL(inURL, 301 inRoleMask, 302 &outAppRef, 303 &outAppURL); 304 if (_err != noErr) return PyMac_Error(_err); 305 _res = Py_BuildValue("O&O&", 306 PyMac_BuildFSRef, &outAppRef, 307 CFURLRefObj_New, outAppURL); 308 return _res; 309 309 } 310 310 311 311 static PyObject *Launch_LSFindApplicationForInfo(PyObject *_self, PyObject *_args) 312 312 { 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 313 PyObject *_res = NULL; 314 OSStatus _err; 315 OSType inCreator; 316 CFStringRef inBundleID; 317 CFStringRef inName; 318 FSRef outAppRef; 319 CFURLRef outAppURL; 320 if (!PyArg_ParseTuple(_args, "O&O&O&", 321 PyMac_GetOSType, &inCreator, 322 OptCFStringRefObj_Convert, &inBundleID, 323 OptCFStringRefObj_Convert, &inName)) 324 return NULL; 325 _err = LSFindApplicationForInfo(inCreator, 326 inBundleID, 327 inName, 328 &outAppRef, 329 &outAppURL); 330 if (_err != noErr) return PyMac_Error(_err); 331 _res = Py_BuildValue("O&O&", 332 PyMac_BuildFSRef, &outAppRef, 333 CFURLRefObj_New, outAppURL); 334 return _res; 335 335 } 336 336 337 337 static PyObject *Launch_LSCanRefAcceptItem(PyObject *_self, PyObject *_args) 338 338 { 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 339 PyObject *_res = NULL; 340 OSStatus _err; 341 FSRef inItemFSRef; 342 FSRef inTargetRef; 343 LSRolesMask inRoleMask; 344 LSAcceptanceFlags inFlags; 345 Boolean outAcceptsItem; 346 if (!PyArg_ParseTuple(_args, "O&O&ll", 347 PyMac_GetFSRef, &inItemFSRef, 348 PyMac_GetFSRef, &inTargetRef, 349 &inRoleMask, 350 &inFlags)) 351 return NULL; 352 _err = LSCanRefAcceptItem(&inItemFSRef, 353 &inTargetRef, 354 inRoleMask, 355 inFlags, 356 &outAcceptsItem); 357 if (_err != noErr) return PyMac_Error(_err); 358 _res = Py_BuildValue("b", 359 outAcceptsItem); 360 return _res; 361 361 } 362 362 363 363 static PyObject *Launch_LSCanURLAcceptURL(PyObject *_self, PyObject *_args) 364 364 { 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 365 PyObject *_res = NULL; 366 OSStatus _err; 367 CFURLRef inItemURL; 368 CFURLRef inTargetURL; 369 LSRolesMask inRoleMask; 370 LSAcceptanceFlags inFlags; 371 Boolean outAcceptsItem; 372 if (!PyArg_ParseTuple(_args, "O&O&ll", 373 CFURLRefObj_Convert, &inItemURL, 374 CFURLRefObj_Convert, &inTargetURL, 375 &inRoleMask, 376 &inFlags)) 377 return NULL; 378 _err = LSCanURLAcceptURL(inItemURL, 379 inTargetURL, 380 inRoleMask, 381 inFlags, 382 &outAcceptsItem); 383 if (_err != noErr) return PyMac_Error(_err); 384 _res = Py_BuildValue("b", 385 outAcceptsItem); 386 return _res; 387 387 } 388 388 389 389 static PyObject *Launch_LSOpenFSRef(PyObject *_self, PyObject *_args) 390 390 { 391 392 393 394 395 396 397 398 399 400 401 402 403 391 PyObject *_res = NULL; 392 OSStatus _err; 393 FSRef inRef; 394 FSRef outLaunchedRef; 395 if (!PyArg_ParseTuple(_args, "O&", 396 PyMac_GetFSRef, &inRef)) 397 return NULL; 398 _err = LSOpenFSRef(&inRef, 399 &outLaunchedRef); 400 if (_err != noErr) return PyMac_Error(_err); 401 _res = Py_BuildValue("O&", 402 PyMac_BuildFSRef, &outLaunchedRef); 403 return _res; 404 404 } 405 405 406 406 static PyObject *Launch_LSOpenCFURLRef(PyObject *_self, PyObject *_args) 407 407 { 408 409 410 411 412 413 414 415 416 417 418 419 420 408 PyObject *_res = NULL; 409 OSStatus _err; 410 CFURLRef inURL; 411 CFURLRef outLaunchedURL; 412 if (!PyArg_ParseTuple(_args, "O&", 413 CFURLRefObj_Convert, &inURL)) 414 return NULL; 415 _err = LSOpenCFURLRef(inURL, 416 &outLaunchedURL); 417 if (_err != noErr) return PyMac_Error(_err); 418 _res = Py_BuildValue("O&", 419 CFURLRefObj_New, outLaunchedURL); 420 return _res; 421 421 } 422 422 423 423 static PyMethodDef Launch_methods[] = { 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 424 {"LSCopyItemInfoForRef", (PyCFunction)Launch_LSCopyItemInfoForRef, 1, 425 PyDoc_STR("(FSRef inItemRef, LSRequestedInfo inWhichInfo) -> (LSItemInfoRecord outItemInfo)")}, 426 {"LSCopyItemInfoForURL", (PyCFunction)Launch_LSCopyItemInfoForURL, 1, 427 PyDoc_STR("(CFURLRef inURL, LSRequestedInfo inWhichInfo) -> (LSItemInfoRecord outItemInfo)")}, 428 {"LSGetExtensionInfo", (PyCFunction)Launch_LSGetExtensionInfo, 1, 429 PyDoc_STR("(Buffer inNameLen) -> (UniCharCount outExtStartIndex)")}, 430 {"LSCopyDisplayNameForRef", (PyCFunction)Launch_LSCopyDisplayNameForRef, 1, 431 PyDoc_STR("(FSRef inRef) -> (CFStringRef outDisplayName)")}, 432 {"LSCopyDisplayNameForURL", (PyCFunction)Launch_LSCopyDisplayNameForURL, 1, 433 PyDoc_STR("(CFURLRef inURL) -> (CFStringRef outDisplayName)")}, 434 {"LSSetExtensionHiddenForRef", (PyCFunction)Launch_LSSetExtensionHiddenForRef, 1, 435 PyDoc_STR("(FSRef inRef, Boolean inHide) -> None")}, 436 {"LSSetExtensionHiddenForURL", (PyCFunction)Launch_LSSetExtensionHiddenForURL, 1, 437 PyDoc_STR("(CFURLRef inURL, Boolean inHide) -> None")}, 438 {"LSCopyKindStringForRef", (PyCFunction)Launch_LSCopyKindStringForRef, 1, 439 PyDoc_STR("(FSRef inFSRef) -> (CFStringRef outKindString)")}, 440 {"LSCopyKindStringForURL", (PyCFunction)Launch_LSCopyKindStringForURL, 1, 441 PyDoc_STR("(CFURLRef inURL) -> (CFStringRef outKindString)")}, 442 {"LSGetApplicationForItem", (PyCFunction)Launch_LSGetApplicationForItem, 1, 443 PyDoc_STR("(FSRef inItemRef, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")}, 444 {"LSGetApplicationForInfo", (PyCFunction)Launch_LSGetApplicationForInfo, 1, 445 PyDoc_STR("(OSType inType, OSType inCreator, CFStringRef inExtension, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")}, 446 {"LSGetApplicationForURL", (PyCFunction)Launch_LSGetApplicationForURL, 1, 447 PyDoc_STR("(CFURLRef inURL, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")}, 448 {"LSFindApplicationForInfo", (PyCFunction)Launch_LSFindApplicationForInfo, 1, 449 PyDoc_STR("(OSType inCreator, CFStringRef inBundleID, CFStringRef inName) -> (FSRef outAppRef, CFURLRef outAppURL)")}, 450 {"LSCanRefAcceptItem", (PyCFunction)Launch_LSCanRefAcceptItem, 1, 451 PyDoc_STR("(FSRef inItemFSRef, FSRef inTargetRef, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags) -> (Boolean outAcceptsItem)")}, 452 {"LSCanURLAcceptURL", (PyCFunction)Launch_LSCanURLAcceptURL, 1, 453 PyDoc_STR("(CFURLRef inItemURL, CFURLRef inTargetURL, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags) -> (Boolean outAcceptsItem)")}, 454 {"LSOpenFSRef", (PyCFunction)Launch_LSOpenFSRef, 1, 455 PyDoc_STR("(FSRef inRef) -> (FSRef outLaunchedRef)")}, 456 {"LSOpenCFURLRef", (PyCFunction)Launch_LSOpenCFURLRef, 1, 457 PyDoc_STR("(CFURLRef inURL) -> (CFURLRef outLaunchedURL)")}, 458 {NULL, NULL, 0} 459 459 }; 460 460 … … 464 464 void init_Launch(void) 465 465 { 466 467 468 469 470 471 472 473 474 475 476 477 466 PyObject *m; 467 PyObject *d; 468 469 470 471 472 m = Py_InitModule("_Launch", Launch_methods); 473 d = PyModule_GetDict(m); 474 Launch_Error = PyMac_GetOSErrException(); 475 if (Launch_Error == NULL || 476 PyDict_SetItemString(d, "Error", Launch_Error) != 0) 477 return; 478 478 } 479 479
Note:
See TracChangeset
for help on using the changeset viewer.