Exemplo n.º 1
0
 def deserialize(self, value, display=False):
     validators.validate_required(value, self._required)
     if not value.strip():
         return None
     socket_path = path.get_unix_socket_path(value)
     if socket_path is not None:
         return 'unix:' + Path(not self._required).deserialize(socket_path)
     try:
         socket.getaddrinfo(value, None)
     except socket.error:
         raise ValueError('must be a resolveable hostname or valid IP')
     return value
Exemplo n.º 2
0
    def create_server_socket(self, host, port):
        socket_path = path.get_unix_socket_path(host)
        if socket_path is not None:  # host is a path so use unix socket
            sock = create_unix_socket()
            sock.bind(socket_path)
        else:
            # ensure the port is supplied
            validation.check_integer(port)
            sock = create_tcp_socket()
            sock.bind((host, port))

        sock.setblocking(False)
        sock.listen(1)
        return sock
Exemplo n.º 3
0
    def create_server_socket(self, host, port):
        socket_path = path.get_unix_socket_path(host)
        if socket_path is not None:  # host is a path so use unix socket
            sock = create_unix_socket()
            sock.bind(socket_path)
        else:
            # ensure the port is supplied
            validation.check_integer(port)
            sock = create_tcp_socket()
            sock.bind((host, port))

        sock.setblocking(False)
        sock.listen(1)
        return sock
Exemplo n.º 4
0
    def deserialize(self, value, display=False):
        value = decode(value).strip()
        validators.validate_required(value, self._required)
        if not value:
            return None

        socket_path = path.get_unix_socket_path(value)
        if socket_path is not None:
            path_str = Path(not self._required).deserialize(socket_path)
            return f"unix:{path_str}"

        try:
            socket.getaddrinfo(value, None)
        except OSError:
            raise ValueError("must be a resolveable hostname or valid IP")

        return value
Exemplo n.º 5
0
 def test_correctly_no_match_socket_path(self):
     assert path.get_unix_socket_path("127.0.0.1") is None
Exemplo n.º 6
0
 def test_correctly_matched_socket_path(self):
     assert (path.get_unix_socket_path("unix:/tmp/mopidy.socket") ==
             "/tmp/mopidy.socket")
Exemplo n.º 7
0
 def test_correctly_no_match_socket_path(self):
     self.assertIsNone(path.get_unix_socket_path('127.0.0.1'))
Exemplo n.º 8
0
 def test_correctly_matched_socket_path(self):
     self.assertEqual(
         path.get_unix_socket_path('unix:/tmp/mopidy.socket'),
         '/tmp/mopidy.socket'
     )
Exemplo n.º 9
0
def get_socket_address(host, port):
    unix_socket_path = path.get_unix_socket_path(host)
    if unix_socket_path is not None:
        return (unix_socket_path, None)
    else:
        return (host, port)