blob: d5e03bd4d3b1795689aa5f8c558acc0fe0701090 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`ic` --- Access to the Mac OS X Internet Config
3====================================================
4
5.. module:: ic
6 :platform: Mac
7 :synopsis: Access to the Mac OS X Internet Config.
8
9
10This module provides access to various internet-related preferences set through
11:program:`System Preferences` or the :program:`Finder`.
12
13.. index:: module: icglue
14
15There is a low-level companion module :mod:`icglue` which provides the basic
16Internet Config access functionality. This low-level module is not documented,
17but the docstrings of the routines document the parameters and the routine names
18are the same as for the Pascal or C API to Internet Config, so the standard IC
19programmers' documentation can be used if this module is needed.
20
21The :mod:`ic` module defines the :exc:`error` exception and symbolic names for
22all error codes Internet Config can produce; see the source for details.
23
24
25.. exception:: error
26
27 Exception raised on errors in the :mod:`ic` module.
28
29The :mod:`ic` module defines the following class and function:
30
31
32.. class:: IC([signature[, ic]])
33
34 Create an Internet Config object. The signature is a 4-character creator code of
35 the current application (default ``'Pyth'``) which may influence some of ICs
36 settings. The optional *ic* argument is a low-level ``icglue.icinstance``
37 created beforehand, this may be useful if you want to get preferences from a
38 different config file, etc.
39
40
41.. function:: launchurl(url[, hint])
42 parseurl(data[, start[, end[, hint]]])
43 mapfile(file)
44 maptypecreator(type, creator[, filename])
45 settypecreator(file)
46
47 These functions are "shortcuts" to the methods of the same name, described
48 below.
49
50
51IC Objects
52----------
53
54:class:`IC` objects have a mapping interface, hence to obtain the mail address
55you simply get ``ic['MailAddress']``. Assignment also works, and changes the
56option in the configuration file.
57
58The module knows about various datatypes, and converts the internal IC
59representation to a "logical" Python data structure. Running the :mod:`ic`
60module standalone will run a test program that lists all keys and values in your
61IC database, this will have to serve as documentation.
62
63If the module does not know how to represent the data it returns an instance of
64the ``ICOpaqueData`` type, with the raw data in its :attr:`data` attribute.
65Objects of this type are also acceptable values for assignment.
66
67Besides the dictionary interface, :class:`IC` objects have the following
68methods:
69
70
71.. method:: IC.launchurl(url[, hint])
72
73 Parse the given URL, launch the correct application and pass it the URL. The
74 optional *hint* can be a scheme name such as ``'mailto:'``, in which case
75 incomplete URLs are completed with this scheme. If *hint* is not provided,
76 incomplete URLs are invalid.
77
78
79.. method:: IC.parseurl(data[, start[, end[, hint]]])
80
81 Find an URL somewhere in *data* and return start position, end position and the
82 URL. The optional *start* and *end* can be used to limit the search, so for
83 instance if a user clicks in a long text field you can pass the whole text field
84 and the click-position in *start* and this routine will return the whole URL in
85 which the user clicked. As above, *hint* is an optional scheme used to complete
86 incomplete URLs.
87
88
89.. method:: IC.mapfile(file)
90
91 Return the mapping entry for the given *file*, which can be passed as either a
92 filename or an :func:`FSSpec` result, and which need not exist.
93
94 The mapping entry is returned as a tuple ``(version, type, creator, postcreator,
95 flags, extension, appname, postappname, mimetype, entryname)``, where *version*
96 is the entry version number, *type* is the 4-character filetype, *creator* is
97 the 4-character creator type, *postcreator* is the 4-character creator code of
98 an optional application to post-process the file after downloading, *flags* are
99 various bits specifying whether to transfer in binary or ascii and such,
100 *extension* is the filename extension for this file type, *appname* is the
101 printable name of the application to which this file belongs, *postappname* is
102 the name of the postprocessing application, *mimetype* is the MIME type of this
103 file and *entryname* is the name of this entry.
104
105
106.. method:: IC.maptypecreator(type, creator[, filename])
107
108 Return the mapping entry for files with given 4-character *type* and *creator*
109 codes. The optional *filename* may be specified to further help finding the
110 correct entry (if the creator code is ``'????'``, for instance).
111
112 The mapping entry is returned in the same format as for *mapfile*.
113
114
115.. method:: IC.settypecreator(file)
116
117 Given an existing *file*, specified either as a filename or as an :func:`FSSpec`
118 result, set its creator and type correctly based on its extension. The finder
119 is told about the change, so the finder icon will be updated quickly.