97
97
def parse(description, factory, default=None):
98
"""Parse a description of a reliable virtual circuit server
100
@type description: C{str}
101
@type factory: C{twisted.internet.interfaces.IProtocolFactory}
102
@type default: C{str} or C{None}
104
@return: a tuple of string, tuple and dictionary. The string
105
is the name of the method (sans C{'listen'}) to call, and
106
the tuple and dictionary are the arguments and keyword arguments
108
@raises: C{ValueError} if the string is formatted incorrectly,
109
C{KeyError} if the type is other than unix, ssl or tcp.
111
Parse the description of a reliable virtual circuit server (that is,
112
a TCP port, a UNIX domain socket or an SSL port) and return the
113
data necessary to call the reactor methods to listen on the given
114
socket with the given factory.
99
Parse the description of a reliable virtual circuit server (that is, a
100
TCP port, a UNIX domain socket or an SSL port) and return the data
101
necessary to call the reactor methods to listen on the given socket with
116
104
An argument with no colons means a default port. Usually the default
117
type is C{tcp}, but passing a non-C{None} value as C{default} will
118
set that as the default. Otherwise, it is a colon-separated string.
119
The first part means the type -- currently,
120
it can only be ssl, unix or tcp. After that, comes a list of
121
arguments. Arguments can be positional or keyword, and can be mixed.
122
Keyword arguments are indicated by C{'name=value'}. If a value is supposed
123
to contain a C{':'}, a C{'='} or a C{'\\'}, escape it with a C{'\\'}.
105
type is C{tcp}, but passing a non-C{None} value as C{default} will set
106
that as the default. Otherwise, it is a colon-separated string. The
107
first part means the type -- currently, it can only be ssl, unix or tcp.
108
After that, comes a list of arguments. Arguments can be positional or
109
keyword, and can be mixed. Keyword arguments are indicated by
110
C{'name=value'}. If a value is supposed to contain a C{':'}, a C{'='} or
111
a C{'\\'}, escape it with a C{'\\'}.
125
113
For TCP, the arguments are the port (port number) and, optionally the
126
interface (interface on which to listen) and backlog (how many clients to
127
keep in the backlog).
114
interface (interface on which to listen) and backlog (how many clients
115
to keep in the backlog).
129
117
For UNIX domain sockets, the arguments are address (the file name of the
130
118
socket) and optionally the mode (the mode bits of the file, as an octal
131
119
number) and the backlog (how many clients to keep in the backlog).
133
For SSL sockets, the arguments are the port (port number) and, optionally,
134
the privateKey (file in which the private key is in), certKey (file in
135
which the certification is in), sslmethod (the name of the SSL method
136
to allow), the interface (interface on which to listen) and the
137
backlog (how many clients to keep in the backlog).
121
For SSL sockets, the arguments are the port (port number) and,
122
optionally, the privateKey (file in which the private key is in),
123
certKey (file in which the certification is in), sslmethod (the name of
124
the SSL method to allow), the interface (interface on which to listen)
125
and the backlog (how many clients to keep in the backlog).
127
@type description: C{str}
128
@type factory: L{twisted.internet.interfaces.IProtocolFactory}
129
@type default: C{str} or C{None}
131
@return: a tuple of string, tuple and dictionary. The string is the name
132
of the method (sans C{'listen'}) to call, and the tuple and dictionary
133
are the arguments and keyword arguments to the method.
134
@raises ValueError: if the string is formatted incorrectly.
135
@raises KeyError: if the type is other than unix, ssl or tcp.
139
137
args, kw = _parse(description)
140
138
if not args or (len(args)==1 and not kw):