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
|
||||
"""
|
||||
|
||||
r = self.session.request(messages.GetAccount(id))
|
||||
r = self.session.request(message.GetAccount(id))
|
||||
r.raise_on_error()
|
||||
if r.account is None:
|
||||
return None
|
||||
|
||||
return r.account[0]
|
||||
|
||||
def ping(self):
|
||||
|
@ -22,9 +22,7 @@ class Connection:
|
||||
self._host = host
|
||||
self._port = port
|
||||
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self._recv_buffer = b""
|
||||
|
||||
self._socket.settimeout(3)
|
||||
self._recv_buffer = ""
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
@ -51,26 +49,21 @@ class Connection:
|
||||
|
||||
data = b""
|
||||
while True:
|
||||
try:
|
||||
new_data = self._socket.recv(1024)
|
||||
except TimeoutError:
|
||||
break
|
||||
|
||||
new_data = self._socket.recv(65536)
|
||||
if new_data is not None:
|
||||
data += new_data
|
||||
|
||||
if b"\0" in new_data:
|
||||
else:
|
||||
break
|
||||
self._recv_buffer += data.decode("utf-8")
|
||||
|
||||
self._recv_buffer += data
|
||||
|
||||
if b"\0" not in self._recv_buffer:
|
||||
if "\0" not in self._recv_buffer:
|
||||
# no new messages
|
||||
return None
|
||||
|
||||
message, buffer = self._recv_buffer.split(b"\0", 1)
|
||||
message, buffer = self._recv_buffer.split("\0", 1)
|
||||
self._recv_buffer = buffer
|
||||
|
||||
return message.decode("utf-8")
|
||||
return message
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
@ -87,10 +80,6 @@ class SSLConnection(Connection):
|
||||
"""
|
||||
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 port: Port of the OM Application XML ssl TCP port
|
||||
|
||||
|
@ -75,7 +75,7 @@ class Response:
|
||||
"""
|
||||
|
||||
if self.errCode is not None:
|
||||
raise exception_classes.get(self.errCode, OMResponseException)(response=self)
|
||||
raise exception_classes.get(self.errCode, OMResponseException)()
|
||||
|
||||
@property
|
||||
def seq(self):
|
||||
@ -98,7 +98,6 @@ class Response:
|
||||
return self.attrs.get("maxLen")
|
||||
|
||||
from .getaccount import GetAccount, GetAccountResp
|
||||
from .open import Open, OpenResp
|
||||
from .ping import Ping, PingResp
|
||||
|
||||
def construct(request):
|
||||
|
@ -24,4 +24,4 @@ class GetAccount(Request):
|
||||
class GetAccountResp(Response):
|
||||
@property
|
||||
def account(self):
|
||||
return self.childs.get("account")
|
||||
return self.attrs.get("account")
|
||||
|
@ -27,7 +27,7 @@ class Session:
|
||||
self.port = port
|
||||
self.connection_class = connection_class
|
||||
if self.connection_class is None:
|
||||
self.connection_class = connection.Connection
|
||||
self.connection_class = connection.SSLConnection
|
||||
|
||||
self._connection = None
|
||||
|
||||
@ -39,7 +39,7 @@ class Session:
|
||||
"""
|
||||
|
||||
while True:
|
||||
r = self._connection.recv()
|
||||
r = self.connection.recv()
|
||||
if r is not None:
|
||||
return r
|
||||
sleep(0.1)
|
||||
@ -58,9 +58,11 @@ class Session:
|
||||
self._connection.connect()
|
||||
|
||||
# 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):
|
||||
"""
|
||||
@ -75,7 +77,7 @@ class Session:
|
||||
"""
|
||||
|
||||
message = messages.construct(request)
|
||||
self._connection.send(message)
|
||||
self.connection.send(message)
|
||||
|
||||
res = self._wait_for_respose()
|
||||
return messages.parse(res)
|
||||
|
Loading…
Reference in New Issue
Block a user