Beispiel #1
0
def parse(description, factory, default='tcp'):
    """
    This function is deprecated as of Twisted 10.2.

    @see: L{twisted.internet.endpoints.server}
    """
    return endpoints._parseServer(description, factory, default)
Beispiel #2
0
def parse(description, factory, default='tcp'):
    """
    This function is deprecated as of Twisted 10.2.

    @see: L{twisted.internet.endpoints.server}
    """
    return endpoints._parseServer(description, factory, default)
 def test_defaultPort(self):
     """
     If the I{--port} option is not specified, L{Options} defaults the port
     to C{8080}.
     """
     options = Options()
     options.parseOptions([])
     self.assertEqual(endpoints._parseServer(options["port"], None)[:2], ("TCP", (8080, None)))
Beispiel #4
0
 def test_defaultPort(self):
     """
     If the I{--port} option is not specified, L{Options} defaults the port
     to C{8080}.
     """
     options = Options()
     options.parseOptions([])
     self.assertEqual(
         endpoints._parseServer(options['port'], None)[:2],
         ('TCP', (8080, None)))
 def test_defaultPersonalPath(self):
     """
     If the I{--port} option not specified but the I{--personal} option is,
     L{Options} defaults the port to C{UserDirectory.userSocketName} in the
     user's home directory.
     """
     options = Options()
     options.parseOptions(['--personal'])
     path = os.path.expanduser(
         os.path.join('~', UserDirectory.userSocketName))
     self.assertEqual(
         endpoints._parseServer(options['port'], None)[:2],
         ('UNIX', (path, None)))
Beispiel #6
0
 def test_defaultPersonalPath(self):
     """
     If the I{--port} option not specified but the I{--personal} option is,
     L{Options} defaults the port to C{UserDirectory.userSocketName} in the
     user's home directory.
     """
     options = Options()
     options.parseOptions(['--personal'])
     path = os.path.expanduser(
         os.path.join('~', UserDirectory.userSocketName))
     self.assertEqual(
         endpoints._parseServer(options['port'], None)[:2],
         ('UNIX', (path, None)))
Beispiel #7
0
def listen(description, factory, default=None):
    """Listen on a port corresponding to a description

    @type description: L{str}
    @type factory: L{twisted.internet.interfaces.IProtocolFactory}
    @type default: L{str} or L{None}
    @rtype: L{twisted.internet.interfaces.IListeningPort}
    @return: the port corresponding to a description of a reliable
    virtual circuit server.

    @see: L{twisted.internet.endpoints.serverFromString}
    """
    from twisted.internet import reactor
    name, args, kw = endpoints._parseServer(description, factory, default)
    return getattr(reactor, 'listen' + name)(*args, **kw)
Beispiel #8
0
def endpoint_string_to_url(desc, scheme='http', hostname='localhost', path='/', listening_port=None):
    """Construct a URL from a twisted.internet.endpoints string.
    
    If listening_port is supplied then it is used to obtain the actual port number."""
    (method, args, _) = endpoints._parseServer(desc, None)
    if listening_port:
        # assuming that this is a TCP port object
        port_number = listening_port.getHost().port
    else:
        port_number = args[0]
    if method == 'TCP':
        return scheme + '://' + hostname + ':' + str(port_number) + path
    elif method == 'SSL':
        return scheme + 's://' + hostname + ':' + str(port_number) + path
    else:
        # TODO better error return
        return '???'
Beispiel #9
0
def endpoint_string_to_url(desc, scheme='http', hostname='localhost', path='/', listening_port=None):
    """Construct a URL from a twisted.internet.endpoints string.
    
    If listening_port is supplied then it is used to obtain the actual port number."""
    (method, args, _) = endpoints._parseServer(desc, None)
    if listening_port:
        # assuming that this is a TCP port object
        port_number = listening_port.getHost().port
    else:
        port_number = args[0]
    if method == 'TCP':
        return scheme + '://' + hostname + ':' + str(port_number) + path
    elif method == 'SSL':
        return scheme + 's://' + hostname + ':' + str(port_number) + path
    else:
        # TODO better error return
        return '???'
Beispiel #10
0
def listen(description, factory):
    """
    Listen on a port corresponding to a description.

    @param description: The description of the connecting port, in the syntax
        described by L{twisted.internet.endpoints.serverFromString}.
    @type description: L{str}

    @param factory: The protocol factory which will build protocols on
        connection.
    @type factory: L{twisted.internet.interfaces.IProtocolFactory}

    @rtype: L{twisted.internet.interfaces.IListeningPort}
    @return: the port corresponding to a description of a reliable virtual
        circuit server.

    @see: L{twisted.internet.endpoints.serverFromString}
    """
    from twisted.internet import reactor
    name, args, kw = endpoints._parseServer(description, factory)
    return getattr(reactor, 'listen' + name)(*args, **kw)
Beispiel #11
0
def listen(description, factory):
    """
    Listen on a port corresponding to a description.

    @param description: The description of the connecting port, in the syntax
        described by L{twisted.internet.endpoints.serverFromString}.
    @type description: L{str}

    @param factory: The protocol factory which will build protocols on
        connection.
    @type factory: L{twisted.internet.interfaces.IProtocolFactory}

    @rtype: L{twisted.internet.interfaces.IListeningPort}
    @return: the port corresponding to a description of a reliable virtual
        circuit server.

    @see: L{twisted.internet.endpoints.serverFromString}
    """
    from twisted.internet import reactor
    name, args, kw = endpoints._parseServer(description, factory)
    return getattr(reactor, 'listen' + name)(*args, **kw)
Beispiel #12
0
 def parse(self, *a, **kw):
     """
     Provide a hook for test_strports to substitute the deprecated API.
     """
     return endpoints._parseServer(*a, **kw)
Beispiel #13
0
 def parse(self, *a, **kw):
     """
     Provide a hook for test_strports to substitute the deprecated API.
     """
     return endpoints._parseServer(*a, **kw)