~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/application/strports.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
    return args, kw 
96
96
 
97
97
def parse(description, factory, default=None):
98
 
    """Parse a description of a reliable virtual circuit server
99
 
 
100
 
    @type description: C{str}
101
 
    @type factory: C{twisted.internet.interfaces.IProtocolFactory}
102
 
    @type default: C{str} or C{None}
103
 
    @rtype: C{tuple}
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
107
 
    to the method.
108
 
    @raises: C{ValueError} if the string is formatted incorrectly,
109
 
    C{KeyError} if the type is other than unix, ssl or tcp.
110
 
 
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.
 
98
    """
 
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
 
102
    the given factory.
115
103
 
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{'\\'}.
124
112
 
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).
128
116
 
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).
132
120
 
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).
 
126
 
 
127
    @type description: C{str}
 
128
    @type factory: L{twisted.internet.interfaces.IProtocolFactory}
 
129
    @type default: C{str} or C{None}
 
130
    @rtype: C{tuple}
 
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.
138
136
    """
139
137
    args, kw = _parse(description)
140
138
    if not args or (len(args)==1 and not kw):
145
143
    """Return the service corresponding to a description
146
144
 
147
145
    @type description: C{str}
148
 
    @type factory: C{twisted.internet.interfaces.IProtocolFactory}
 
146
    @type factory: L{twisted.internet.interfaces.IProtocolFactory}
149
147
    @type default: C{str} or C{None}
150
148
    @rtype: C{twisted.application.service.IService}
151
149
    @return: the service corresponding to a description of a reliable
162
160
    """Listen on a port corresponding to a description
163
161
 
164
162
    @type description: C{str}
165
 
    @type factory: C{twisted.internet.interfaces.IProtocolFactory}
 
163
    @type factory: L{twisted.internet.interfaces.IProtocolFactory}
166
164
    @type default: C{str} or C{None}
167
165
    @rtype: C{twisted.internet.interfaces.IListeningPort}
168
166
    @return: the port corresponding to a description of a reliable