Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding experimental __slots__ to some classes #368

Merged
merged 5 commits into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions amqp/abstract_channel.py
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions amqp/basic_message.py
Expand Up @@ -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')
Expand Down
12 changes: 12 additions & 0 deletions amqp/channel.py
Expand Up @@ -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)

Expand Down
17 changes: 17 additions & 0 deletions amqp/sasl.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions amqp/serialization.py
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions amqp/transport.py
Expand Up @@ -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]}'
Expand Down Expand Up @@ -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)
Expand Down