mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-03 11:07:25 +02:00
Include epplibwrapper module
This commit is contained in:
parent
d3cc3853c1
commit
ce7cfc1a53
14 changed files with 325 additions and 49 deletions
37
src/epplibwrapper/socket.py
Normal file
37
src/epplibwrapper/socket.py
Normal 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.")
|
Loading…
Add table
Add a link
Reference in a new issue