root/trunk/twisted/application/strports.py

Revision 34127, 3.1 KB (checked in by thijs, 6 weeks ago)

Apply strportspatch.patch: Correct formatting in the docstring of t.application.strports.service.

Author: gdeng
Reviewer: jesstess, itamar, thijs
Fixes: #5055

Line 
1# -*- test-case-name: twisted.test.test_strports -*-
2# Copyright (c) Twisted Matrix Laboratories.
3# See LICENSE for details.
4
5"""
6Construct listening port services from a simple string description.
7
8@see: L{twisted.internet.endpoints.serverFromString}
9@see: L{twisted.internet.endpoints.clientFromString}
10"""
11
12import warnings
13
14from twisted.internet import endpoints
15from twisted.python.deprecate import deprecatedModuleAttribute
16from twisted.python.versions import Version
17from twisted.application.internet import StreamServerEndpointService
18
19
20
21def parse(description, factory, default='tcp'):
22    """
23    This function is deprecated as of Twisted 10.2.
24
25    @see: L{twisted.internet.endpoints.server}
26    """
27    return endpoints._parseServer(description, factory, default)
28
29deprecatedModuleAttribute(
30    Version("Twisted", 10, 2, 0),
31    "in favor of twisted.internet.endpoints.serverFromString",
32    __name__, "parse")
33
34
35
36_DEFAULT = object()
37
38def service(description, factory, default=_DEFAULT, reactor=None):
39    """
40    Return the service corresponding to a description.
41
42    @param description: The description of the listening port, in the syntax
43        described by L{twisted.internet.endpoints.server}.
44
45    @type description: C{str}
46
47    @param factory: The protocol factory which will build protocols for
48        connections to this service.
49
50    @type factory: L{twisted.internet.interfaces.IProtocolFactory}
51
52    @type default: C{str} or C{None}
53
54    @param default: Do not use this parameter. It has been deprecated since
55        Twisted 10.2.0.
56
57    @rtype: C{twisted.application.service.IService}
58
59    @return: the service corresponding to a description of a reliable
60        stream server.
61
62    @see: L{twisted.internet.endpoints.serverFromString}
63    """
64    if reactor is None:
65        from twisted.internet import reactor
66    if default is _DEFAULT:
67        default = None
68    else:
69        message = "The 'default' parameter was deprecated in Twisted 10.2.0."
70        if default is not None:
71            message += (
72                "  Use qualified endpoint descriptions; for example, "
73                "'tcp:%s'." % (description,))
74        warnings.warn(
75            message=message, category=DeprecationWarning, stacklevel=2)
76    svc = StreamServerEndpointService(
77        endpoints._serverFromStringLegacy(reactor, description, default),
78        factory)
79    svc._raiseSynchronously = True
80    return svc
81
82
83
84def listen(description, factory, default=None):
85    """Listen on a port corresponding to a description
86
87    @type description: C{str}
88    @type factory: L{twisted.internet.interfaces.IProtocolFactory}
89    @type default: C{str} or C{None}
90    @rtype: C{twisted.internet.interfaces.IListeningPort}
91    @return: the port corresponding to a description of a reliable
92    virtual circuit server.
93
94    See the documentation of the C{parse} function for description
95    of the semantics of the arguments.
96    """
97    from twisted.internet import reactor
98    name, args, kw = parse(description, factory, default)
99    return getattr(reactor, 'listen'+name)(*args, **kw)
100
101
102
103__all__ = ['parse', 'service', 'listen']
Note: See TracBrowser for help on using the browser.