mirror of
https://github.com/django/daphne.git
synced 2024-11-21 23:46:33 +03:00
Remove domain from file descriptor in serverFromString (#68)
This commit is contained in:
parent
7597576db2
commit
71f6052fb3
|
@ -1,9 +1,9 @@
|
|||
import logging
|
||||
import socket
|
||||
import warnings
|
||||
|
||||
from twisted.internet import reactor, defer
|
||||
from twisted.logger import globalLogBeginner, STDLibLogObserver
|
||||
from twisted.internet.endpoints import serverFromString
|
||||
from twisted.logger import globalLogBeginner, STDLibLogObserver
|
||||
|
||||
from .http_protocol import HTTPFactory
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Server(object):
|
|||
channel_layer,
|
||||
host=None,
|
||||
port=None,
|
||||
endpoints=[],
|
||||
endpoints=None,
|
||||
unix_socket=None,
|
||||
file_descriptor=None,
|
||||
signal_handlers=True,
|
||||
|
@ -33,12 +33,12 @@ class Server(object):
|
|||
verbosity=1
|
||||
):
|
||||
self.channel_layer = channel_layer
|
||||
self.endpoints = endpoints
|
||||
self.endpoints = endpoints or []
|
||||
|
||||
if any([host, port, unix_socket, file_descriptor]):
|
||||
raise DeprecationWarning('''
|
||||
warnings.warn('''
|
||||
The host/port/unix_socket/file_descriptor keyword arguments to %s are deprecated.
|
||||
''' % self.__class__.__name__)
|
||||
''' % self.__class__.__name__, DeprecationWarning)
|
||||
# build endpoint description strings from deprecated kwargs
|
||||
self.endpoints = sorted(self.endpoints + build_endpoint_description_strings(
|
||||
host=host,
|
||||
|
@ -193,12 +193,6 @@ def build_endpoint_description_strings(
|
|||
socket_descriptions.append('unix:%s' % unix_socket)
|
||||
|
||||
if file_descriptor:
|
||||
socket_descriptions.append('fd:domain=INET:fileno=%d' % int(file_descriptor))
|
||||
socket_descriptions.append('fd:fileno=%d' % int(file_descriptor))
|
||||
|
||||
return socket_descriptions
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
# coding: utf8
|
||||
from __future__ import unicode_literals
|
||||
from unittest import TestCase
|
||||
from six import string_types
|
||||
import logging
|
||||
|
||||
from ..server import Server, build_endpoint_description_strings
|
||||
import logging
|
||||
from unittest import TestCase
|
||||
|
||||
from six import string_types
|
||||
|
||||
from ..cli import CommandLineInterface
|
||||
from ..server import Server, build_endpoint_description_strings
|
||||
|
||||
# this is the callable that will be tested here
|
||||
build = build_endpoint_description_strings
|
||||
|
||||
|
||||
class TestEndpointDescriptions(TestCase):
|
||||
|
||||
def testBasics(self):
|
||||
self.assertEqual(build(), [], msg="Empty list returned when no kwargs given")
|
||||
|
||||
|
@ -46,7 +47,7 @@ class TestEndpointDescriptions(TestCase):
|
|||
def testFileDescriptorBinding(self):
|
||||
self.assertEqual(
|
||||
build(file_descriptor=5),
|
||||
['fd:domain=INET:fileno=5']
|
||||
['fd:fileno=5']
|
||||
)
|
||||
|
||||
def testMultipleEnpoints(self):
|
||||
|
@ -62,13 +63,12 @@ class TestEndpointDescriptions(TestCase):
|
|||
sorted([
|
||||
'tcp:port=8080:interface=10.0.0.1',
|
||||
'unix:/tmp/daphne.sock',
|
||||
'fd:domain=INET:fileno=123'
|
||||
'fd:fileno=123'
|
||||
])
|
||||
)
|
||||
|
||||
|
||||
class TestCLIInterface(TestCase):
|
||||
|
||||
# construct a string that will be accepted as the channel_layer argument
|
||||
_import_channel_layer_string = 'daphne.tests.asgi:channel_layer'
|
||||
|
||||
|
@ -97,7 +97,8 @@ class TestCLIInterface(TestCase):
|
|||
cli = self.build_cli(cli_args=cli_args)
|
||||
return cli.server.endpoints
|
||||
|
||||
def checkCLI(self, args='', endpoints=[], msg='Expected endpoints do not match.'):
|
||||
def checkCLI(self, args='', endpoints=None, msg='Expected endpoints do not match.'):
|
||||
endpoints = endpoints or []
|
||||
cli = self.build_cli(cli_args=args)
|
||||
generated_endpoints = sorted(cli.server.endpoints)
|
||||
endpoints.sort()
|
||||
|
@ -149,14 +150,13 @@ class TestCLIInterface(TestCase):
|
|||
self.checkCLI(
|
||||
'-u /tmp/daphne.sock --fd 5',
|
||||
[
|
||||
'fd:domain=INET:fileno=5',
|
||||
'fd:fileno=5',
|
||||
'unix:/tmp/daphne.sock'
|
||||
],
|
||||
'File descriptor and unix socket bound, TCP ignored.'
|
||||
)
|
||||
|
||||
def testMixedCLIEndpointCreation(self):
|
||||
|
||||
self.checkCLI(
|
||||
'-p 8080 -e unix:/tmp/daphne.sock',
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue
Block a user