diff --git a/amqp/abstract_channel.py b/amqp/abstract_channel.py index 6234b196..ae95a89e 100644 --- a/amqp/abstract_channel.py +++ b/amqp/abstract_channel.py @@ -39,6 +39,19 @@ def __init__(self, connection, channel_id): self._setup_listeners() + __slots__ = ( + "is_closing", + "connection", + "channel_id", + "method_queue", + "auto_decode", + "_pending", + "_callbacks", + # adding '__dict__' to get dynamic assignment + "__dict__", + "__weakref__", + ) + def __enter__(self): return self diff --git a/amqp/basic_message.py b/amqp/basic_message.py index 222d3660..cee0515d 100644 --- a/amqp/basic_message.py +++ b/amqp/basic_message.py @@ -107,6 +107,12 @@ def __init__(self, body='', children=None, channel=None, **properties): self.body = body self.channel = channel + __slots__ = ( + "delivery_info", + "body", + "channel", + ) + @property def headers(self): return self.properties.get('application_headers') diff --git a/amqp/channel.py b/amqp/channel.py index b2718204..281fc461 100644 --- a/amqp/channel.py +++ b/amqp/channel.py @@ -122,6 +122,18 @@ def __init__(self, connection, if self.connection.confirm_publish: self.basic_publish = self.basic_publish_confirm + __slots__ = ( + "is_open", + "active", + "returned_messages", + "callbacks", + "cancel_callbacks", + "events", + "no_ack_consumers", + "on_open", + "_confirm_selected", + ) + def then(self, on_success, on_error=None): return self.on_open.then(on_success, on_error) diff --git a/amqp/sasl.py b/amqp/sasl.py index 9a98a7af..407ccb8e 100644 --- a/amqp/sasl.py +++ b/amqp/sasl.py @@ -34,6 +34,11 @@ class PLAIN(SASL): def __init__(self, username, password): self.username, self.password = username, password + __slots__ = ( + "username", + "password", + ) + def start(self, connection): if self.username is None or self.password is None: return NotImplemented @@ -56,6 +61,11 @@ class AMQPLAIN(SASL): def __init__(self, username, password): self.username, self.password = username, password + __slots__ = ( + "username", + "password", + ) + def start(self, connection): if self.username is None or self.password is None: return NotImplemented @@ -104,6 +114,13 @@ def __init__(self, client_name=None, service=b'amqp', self.service = service self.rdns = rdns + __slots__ = ( + "client_name", + "fail_soft", + "service", + "rdns" + ) + def get_hostname(self, connection): sock = connection.transport.sock if self.rdns and sock.family in (socket.AF_INET, diff --git a/amqp/serialization.py b/amqp/serialization.py index 90f5857a..1f2f8e2d 100644 --- a/amqp/serialization.py +++ b/amqp/serialization.py @@ -488,6 +488,19 @@ def __init__(self, frame_method=None, frame_args=None, **props): self.body_size = 0 self.ready = False + __slots__ = ( + "frame_method", + "frame_args", + "properties", + "_pending_chunks", + "body_received", + "body_size", + "ready", + # adding '__dict__' to get dynamic assignment + "__dict__", + "__weakref__", + ) + def __getattr__(self, name): # Look for additional properties in the 'properties' # dictionary, and if present - the 'delivery_info' dictionary. diff --git a/amqp/transport.py b/amqp/transport.py index 701c34ca..cebd3b65 100644 --- a/amqp/transport.py +++ b/amqp/transport.py @@ -97,6 +97,22 @@ def __init__(self, host, connect_timeout=None, self.write_timeout = write_timeout self.socket_settings = socket_settings + __slots__ = ( + "connection", + "sock", + "raise_on_initial_eintr", + "_read_buffer", + "host", + "port", + "connect_timeout", + "read_timeout", + "write_timeout", + "socket_settings", + # adding '__dict__' to get dynamic assignment + "__dict__", + "__weakref__", + ) + def __repr__(self): if self.sock: src = f'{self.sock.getsockname()[0]}:{self.sock.getsockname()[1]}' @@ -399,6 +415,10 @@ def __init__(self, host, connect_timeout=None, ssl=None, **kwargs): super().__init__( host, connect_timeout=connect_timeout, **kwargs) + __slots__ = ( + "sslopts", + ) + def _setup_transport(self): """Wrap the socket in an SSL object.""" self.sock = self._wrap_socket(self.sock, **self.sslopts)