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,
|
self._ssl = self._context.wrap_socket(self._tcp,
|
||||||
server_hostname=self.host)
|
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):
|
def login(self):
|
||||||
"""login()
|
"""login()
|
||||||
|
|
||||||
@@ -95,8 +109,8 @@ Login lmw using the object creation user, password.
|
|||||||
Raises a LmwLoginFailure exception on failure
|
Raises a LmwLoginFailure exception on failure
|
||||||
"""
|
"""
|
||||||
li="LI " + self.user + "," + self.password + "\r"
|
li="LI " + self.user + "," + self.password + "\r"
|
||||||
self._ssl.sendall(li.encode('ascii'))
|
self.send(li)
|
||||||
d = self._ssl.recv()
|
d = self.recv()
|
||||||
if (d.decode('ascii')[0] != '!'):
|
if (d.decode('ascii')[0] != '!'):
|
||||||
raise LmwLoginFailure(self.user + ":" + d.decode('ascii'))
|
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
|
Raises a LmwCmdWarn of failure
|
||||||
"""
|
"""
|
||||||
ti="TI " + self.meetnet + "\r"
|
ti="TI " + self.meetnet + "\r"
|
||||||
self._ssl.sendall(ti.encode('ascii'))
|
self.send(ti)
|
||||||
d = self._ssl.recv()
|
d = self.recv()
|
||||||
if (d.decode('ascii')[0] != '!'):
|
if (d.decode('ascii')[0] != '!'):
|
||||||
raise LmwCmdWarn("TI " + self.meetnet +":" + d.decode('ascii'))
|
raise LmwCmdWarn("TI " + self.meetnet +":" + d.decode('ascii'))
|
||||||
return (d.decode('ascii')[2:-1])
|
return (d.decode('ascii')[2:-1])
|
||||||
@@ -143,8 +157,8 @@ Returns:
|
|||||||
parameter + "," + time_delta + "," + day + "," + \
|
parameter + "," + time_delta + "," + day + "," + \
|
||||||
time_of_day + data + "\r"
|
time_of_day + data + "\r"
|
||||||
|
|
||||||
self._ssl.sendall(cmdstr.encode('ascii'))
|
self.send(cmdstr)
|
||||||
d = self._ssl.recv()
|
d = self.recv()
|
||||||
if (d.decode('ascii')[0] != '!'):
|
if (d.decode('ascii')[0] != '!'):
|
||||||
raise LmwCmdWarn(d.decode('ascii'))
|
raise LmwCmdWarn(d.decode('ascii'))
|
||||||
return (d.decode('ascii')[2:-1])
|
return (d.decode('ascii')[2:-1])
|
||||||
@@ -190,7 +204,7 @@ Returns a single string value or None
|
|||||||
|
|
||||||
Logs of
|
Logs of
|
||||||
"""
|
"""
|
||||||
self._ssl.sendall(b"LO\r")
|
self.send("LO\r")
|
||||||
|
|
||||||
class LmwLoginFailure(Exception):
|
class LmwLoginFailure(Exception):
|
||||||
"""Exception from LmwSip on login failure"""
|
"""Exception from LmwSip on login failure"""
|
||||||
|
Reference in New Issue
Block a user