1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
35 extern int ResObj_Convert(PyObject
*, Handle
*); /* From Resmodule.c */
40 static PyObject
*ErrorObject
;
43 ici_error(ICError err
)
45 PyErr_SetObject(ErrorObject
, PyInt_FromLong((long)err
));
49 /* ----------------------------------------------------- */
51 /* Declarations for objects of type ic_instance */
58 staticforward PyTypeObject Icitype
;
62 /* ---------------------------------------------------------------- */
64 static char ici_ICFindConfigFile__doc__
[] =
65 "()->None; Find config file in standard places"
69 ici_ICFindConfigFile(self
, args
)
75 if (!PyArg_ParseTuple(args
, ""))
77 if ((err
=ICFindConfigFile(self
->inst
, 0, NULL
)) != 0 )
78 return ici_error(err
);
84 static char ici_ICFindUserConfigFile__doc__
[] =
85 "(vRefNum, dirID)->None; Find config file in specified place"
89 ici_ICFindUserConfigFile(self
, args
)
96 if (!PyArg_ParseTuple(args
, "sl", &where
.vRefNum
, &where
.dirID
))
98 if ((err
=ICFindUserConfigFile(self
->inst
, &where
)) != 0 )
99 return ici_error(err
);
105 static char ici_ICChooseConfig__doc__
[] =
106 "()->None; Let the user choose a config file"
110 ici_ICChooseConfig(self
, args
)
116 if (!PyArg_ParseTuple(args
, ""))
118 if ((err
=ICChooseConfig(self
->inst
)) != 0 )
119 return ici_error(err
);
125 static char ici_ICChooseNewConfig__doc__
[] =
126 "()->None; Let the user choose a new config file"
130 ici_ICChooseNewConfig(self
, args
)
136 if (!PyArg_ParseTuple(args
, ""))
138 if ((err
=ICChooseNewConfig(self
->inst
)) != 0 )
139 return ici_error(err
);
145 static char ici_ICGetSeed__doc__
[] =
146 "()->int; Returns int that changes when configuration does"
150 ici_ICGetSeed(self
, args
)
157 if (!PyArg_ParseTuple(args
, ""))
159 if ((err
=ICGetSeed(self
->inst
, &seed
)) != 0 )
160 return ici_error(err
);
161 return Py_BuildValue("i", (int)seed
);
165 static char ici_ICBegin__doc__
[] =
166 "(perm)->None; Lock config file for read/write"
170 ici_ICBegin(self
, args
)
177 if (!PyArg_ParseTuple(args
, "i", &perm
))
179 if ((err
=ICBegin(self
->inst
, (ICPerm
)perm
)) != 0 )
180 return ici_error(err
);
186 static char ici_ICFindPrefHandle__doc__
[] =
187 "(key, handle)->attrs; Lookup key, store result in handle, return attributes"
191 ici_ICFindPrefHandle(self
, args
)
200 if (!PyArg_ParseTuple(args
, "O&O&", PyMac_GetStr255
, &key
, ResObj_Convert
, &h
))
202 if ((err
=ICFindPrefHandle(self
->inst
, key
, &attr
, h
)) != 0 )
203 return ici_error(err
);
204 return Py_BuildValue("i", (int)attr
);
208 static char ici_ICSetPref__doc__
[] =
209 "(key, attr, data)->None; Set preference key to data with attributes"
213 ici_ICSetPref(self
, args
)
223 if (!PyArg_ParseTuple(args
, "O&is#", PyMac_GetStr255
, &key
, &attr
,
226 if ((err
=ICSetPref(self
->inst
, key
, (ICAttr
)attr
, (Ptr
)data
,
227 (long)datalen
)) != 0)
228 return ici_error(err
);
234 static char ici_ICCountPref__doc__
[] =
235 "()->int; Return number of preferences"
239 ici_ICCountPref(self
, args
)
246 if (!PyArg_ParseTuple(args
, ""))
248 if ((err
=ICCountPref(self
->inst
, &count
)) != 0 )
249 return ici_error(err
);
250 return Py_BuildValue("i", (int)count
);
254 static char ici_ICGetIndPref__doc__
[] =
255 "(num)->key; Return key of preference with given index"
259 ici_ICGetIndPref(self
, args
)
267 if (!PyArg_ParseTuple(args
, "l", &num
))
269 if ((err
=ICGetIndPref(self
->inst
, num
, key
)) != 0 )
270 return ici_error(err
);
271 return Py_BuildValue("O&", PyMac_BuildStr255
, key
);
275 static char ici_ICDeletePref__doc__
[] =
276 "(key)->None; Delete preference"
280 ici_ICDeletePref(self
, args
)
287 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
289 if ((err
=ICDeletePref(self
->inst
, key
)) != 0 )
290 return ici_error(err
);
296 static char ici_ICEnd__doc__
[] =
297 "()->None; Unlock file after ICBegin call"
301 ici_ICEnd(self
, args
)
307 if (!PyArg_ParseTuple(args
, ""))
309 if ((err
=ICEnd(self
->inst
)) != 0 )
310 return ici_error(err
);
316 static char ici_ICEditPreferences__doc__
[] =
317 "(key)->None; Ask user to edit preferences, staring with key"
321 ici_ICEditPreferences(self
, args
)
328 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, key
))
330 if ((err
=ICEditPreferences(self
->inst
, key
)) != 0 )
331 return ici_error(err
);
337 static char ici_ICParseURL__doc__
[] =
338 "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle"
342 ici_ICParseURL(self
, args
)
350 long selStart
, selEnd
;
353 if (!PyArg_ParseTuple(args
, "O&s#llO&", PyMac_GetStr255
, hint
, &data
, &datalen
,
354 &selStart
, &selEnd
, ResObj_Convert
, &h
))
356 if ((err
=ICParseURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
357 &selStart
, &selEnd
, h
)) != 0 )
358 return ici_error(err
);
359 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
363 static char ici_ICLaunchURL__doc__
[] =
364 "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app"
368 ici_ICLaunchURL(self
, args
)
376 long selStart
, selEnd
;
378 if (!PyArg_ParseTuple(args
, "O&s#ll", PyMac_GetStr255
, hint
, &data
, &datalen
,
381 if ((err
=ICLaunchURL(self
->inst
, hint
, (Ptr
)data
, (long)datalen
,
382 &selStart
, &selEnd
)) != 0 )
383 return ici_error(err
);
384 return Py_BuildValue("ii", (int)selStart
, (int)selEnd
);
388 static char ici_ICMapFilename__doc__
[] =
389 "(filename)->mapinfo; Get filemap info for given filename"
393 ici_ICMapFilename(self
, args
)
401 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetStr255
, filename
))
403 if ((err
=ICMapFilename(self
->inst
, filename
, &entry
)) != 0 )
404 return ici_error(err
);
405 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
406 PyMac_BuildOSType
, entry
.file_type
,
407 PyMac_BuildOSType
, entry
.file_creator
,
408 PyMac_BuildOSType
, entry
.post_creator
,
410 PyMac_BuildStr255
, entry
.extension
,
411 PyMac_BuildStr255
, entry
.creator_app_name
,
412 PyMac_BuildStr255
, entry
.post_app_name
,
413 PyMac_BuildStr255
, entry
.MIME_type
,
414 PyMac_BuildStr255
, entry
.entry_name
);
418 static char ici_ICMapTypeCreator__doc__
[] =
419 "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename"
423 ici_ICMapTypeCreator(self
, args
)
428 OSType type
, creator
;
432 if (!PyArg_ParseTuple(args
, "O&O&O&",
433 PyMac_GetOSType
, &type
,
434 PyMac_GetOSType
, &creator
,
435 PyMac_GetStr255
, filename
))
437 if ((err
=ICMapTypeCreator(self
->inst
, type
, creator
, filename
, &entry
)) != 0 )
438 return ici_error(err
);
439 return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry
.version
,
440 PyMac_BuildOSType
, entry
.file_type
,
441 PyMac_BuildOSType
, entry
.file_creator
,
442 PyMac_BuildOSType
, entry
.post_creator
,
444 PyMac_BuildStr255
, entry
.extension
,
445 PyMac_BuildStr255
, entry
.creator_app_name
,
446 PyMac_BuildStr255
, entry
.post_app_name
,
447 PyMac_BuildStr255
, entry
.MIME_type
,
448 PyMac_BuildStr255
, entry
.entry_name
);
452 static struct PyMethodDef ici_methods
[] = {
453 {"ICFindConfigFile", (PyCFunction
)ici_ICFindConfigFile
, METH_VARARGS
, ici_ICFindConfigFile__doc__
},
454 {"ICFindUserConfigFile", (PyCFunction
)ici_ICFindUserConfigFile
, METH_VARARGS
, ici_ICFindUserConfigFile__doc__
},
455 {"ICChooseConfig", (PyCFunction
)ici_ICChooseConfig
, METH_VARARGS
, ici_ICChooseConfig__doc__
},
456 {"ICChooseNewConfig", (PyCFunction
)ici_ICChooseNewConfig
, METH_VARARGS
, ici_ICChooseNewConfig__doc__
},
457 {"ICGetSeed", (PyCFunction
)ici_ICGetSeed
, METH_VARARGS
, ici_ICGetSeed__doc__
},
458 {"ICBegin", (PyCFunction
)ici_ICBegin
, METH_VARARGS
, ici_ICBegin__doc__
},
459 {"ICFindPrefHandle", (PyCFunction
)ici_ICFindPrefHandle
, METH_VARARGS
, ici_ICFindPrefHandle__doc__
},
460 {"ICSetPref", (PyCFunction
)ici_ICSetPref
, METH_VARARGS
, ici_ICSetPref__doc__
},
461 {"ICCountPref", (PyCFunction
)ici_ICCountPref
, METH_VARARGS
, ici_ICCountPref__doc__
},
462 {"ICGetIndPref", (PyCFunction
)ici_ICGetIndPref
, METH_VARARGS
, ici_ICGetIndPref__doc__
},
463 {"ICDeletePref", (PyCFunction
)ici_ICDeletePref
, METH_VARARGS
, ici_ICDeletePref__doc__
},
464 {"ICEnd", (PyCFunction
)ici_ICEnd
, METH_VARARGS
, ici_ICEnd__doc__
},
465 {"ICEditPreferences", (PyCFunction
)ici_ICEditPreferences
, METH_VARARGS
, ici_ICEditPreferences__doc__
},
466 {"ICParseURL", (PyCFunction
)ici_ICParseURL
, METH_VARARGS
, ici_ICParseURL__doc__
},
467 {"ICLaunchURL", (PyCFunction
)ici_ICLaunchURL
, METH_VARARGS
, ici_ICLaunchURL__doc__
},
468 {"ICMapFilename", (PyCFunction
)ici_ICMapFilename
, METH_VARARGS
, ici_ICMapFilename__doc__
},
469 {"ICMapTypeCreator", (PyCFunction
)ici_ICMapTypeCreator
, METH_VARARGS
, ici_ICMapTypeCreator__doc__
},
471 {NULL
, NULL
} /* sentinel */
478 newiciobject(OSType creator
)
483 self
= PyObject_NEW(iciobject
, &Icitype
);
486 if ((err
=ICStart(&self
->inst
, creator
)) != 0 ) {
487 (void)ici_error(err
);
499 (void)ICStop(self
->inst
);
504 ici_getattr(self
, name
)
508 return Py_FindMethod(ici_methods
, (PyObject
*)self
, name
);
511 static char Icitype__doc__
[] =
512 "Internet Config instance"
515 static PyTypeObject Icitype
= {
516 PyObject_HEAD_INIT(&PyType_Type
)
518 "ic_instance", /*tp_name*/
519 sizeof(iciobject
), /*tp_basicsize*/
522 (destructor
)ici_dealloc
, /*tp_dealloc*/
523 (printfunc
)0, /*tp_print*/
524 (getattrfunc
)ici_getattr
, /*tp_getattr*/
525 (setattrfunc
)0, /*tp_setattr*/
526 (cmpfunc
)0, /*tp_compare*/
527 (reprfunc
)0, /*tp_repr*/
529 0, /*tp_as_sequence*/
531 (hashfunc
)0, /*tp_hash*/
532 (ternaryfunc
)0, /*tp_call*/
533 (reprfunc
)0, /*tp_str*/
535 /* Space for future expansion */
537 Icitype__doc__
/* Documentation string */
540 /* End of code for ic_instance objects */
541 /* -------------------------------------------------------- */
544 static char ic_ICStart__doc__
[] =
545 "(OSType)->ic_instance; Create an Internet Config instance"
549 ic_ICStart(self
, args
)
550 PyObject
*self
; /* Not used */
555 if (!PyArg_ParseTuple(args
, "O&", PyMac_GetOSType
, &creator
))
557 return (PyObject
*)newiciobject(creator
);
560 /* List of methods defined in the module */
562 static struct PyMethodDef ic_methods
[] = {
563 {"ICStart", (PyCFunction
)ic_ICStart
, METH_VARARGS
, ic_ICStart__doc__
},
565 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
569 /* Initialization function for the module (*must* be called initicglue) */
571 static char icglue_module_documentation
[] =
572 "Implements low-level Internet Config interface"
580 /* Create the module and add the functions */
581 m
= Py_InitModule4("icglue", ic_methods
,
582 icglue_module_documentation
,
583 (PyObject
*)NULL
,PYTHON_API_VERSION
);
585 /* Add some symbolic constants to the module */
586 d
= PyModule_GetDict(m
);
587 ErrorObject
= PyString_FromString("icglue.error");
588 PyDict_SetItemString(d
, "error", ErrorObject
);
590 /* XXXX Add constants here */
592 /* Check for errors */
593 if (PyErr_Occurred())
594 Py_FatalError("can't initialize module icglue");