Skip to content

AbstractSocketMixin

Base classes

Name Children Inherits
IODeviceMixin
prettyqt.core.iodevice

Subclasses

Class Module Description
AbstractSocket prettyqt.network.abstractsocket
TcpSocket prettyqt.network.tcpsocket
UdpSocket prettyqt.network.udpsocket

⋔ Inheritance diagram

graph TD
  1473574011472["network.AbstractSocketMixin"]
  1473299871632["core.IODeviceMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473299871632 --> 1473574011472
  1473299815024 --> 1473299871632
  140713234304496 --> 1473299815024

🛈 DocStrings

Bases: IODeviceMixin

Source code in prettyqt\network\abstractsocket.py
class AbstractSocketMixin(core.IODeviceMixin):
    def __repr__(self):
        return get_repr(self)

    def bind_to(
        self,
        address: str | network.QHostAddress,
        port: int = 0,
        bind_mode: (
            network.QAbstractSocket.BindFlag | BindModeStr
        ) = "default_for_platform",
    ) -> bool:
        if isinstance(address, str):
            address = network.QHostAddress(address)
        mode = BIND_MODE.get_enum_value(bind_mode)
        return self.bind(address, port, mode)

    def connect_to_host(
        self,
        hostname: str,
        port: int,
        open_mode: core.QIODevice.OpenModeFlag | core.iodevice.OpenModeStr = "read_write",
        protocol: (
            network.QAbstractSocket.NetworkLayerProtocol | NetworkLayerProtocolStr
        ) = "any_ip",
    ):
        mode = core.iodevice.OPEN_MODES.get_enum_value(open_mode)
        prot = NETWORK_LAYER_PROTOCOL.get_enum_value(protocol)
        self.connectToHost(hostname, port, mode, prot)

    def get_error(self) -> SocketErrorStr:
        return SOCKET_ERROR.inverse[self.error()]

    def set_pause_mode(self, mode: PauseModeStr | mod.PauseMode):
        """Set pause mode.

        Args:
            mode: pause mode
        """
        self.setPauseMode(PAUSE_MODES.get_enum_value(mode))

    def get_pause_mode(self) -> PauseModeStr:
        return PAUSE_MODES.inverse[self.pauseMode()]

    def get_proxy(self) -> network.NetworkProxy:
        return network.NetworkProxy(self.proxy())

    # def set_socket_option(self, name: str, value):
    #     self.setSocketOption(SOCKET_OPTION.get_enum_value(name), value)

    # def get_socket_option(self, name: str):
    #     return self.socketOption(SOCKET_OPTION.get_enum_value(name))

    # def set_type_of_service(self, typ: str):
    #     self.set_socket_option("type_of_service", TYPE_OF_SERVICE.get_enum_value(typ))

    # def get_type_of_service(self):
    #     opt = self.get_socket_option("type_of_service")
    #     return TYPE_OF_SERVICE.inverse[opt]

    def get_socket_type(self) -> SocketTypeStr:
        return SOCKET_TYPE.inverse[self.socketType()]

    def get_state(self) -> SocketStateStr:
        return SOCKET_STATE.inverse[self.state()]

    def get_local_address(self) -> network.HostAddress:
        return network.HostAddress(self.localAddress())

set_pause_mode(mode: PauseModeStr | mod.PauseMode)

Set pause mode.

Parameters:

Name Type Description Default
mode PauseModeStr | PauseMode

pause mode

required
Source code in prettyqt\network\abstractsocket.py
def set_pause_mode(self, mode: PauseModeStr | mod.PauseMode):
    """Set pause mode.

    Args:
        mode: pause mode
    """
    self.setPauseMode(PAUSE_MODES.get_enum_value(mode))