Refactor: losse send and recv functie
This commit is contained in:
28
lmwsip.py
28
lmwsip.py
@@ -88,6 +88,20 @@ connects to lmw with tcp using the values of the object creation.
|
||||
self._ssl = self._context.wrap_socket(self._tcp,
|
||||
server_hostname=self.host)
|
||||
|
||||
def send(self, sipcmd):
|
||||
"""send(sipcmd)
|
||||
|
||||
send a sip command to the server
|
||||
"""
|
||||
self._ssl.sendall(sipcmd.encode('ascii'))
|
||||
|
||||
def recv(self):
|
||||
"""recv()
|
||||
|
||||
recieve a answer from the sip server
|
||||
"""
|
||||
return(self._ssl.recv())
|
||||
|
||||
def login(self):
|
||||
"""login()
|
||||
|
||||
@@ -95,8 +109,8 @@ Login lmw using the object creation user, password.
|
||||
Raises a LmwLoginFailure exception on failure
|
||||
"""
|
||||
li="LI " + self.user + "," + self.password + "\r"
|
||||
self._ssl.sendall(li.encode('ascii'))
|
||||
d = self._ssl.recv()
|
||||
self.send(li)
|
||||
d = self.recv()
|
||||
if (d.decode('ascii')[0] != '!'):
|
||||
raise LmwLoginFailure(self.user + ":" + d.decode('ascii'))
|
||||
|
||||
@@ -108,8 +122,8 @@ Request the time from lmw and returns the string.
|
||||
Raises a LmwCmdWarn of failure
|
||||
"""
|
||||
ti="TI " + self.meetnet + "\r"
|
||||
self._ssl.sendall(ti.encode('ascii'))
|
||||
d = self._ssl.recv()
|
||||
self.send(ti)
|
||||
d = self.recv()
|
||||
if (d.decode('ascii')[0] != '!'):
|
||||
raise LmwCmdWarn("TI " + self.meetnet +":" + d.decode('ascii'))
|
||||
return (d.decode('ascii')[2:-1])
|
||||
@@ -143,8 +157,8 @@ Returns:
|
||||
parameter + "," + time_delta + "," + day + "," + \
|
||||
time_of_day + data + "\r"
|
||||
|
||||
self._ssl.sendall(cmdstr.encode('ascii'))
|
||||
d = self._ssl.recv()
|
||||
self.send(cmdstr)
|
||||
d = self.recv()
|
||||
if (d.decode('ascii')[0] != '!'):
|
||||
raise LmwCmdWarn(d.decode('ascii'))
|
||||
return (d.decode('ascii')[2:-1])
|
||||
@@ -190,7 +204,7 @@ Returns a single string value or None
|
||||
|
||||
Logs of
|
||||
"""
|
||||
self._ssl.sendall(b"LO\r")
|
||||
self.send("LO\r")
|
||||
|
||||
class LmwLoginFailure(Exception):
|
||||
"""Exception from LmwSip on login failure"""
|
||||
|
Reference in New Issue
Block a user