This commit is contained in:
zandercymatics 2023-10-11 12:58:00 -06:00
parent 1550fde832
commit af852125f8
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
6 changed files with 1131 additions and 737 deletions

View file

@ -20,6 +20,14 @@ class Socket:
self.login = login
def __enter__(self):
"""Runs connect(), which opens a connection with EPPLib."""
self.connect()
def __exit__(self, *args, **kwargs):
"""Runs disconnect(), which closes a connection with EPPLib."""
self.disconnect()
def connect(self):
"""Use epplib to connect."""
self.client.connect()
response = self.client.send(self.login)
@ -27,11 +35,22 @@ class Socket:
self.client.close()
raise LoginError(response.msg)
return self.client
def __exit__(self, *args, **kwargs):
def disconnect(self):
"""Close the connection."""
try:
self.client.send(commands.Logout())
self.client.close()
except Exception:
logger.warning("Connection to registry was not cleanly closed.")
def send(self, command):
logger.debug(f"command is this: {command}")
response = self.client.send(command)
# TODO - add some validation
"""
if response.code >= 2000:
self.client.close()
raise LoginError(response.msg)
"""
return response