mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-01 18:18:34 +02:00
Template
This commit is contained in:
parent
1550fde832
commit
af852125f8
6 changed files with 1131 additions and 737 deletions
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue