Skip to content

Commit

Permalink
Create xcmp_connector.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent e6b6553 commit 1bb4a79
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions projects/DAPIO/interoperability/xcmp/xcmp_connector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import http.client

class XCMPConnector:
def __init__(self, url: str, namespace: str):
self.url = url
self.namespace = namespace
self.adapter = XCMPAdapter(namespace)

def send_request(self, request: dict) -> dict:
xcmp = self.adapter.convert_to_xcmp(request)
headers = {"Content-Type": "application/xcmp+xml"}
conn = http.client.HTTPConnection(self.url)
conn.request("POST", "/", ET.tostring(xcmp, encoding="unicode"), headers)
response = conn.getresponse()
xcmp_response = ET.fromstring(response.read())
return self.adapter.convert_from_xcmp(xcmp_response)

def receive_request(self) -> dict:
conn = http.client.HTTPConnection(self.url)
conn.request("GET", "/")
response = conn.getresponse()
xcmp = ET.fromstring(response.read())
return self.adapter.convert_from_xcmp(xcmp)

0 comments on commit 1bb4a79

Please sign in to comment.