Include epplibwrapper module

This commit is contained in:
Seamus Johnston 2023-04-21 09:08:47 -05:00
parent d3cc3853c1
commit ce7cfc1a53
No known key found for this signature in database
GPG key ID: 2F21225985069105
14 changed files with 325 additions and 49 deletions

View file

@ -0,0 +1,37 @@
import logging
try:
from epplib import commands
except ImportError:
pass
from .errors import LoginError
logger = logging.getLogger(__name__)
class Socket:
"""Context manager which establishes a TCP connection with registry."""
def __init__(self, client, login) -> None:
"""Save the epplib client and login details."""
self.client = client
self.login = login
def __enter__(self):
"""Use epplib to connect."""
self.client.connect()
response = self.client.send(self.login)
if response.code >= 2000:
self.client.close()
raise LoginError(response.msg)
return self.client
def __exit__(self, *args, **kwargs):
"""Close the connection."""
try:
self.client.send(commands.Logout())
self.client.close()
except Exception:
logger.warning("Connection to registry was not cleanly closed.")