Compare commits
No commits in common. "c63ecf77818cb47d5374cfacb8aa236357c2ab93" and "f62579ce908f3baf97cddeac2918ca794c341fa6" have entirely different histories.
c63ecf7781
...
f62579ce90
@ -44,10 +44,9 @@ class OMMClient2:
|
|||||||
:param id: User id
|
:param id: User id
|
||||||
"""
|
"""
|
||||||
|
|
||||||
r = self.session.request(messages.GetAccount(id))
|
r = self.session.request(message.GetAccount(id))
|
||||||
r.raise_on_error()
|
r.raise_on_error()
|
||||||
if r.account is None:
|
|
||||||
return None
|
|
||||||
return r.account[0]
|
return r.account[0]
|
||||||
|
|
||||||
def ping(self):
|
def ping(self):
|
||||||
|
@ -22,9 +22,7 @@ class Connection:
|
|||||||
self._host = host
|
self._host = host
|
||||||
self._port = port
|
self._port = port
|
||||||
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self._recv_buffer = b""
|
self._recv_buffer = ""
|
||||||
|
|
||||||
self._socket.settimeout(3)
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""
|
"""
|
||||||
@ -51,26 +49,21 @@ class Connection:
|
|||||||
|
|
||||||
data = b""
|
data = b""
|
||||||
while True:
|
while True:
|
||||||
try:
|
new_data = self._socket.recv(65536)
|
||||||
new_data = self._socket.recv(1024)
|
if new_data is not None:
|
||||||
except TimeoutError:
|
data += new_data
|
||||||
|
else:
|
||||||
break
|
break
|
||||||
|
self._recv_buffer += data.decode("utf-8")
|
||||||
|
|
||||||
data += new_data
|
if "\0" not in self._recv_buffer:
|
||||||
|
|
||||||
if b"\0" in new_data:
|
|
||||||
break
|
|
||||||
|
|
||||||
self._recv_buffer += data
|
|
||||||
|
|
||||||
if b"\0" not in self._recv_buffer:
|
|
||||||
# no new messages
|
# no new messages
|
||||||
return None
|
return None
|
||||||
|
|
||||||
message, buffer = self._recv_buffer.split(b"\0", 1)
|
message, buffer = self._recv_buffer.split("\0", 1)
|
||||||
self._recv_buffer = buffer
|
self._recv_buffer = buffer
|
||||||
|
|
||||||
return message.decode("utf-8")
|
return message
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
@ -87,10 +80,6 @@ class SSLConnection(Connection):
|
|||||||
"""
|
"""
|
||||||
Establishes a secure connection to the OM Application XML Interface
|
Establishes a secure connection to the OM Application XML Interface
|
||||||
|
|
||||||
Please not that this class might be useless on your system since new
|
|
||||||
versions of OpenSSL don't ship with TLVv1.2 or lower anymore which are
|
|
||||||
the protocols supported by OMM.
|
|
||||||
|
|
||||||
:param host: Hostname or IP address of OMM
|
:param host: Hostname or IP address of OMM
|
||||||
:param port: Port of the OM Application XML ssl TCP port
|
:param port: Port of the OM Application XML ssl TCP port
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class Response:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if self.errCode is not None:
|
if self.errCode is not None:
|
||||||
raise exception_classes.get(self.errCode, OMResponseException)(response=self)
|
raise exception_classes.get(self.errCode, OMResponseException)()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def seq(self):
|
def seq(self):
|
||||||
@ -98,7 +98,6 @@ class Response:
|
|||||||
return self.attrs.get("maxLen")
|
return self.attrs.get("maxLen")
|
||||||
|
|
||||||
from .getaccount import GetAccount, GetAccountResp
|
from .getaccount import GetAccount, GetAccountResp
|
||||||
from .open import Open, OpenResp
|
|
||||||
from .ping import Ping, PingResp
|
from .ping import Ping, PingResp
|
||||||
|
|
||||||
def construct(request):
|
def construct(request):
|
||||||
|
@ -24,4 +24,4 @@ class GetAccount(Request):
|
|||||||
class GetAccountResp(Response):
|
class GetAccountResp(Response):
|
||||||
@property
|
@property
|
||||||
def account(self):
|
def account(self):
|
||||||
return self.childs.get("account")
|
return self.attrs.get("account")
|
||||||
|
@ -27,7 +27,7 @@ class Session:
|
|||||||
self.port = port
|
self.port = port
|
||||||
self.connection_class = connection_class
|
self.connection_class = connection_class
|
||||||
if self.connection_class is None:
|
if self.connection_class is None:
|
||||||
self.connection_class = connection.Connection
|
self.connection_class = connection.SSLConnection
|
||||||
|
|
||||||
self._connection = None
|
self._connection = None
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class Session:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
r = self._connection.recv()
|
r = self.connection.recv()
|
||||||
if r is not None:
|
if r is not None:
|
||||||
return r
|
return r
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
@ -58,9 +58,11 @@ class Session:
|
|||||||
self._connection.connect()
|
self._connection.connect()
|
||||||
|
|
||||||
# Login
|
# Login
|
||||||
r = self.request(messages.Open(self.username, self.password))
|
self._connection.send(messages.Open(self.username, self.password))
|
||||||
|
|
||||||
r.raise_on_error()
|
res = self._wait_for_respose()
|
||||||
|
|
||||||
|
res.raise_on_error()
|
||||||
|
|
||||||
def request(self, request):
|
def request(self, request):
|
||||||
"""
|
"""
|
||||||
@ -75,7 +77,7 @@ class Session:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
message = messages.construct(request)
|
message = messages.construct(request)
|
||||||
self._connection.send(message)
|
self.connection.send(message)
|
||||||
|
|
||||||
res = self._wait_for_respose()
|
res = self._wait_for_respose()
|
||||||
return messages.parse(res)
|
return messages.parse(res)
|
||||||
|
Loading…
Reference in New Issue
Block a user