Fred Drake | 3a0351c | 1998-04-04 07:23:21 +0000 | [diff] [blame] | 1 | \section{Built-in Module \module{ctb}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-ctb} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 3 | \bimodindex{ctb} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 4 | |
| 5 | This module provides a partial interface to the Macintosh |
| 6 | Communications Toolbox. Currently, only Connection Manager tools are |
Guido van Rossum | 96628a9 | 1995-04-10 11:34:00 +0000 | [diff] [blame] | 7 | supported. It may not be available in all Mac Python versions. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 8 | \index{Communications Toolbox, Macintosh} |
| 9 | \index{Macintosh Communications Toolbox} |
| 10 | \index{Connection Manager} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 11 | |
| 12 | \begin{datadesc}{error} |
| 13 | The exception raised on errors. |
| 14 | \end{datadesc} |
| 15 | |
| 16 | \begin{datadesc}{cmData} |
| 17 | \dataline{cmCntl} |
| 18 | \dataline{cmAttn} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 19 | Flags for the \var{channel} argument of the \method{Read()} and |
| 20 | \method{Write()} methods. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 21 | \end{datadesc} |
| 22 | |
| 23 | \begin{datadesc}{cmFlagsEOM} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 24 | End-of-message flag for \method{Read()} and \method{Write()}. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 25 | \end{datadesc} |
| 26 | |
| 27 | \begin{datadesc}{choose*} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 28 | Values returned by \method{Choose()}. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 29 | \end{datadesc} |
| 30 | |
| 31 | \begin{datadesc}{cmStatus*} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 32 | Bits in the status as returned by \method{Status()}. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 33 | \end{datadesc} |
| 34 | |
| 35 | \begin{funcdesc}{available}{} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 36 | Return \code{1} if the Communication Toolbox is available, zero otherwise. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 37 | \end{funcdesc} |
| 38 | |
Fred Drake | cce1090 | 1998-03-17 06:33:25 +0000 | [diff] [blame] | 39 | \begin{funcdesc}{CMNew}{name, sizes} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 40 | Create a connection object using the connection tool named |
| 41 | \var{name}. \var{sizes} is a 6-tuple given buffer sizes for data in, |
| 42 | data out, control in, control out, attention in and attention out. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 43 | Alternatively, passing \code{None} for \var{sizes} will result in |
| 44 | default buffer sizes. |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 45 | \end{funcdesc} |
| 46 | |
| 47 | \subsection{connection object} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 48 | \label{connection-object} |
| 49 | |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 50 | For all connection methods that take a \var{timeout} argument, a value |
| 51 | of \code{-1} is indefinite, meaning that the command runs to completion. |
| 52 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 53 | \begin{memberdesc}[connection]{callback} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 54 | If this member is set to a value other than \code{None} it should point |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 55 | to a function accepting a single argument (the connection |
| 56 | object). This will make all connection object methods work |
| 57 | asynchronously, with the callback routine being called upon |
| 58 | completion. |
| 59 | |
Fred Drake | af8a015 | 1998-01-14 14:51:31 +0000 | [diff] [blame] | 60 | \emph{Note:} for reasons beyond my understanding the callback routine |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 61 | is currently never called. You are advised against using asynchronous |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 62 | calls for the time being. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 63 | \end{memberdesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 64 | |
| 65 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 66 | \begin{methoddesc}[connection]{Open}{timeout} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 67 | Open an outgoing connection, waiting at most \var{timeout} seconds for |
| 68 | the connection to be established. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 69 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 70 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 71 | \begin{methoddesc}[connection]{Listen}{timeout} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 72 | Wait for an incoming connection. Stop waiting after \var{timeout} |
| 73 | seconds. This call is only meaningful to some tools. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 74 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 75 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 76 | \begin{methoddesc}[connection]{accept}{yesno} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 77 | Accept (when \var{yesno} is non-zero) or reject an incoming call after |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 78 | \method{Listen()} returned. |
| 79 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 80 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 81 | \begin{methoddesc}[connection]{Close}{timeout, now} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 82 | Close a connection. When \var{now} is zero, the close is orderly |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 83 | (i.e.\ outstanding output is flushed, etc.)\ with a timeout of |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 84 | \var{timeout} seconds. When \var{now} is non-zero the close is |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 85 | immediate, discarding output. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 86 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 87 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 88 | \begin{methoddesc}[connection]{Read}{len, chan, timeout} |
| 89 | Read \var{len} bytes, or until \var{timeout} seconds have passed, from |
| 90 | the channel \var{chan} (which is one of \constant{cmData}, |
| 91 | \constant{cmCntl} or \constant{cmAttn}). Return a 2-tuple:\ the data |
| 92 | read and the end-of-message flag, \constant{cmFlagsEOM}. |
| 93 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 94 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 95 | \begin{methoddesc}[connection]{Write}{buf, chan, timeout, eom} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 96 | Write \var{buf} to channel \var{chan}, aborting after \var{timeout} |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 97 | seconds. When \var{eom} has the value \constant{cmFlagsEOM}, an |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 98 | end-of-message indicator will be written after the data (if this |
| 99 | concept has a meaning for this communication tool). The method returns |
| 100 | the number of bytes written. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 101 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 102 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 103 | \begin{methoddesc}[connection]{Status}{} |
Guido van Rossum | 6bb1adc | 1995-03-13 10:03:32 +0000 | [diff] [blame] | 104 | Return connection status as the 2-tuple \code{(\var{sizes}, |
| 105 | \var{flags})}. \var{sizes} is a 6-tuple giving the actual buffer sizes used |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 106 | (see \function{CMNew()}), \var{flags} is a set of bits describing the state |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 107 | of the connection. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 108 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 109 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 110 | \begin{methoddesc}[connection]{GetConfig}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 111 | Return the configuration string of the communication tool. These |
| 112 | configuration strings are tool-dependent, but usually easily parsed |
| 113 | and modified. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 114 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 115 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 116 | \begin{methoddesc}[connection]{SetConfig}{str} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 117 | Set the configuration string for the tool. The strings are parsed |
| 118 | left-to-right, with later values taking precedence. This means |
| 119 | individual configuration parameters can be modified by simply appending |
| 120 | something like \code{'baud 4800'} to the end of the string returned by |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 121 | \method{GetConfig()} and passing that to this method. The method returns |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 122 | the number of characters actually parsed by the tool before it |
| 123 | encountered an error (or completed successfully). |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 124 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 125 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 126 | \begin{methoddesc}[connection]{Choose}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 127 | Present the user with a dialog to choose a communication tool and |
| 128 | configure it. If there is an outstanding connection some choices (like |
| 129 | selecting a different tool) may cause the connection to be |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 130 | aborted. The return value (one of the \constant{choose*} constants) will |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 131 | indicate this. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 132 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 133 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 134 | \begin{methoddesc}[connection]{Idle}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 135 | Give the tool a chance to use the processor. You should call this |
| 136 | method regularly. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 137 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 138 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 139 | \begin{methoddesc}[connection]{Abort}{} |
| 140 | Abort an outstanding asynchronous \method{Open()} or \method{Listen()}. |
| 141 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 142 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 143 | \begin{methoddesc}[connection]{Reset}{} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 144 | Reset a connection. Exact meaning depends on the tool. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 145 | \end{methoddesc} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 146 | |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 147 | \begin{methoddesc}[connection]{Break}{length} |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 148 | Send a break. Whether this means anything, what it means and |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 149 | interpretation of the \var{length} parameter depends on the tool in |
Jack Jansen | dcb0a9b | 1995-03-01 14:05:27 +0000 | [diff] [blame] | 150 | use. |
Fred Drake | 41788db | 1998-04-04 06:23:02 +0000 | [diff] [blame] | 151 | \end{methoddesc} |