Changeset 391 for python/trunk/Mac/Modules/icgluemodule.c
- 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/icgluemodule.c
r2 r391 44 44 45 45 typedef struct { 46 47 46 PyObject_HEAD 47 ICInstance inst; 48 48 } iciobject; 49 49 … … 55 55 56 56 57 static char ici_ICGetSeed__doc__[] = 57 static char ici_ICGetSeed__doc__[] = 58 58 "()->int; Returns int that changes when configuration does" 59 59 ; … … 62 62 ici_ICGetSeed(iciobject *self, PyObject *args) 63 63 { 64 65 66 67 68 69 70 71 72 } 73 74 75 static char ici_ICBegin__doc__[] = 64 OSStatus err; 65 long seed; 66 67 if (!PyArg_ParseTuple(args, "")) 68 return NULL; 69 if ((err=ICGetSeed(self->inst, &seed)) != 0 ) 70 return PyMac_Error(err); 71 return Py_BuildValue("i", (int)seed); 72 } 73 74 75 static char ici_ICBegin__doc__[] = 76 76 "(perm)->None; Lock config file for read/write" 77 77 ; … … 80 80 ici_ICBegin(iciobject *self, PyObject *args) 81 81 { 82 83 84 85 86 87 88 89 90 91 } 92 93 94 static char ici_ICFindPrefHandle__doc__[] = 82 OSStatus err; 83 int perm; 84 85 if (!PyArg_ParseTuple(args, "i", &perm)) 86 return NULL; 87 if ((err=ICBegin(self->inst, (ICPerm)perm)) != 0 ) 88 return PyMac_Error(err); 89 Py_INCREF(Py_None); 90 return Py_None; 91 } 92 93 94 static char ici_ICFindPrefHandle__doc__[] = 95 95 "(key, handle)->attrs; Lookup key, store result in handle, return attributes" 96 96 ; … … 99 99 ici_ICFindPrefHandle(iciobject *self, PyObject *args) 100 100 { 101 102 103 104 105 106 107 108 109 110 111 } 112 113 114 static char ici_ICSetPref__doc__[] = 101 OSStatus err; 102 Str255 key; 103 ICAttr attr; 104 Handle h; 105 106 if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetStr255, &key, ResObj_Convert, &h)) 107 return NULL; 108 if ((err=ICFindPrefHandle(self->inst, key, &attr, h)) != 0 ) 109 return PyMac_Error(err); 110 return Py_BuildValue("i", (int)attr); 111 } 112 113 114 static char ici_ICSetPref__doc__[] = 115 115 "(key, attr, data)->None; Set preference key to data with attributes" 116 116 ; … … 119 119 ici_ICSetPref(iciobject *self, PyObject *args) 120 120 { 121 122 123 124 125 126 127 if (!PyArg_ParseTuple(args, "O&is#", PyMac_GetStr255, &key, &attr, 128 129 130 if ((err=ICSetPref(self->inst, key, (ICAttr)attr, (Ptr)data, 131 132 133 134 135 } 136 137 138 static char ici_ICCountPref__doc__[] = 121 OSStatus err; 122 Str255 key; 123 int attr; 124 char *data; 125 int datalen; 126 127 if (!PyArg_ParseTuple(args, "O&is#", PyMac_GetStr255, &key, &attr, 128 &data, &datalen)) 129 return NULL; 130 if ((err=ICSetPref(self->inst, key, (ICAttr)attr, (Ptr)data, 131 (long)datalen)) != 0) 132 return PyMac_Error(err); 133 Py_INCREF(Py_None); 134 return Py_None; 135 } 136 137 138 static char ici_ICCountPref__doc__[] = 139 139 "()->int; Return number of preferences" 140 140 ; … … 143 143 ici_ICCountPref(iciobject *self, PyObject *args) 144 144 { 145 146 147 148 149 150 151 152 153 } 154 155 156 static char ici_ICGetIndPref__doc__[] = 145 OSStatus err; 146 long count; 147 148 if (!PyArg_ParseTuple(args, "")) 149 return NULL; 150 if ((err=ICCountPref(self->inst, &count)) != 0 ) 151 return PyMac_Error(err); 152 return Py_BuildValue("i", (int)count); 153 } 154 155 156 static char ici_ICGetIndPref__doc__[] = 157 157 "(num)->key; Return key of preference with given index" 158 158 ; … … 161 161 ici_ICGetIndPref(iciobject *self, PyObject *args) 162 162 { 163 164 165 166 167 168 169 170 171 172 } 173 174 175 static char ici_ICDeletePref__doc__[] = 163 OSStatus err; 164 long num; 165 Str255 key; 166 167 if (!PyArg_ParseTuple(args, "l", &num)) 168 return NULL; 169 if ((err=ICGetIndPref(self->inst, num, key)) != 0 ) 170 return PyMac_Error(err); 171 return Py_BuildValue("O&", PyMac_BuildStr255, key); 172 } 173 174 175 static char ici_ICDeletePref__doc__[] = 176 176 "(key)->None; Delete preference" 177 177 ; … … 180 180 ici_ICDeletePref(iciobject *self, PyObject *args) 181 181 { 182 183 184 185 186 187 188 189 190 191 } 192 193 194 static char ici_ICEnd__doc__[] = 182 OSStatus err; 183 Str255 key; 184 185 if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) 186 return NULL; 187 if ((err=ICDeletePref(self->inst, key)) != 0 ) 188 return PyMac_Error(err); 189 Py_INCREF(Py_None); 190 return Py_None; 191 } 192 193 194 static char ici_ICEnd__doc__[] = 195 195 "()->None; Unlock file after ICBegin call" 196 196 ; … … 199 199 ici_ICEnd(iciobject *self, PyObject *args) 200 200 { 201 202 203 204 205 206 207 208 209 } 210 211 212 static char ici_ICEditPreferences__doc__[] = 201 OSStatus err; 202 203 if (!PyArg_ParseTuple(args, "")) 204 return NULL; 205 if ((err=ICEnd(self->inst)) != 0 ) 206 return PyMac_Error(err); 207 Py_INCREF(Py_None); 208 return Py_None; 209 } 210 211 212 static char ici_ICEditPreferences__doc__[] = 213 213 "(key)->None; Ask user to edit preferences, staring with key" 214 214 ; … … 217 217 ici_ICEditPreferences(iciobject *self, PyObject *args) 218 218 { 219 220 221 222 223 224 225 226 227 228 } 229 230 231 static char ici_ICParseURL__doc__[] = 219 OSStatus err; 220 Str255 key; 221 222 if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) 223 return NULL; 224 if ((err=ICEditPreferences(self->inst, key)) != 0 ) 225 return PyMac_Error(err); 226 Py_INCREF(Py_None); 227 return Py_None; 228 } 229 230 231 static char ici_ICParseURL__doc__[] = 232 232 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle" 233 233 ; … … 236 236 ici_ICParseURL(iciobject *self, PyObject *args) 237 237 { 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 } 253 254 255 static char ici_ICLaunchURL__doc__[] = 238 OSStatus err; 239 Str255 hint; 240 char *data; 241 int datalen; 242 long selStart, selEnd; 243 Handle h; 244 245 if (!PyArg_ParseTuple(args, "O&s#llO&", PyMac_GetStr255, hint, &data, &datalen, 246 &selStart, &selEnd, ResObj_Convert, &h)) 247 return NULL; 248 if ((err=ICParseURL(self->inst, hint, (Ptr)data, (long)datalen, 249 &selStart, &selEnd, h)) != 0 ) 250 return PyMac_Error(err); 251 return Py_BuildValue("ii", (int)selStart, (int)selEnd); 252 } 253 254 255 static char ici_ICLaunchURL__doc__[] = 256 256 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app" 257 257 ; … … 260 260 ici_ICLaunchURL(iciobject *self, PyObject *args) 261 261 { 262 263 264 265 266 267 268 269 270 271 272 273 274 275 } 276 277 278 static char ici_ICMapFilename__doc__[] = 262 OSStatus err; 263 Str255 hint; 264 char *data; 265 int datalen; 266 long selStart, selEnd; 267 268 if (!PyArg_ParseTuple(args, "O&s#ll", PyMac_GetStr255, hint, &data, &datalen, 269 &selStart, &selEnd)) 270 return NULL; 271 if ((err=ICLaunchURL(self->inst, hint, (Ptr)data, (long)datalen, 272 &selStart, &selEnd)) != 0 ) 273 return PyMac_Error(err); 274 return Py_BuildValue("ii", (int)selStart, (int)selEnd); 275 } 276 277 278 static char ici_ICMapFilename__doc__[] = 279 279 "(filename)->mapinfo; Get filemap info for given filename" 280 280 ; … … 283 283 ici_ICMapFilename(iciobject *self, PyObject *args) 284 284 { 285 286 287 288 289 290 291 292 293 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, 294 295 PyMac_BuildOSType, entry.fileCreator, 296 PyMac_BuildOSType, entry.postCreator, 297 298 299 300 301 302 303 } 304 305 306 static char ici_ICMapTypeCreator__doc__[] = 285 OSStatus err; 286 Str255 filename; 287 ICMapEntry entry; 288 289 if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, filename)) 290 return NULL; 291 if ((err=ICMapFilename(self->inst, filename, &entry)) != 0 ) 292 return PyMac_Error(err); 293 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, 294 PyMac_BuildOSType, entry.fileType, 295 PyMac_BuildOSType, entry.fileCreator, 296 PyMac_BuildOSType, entry.postCreator, 297 entry.flags, 298 PyMac_BuildStr255, entry.extension, 299 PyMac_BuildStr255, entry.creatorAppName, 300 PyMac_BuildStr255, entry.postAppName, 301 PyMac_BuildStr255, entry.MIMEType, 302 PyMac_BuildStr255, entry.entryName); 303 } 304 305 306 static char ici_ICMapTypeCreator__doc__[] = 307 307 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename" 308 308 ; … … 311 311 ici_ICMapTypeCreator(iciobject *self, PyObject *args) 312 312 { 313 314 315 316 317 318 319 320 321 322 323 324 325 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, 326 327 PyMac_BuildOSType, entry.fileCreator, 328 PyMac_BuildOSType, entry.postCreator, 329 330 331 332 333 334 313 OSStatus err; 314 OSType type, creator; 315 Str255 filename; 316 ICMapEntry entry; 317 318 if (!PyArg_ParseTuple(args, "O&O&O&", 319 PyMac_GetOSType, &type, 320 PyMac_GetOSType, &creator, 321 PyMac_GetStr255, filename)) 322 return NULL; 323 if ((err=ICMapTypeCreator(self->inst, type, creator, filename, &entry)) != 0 ) 324 return PyMac_Error(err); 325 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, 326 PyMac_BuildOSType, entry.fileType, 327 PyMac_BuildOSType, entry.fileCreator, 328 PyMac_BuildOSType, entry.postCreator, 329 entry.flags, 330 PyMac_BuildStr255, entry.extension, 331 PyMac_BuildStr255, entry.creatorAppName, 332 PyMac_BuildStr255, entry.postAppName, 333 PyMac_BuildStr255, entry.MIMEType, 334 PyMac_BuildStr255, entry.entryName); 335 335 } 336 336 337 337 338 338 static struct PyMethodDef ici_methods[] = { 339 {"ICGetSeed", (PyCFunction)ici_ICGetSeed, METH_VARARGS,ici_ICGetSeed__doc__},340 {"ICBegin", (PyCFunction)ici_ICBegin, METH_VARARGS,ici_ICBegin__doc__},341 {"ICFindPrefHandle", (PyCFunction)ici_ICFindPrefHandle, METH_VARARGS,ici_ICFindPrefHandle__doc__},342 {"ICSetPref", (PyCFunction)ici_ICSetPref, METH_VARARGS,ici_ICSetPref__doc__},343 {"ICCountPref", (PyCFunction)ici_ICCountPref, METH_VARARGS,ici_ICCountPref__doc__},344 {"ICGetIndPref", (PyCFunction)ici_ICGetIndPref, METH_VARARGS,ici_ICGetIndPref__doc__},345 {"ICDeletePref", (PyCFunction)ici_ICDeletePref, METH_VARARGS,ici_ICDeletePref__doc__},346 {"ICEnd", (PyCFunction)ici_ICEnd, METH_VARARGS,ici_ICEnd__doc__},347 {"ICEditPreferences", (PyCFunction)ici_ICEditPreferences, METH_VARARGS,ici_ICEditPreferences__doc__},348 {"ICParseURL", (PyCFunction)ici_ICParseURL, METH_VARARGS,ici_ICParseURL__doc__},349 {"ICLaunchURL", (PyCFunction)ici_ICLaunchURL, METH_VARARGS,ici_ICLaunchURL__doc__},350 {"ICMapFilename", (PyCFunction)ici_ICMapFilename, METH_VARARGS,ici_ICMapFilename__doc__},351 {"ICMapTypeCreator", (PyCFunction)ici_ICMapTypeCreator, METH_VARARGS,ici_ICMapTypeCreator__doc__},352 353 {NULL, NULL}/* sentinel */339 {"ICGetSeed", (PyCFunction)ici_ICGetSeed, METH_VARARGS, ici_ICGetSeed__doc__}, 340 {"ICBegin", (PyCFunction)ici_ICBegin, METH_VARARGS, ici_ICBegin__doc__}, 341 {"ICFindPrefHandle", (PyCFunction)ici_ICFindPrefHandle, METH_VARARGS, ici_ICFindPrefHandle__doc__}, 342 {"ICSetPref", (PyCFunction)ici_ICSetPref, METH_VARARGS, ici_ICSetPref__doc__}, 343 {"ICCountPref", (PyCFunction)ici_ICCountPref, METH_VARARGS, ici_ICCountPref__doc__}, 344 {"ICGetIndPref", (PyCFunction)ici_ICGetIndPref, METH_VARARGS, ici_ICGetIndPref__doc__}, 345 {"ICDeletePref", (PyCFunction)ici_ICDeletePref, METH_VARARGS, ici_ICDeletePref__doc__}, 346 {"ICEnd", (PyCFunction)ici_ICEnd, METH_VARARGS, ici_ICEnd__doc__}, 347 {"ICEditPreferences", (PyCFunction)ici_ICEditPreferences, METH_VARARGS, ici_ICEditPreferences__doc__}, 348 {"ICParseURL", (PyCFunction)ici_ICParseURL, METH_VARARGS, ici_ICParseURL__doc__}, 349 {"ICLaunchURL", (PyCFunction)ici_ICLaunchURL, METH_VARARGS, ici_ICLaunchURL__doc__}, 350 {"ICMapFilename", (PyCFunction)ici_ICMapFilename, METH_VARARGS, ici_ICMapFilename__doc__}, 351 {"ICMapTypeCreator", (PyCFunction)ici_ICMapTypeCreator, METH_VARARGS, ici_ICMapTypeCreator__doc__}, 352 353 {NULL, NULL} /* sentinel */ 354 354 }; 355 355 … … 360 360 newiciobject(OSType creator) 361 361 { 362 363 364 365 366 367 368 369 370 371 372 373 362 iciobject *self; 363 OSStatus err; 364 365 self = PyObject_NEW(iciobject, &Icitype); 366 if (self == NULL) 367 return NULL; 368 if ((err=ICStart(&self->inst, creator)) != 0 ) { 369 (void)PyMac_Error(err); 370 PyObject_DEL(self); 371 return NULL; 372 } 373 return self; 374 374 } 375 375 … … 378 378 ici_dealloc(iciobject *self) 379 379 { 380 381 380 (void)ICStop(self->inst); 381 PyObject_DEL(self); 382 382 } 383 383 … … 385 385 ici_getattr(iciobject *self, char *name) 386 386 { 387 388 } 389 390 static char Icitype__doc__[] = 387 return Py_FindMethod(ici_methods, (PyObject *)self, name); 388 } 389 390 static char Icitype__doc__[] = 391 391 "Internet Config instance" 392 392 ; 393 393 394 394 static PyTypeObject Icitype = { 395 396 0,/*ob_size*/397 "icglue.ic_instance",/*tp_name*/398 sizeof(iciobject),/*tp_basicsize*/399 0,/*tp_itemsize*/400 401 (destructor)ici_dealloc,/*tp_dealloc*/402 (printfunc)0,/*tp_print*/403 (getattrfunc)ici_getattr,/*tp_getattr*/404 (setattrfunc)0,/*tp_setattr*/405 (cmpfunc)0,/*tp_compare*/406 (reprfunc)0,/*tp_repr*/407 0,/*tp_as_number*/408 0,/*tp_as_sequence*/409 0,/*tp_as_mapping*/410 (hashfunc)0,/*tp_hash*/411 (ternaryfunc)0,/*tp_call*/412 (reprfunc)0,/*tp_str*/413 414 415 416 395 PyObject_HEAD_INIT(&PyType_Type) 396 0, /*ob_size*/ 397 "icglue.ic_instance", /*tp_name*/ 398 sizeof(iciobject), /*tp_basicsize*/ 399 0, /*tp_itemsize*/ 400 /* methods */ 401 (destructor)ici_dealloc, /*tp_dealloc*/ 402 (printfunc)0, /*tp_print*/ 403 (getattrfunc)ici_getattr, /*tp_getattr*/ 404 (setattrfunc)0, /*tp_setattr*/ 405 (cmpfunc)0, /*tp_compare*/ 406 (reprfunc)0, /*tp_repr*/ 407 0, /*tp_as_number*/ 408 0, /*tp_as_sequence*/ 409 0, /*tp_as_mapping*/ 410 (hashfunc)0, /*tp_hash*/ 411 (ternaryfunc)0, /*tp_call*/ 412 (reprfunc)0, /*tp_str*/ 413 414 /* Space for future expansion */ 415 0L,0L,0L,0L, 416 Icitype__doc__ /* Documentation string */ 417 417 }; 418 418 … … 428 428 ic_ICStart(PyObject *self, PyObject *args) 429 429 { 430 431 432 433 434 430 OSType creator; 431 432 if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &creator)) 433 return NULL; 434 return (PyObject *)newiciobject(creator); 435 435 } 436 436 … … 438 438 439 439 static struct PyMethodDef ic_methods[] = { 440 {"ICStart", (PyCFunction)ic_ICStart, METH_VARARGS,ic_ICStart__doc__},441 442 {NULL, (PyCFunction)NULL, 0, NULL}/* sentinel */440 {"ICStart", (PyCFunction)ic_ICStart, METH_VARARGS, ic_ICStart__doc__}, 441 442 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ 443 443 }; 444 444 … … 446 446 /* Initialization function for the module (*must* be called initicglue) */ 447 447 448 static char icglue_module_documentation[] = 448 static char icglue_module_documentation[] = 449 449 "Implements low-level Internet Config interface" 450 450 ; … … 453 453 initicglue(void) 454 454 { 455 456 457 if (PyErr_WarnPy3k("In 3.x, icglue is removed.", 1))458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 } 478 455 PyObject *m, *d; 456 457 if (PyErr_WarnPy3k("In 3.x, the icglue module is removed.", 1)) 458 return; 459 460 /* Create the module and add the functions */ 461 m = Py_InitModule4("icglue", ic_methods, 462 icglue_module_documentation, 463 (PyObject*)NULL,PYTHON_API_VERSION); 464 465 /* Add some symbolic constants to the module */ 466 d = PyModule_GetDict(m); 467 ErrorObject = PyMac_GetOSErrException(); 468 if (ErrorObject == NULL || 469 PyDict_SetItemString(d, "error", ErrorObject) != 0) 470 return; 471 472 /* XXXX Add constants here */ 473 474 /* Check for errors */ 475 if (PyErr_Occurred()) 476 Py_FatalError("can't initialize module icglue"); 477 } 478
Note:
See TracChangeset
for help on using the changeset viewer.