1
1
import logging
2
2
from pexpect import fdpexpect , TIMEOUT , EOF
3
- from .scscp import ProcessingInstruction as PI , PI_regex , SCSCPError
3
+ from .scscp import SCSCPConnectionError , SCSCPCancel
4
+ from .processing_instruction import ProcessingInstruction as PI
4
5
5
6
class SCSCPClient ():
6
7
"""
@@ -30,7 +31,7 @@ def wrapper(self, *args, **kwds):
30
31
def _get_next_PI (self , expect = None , timeout = - 1 ):
31
32
while True :
32
33
try :
33
- self .stream .expect (PI_regex , timeout = timeout )
34
+ self .stream .expect (PI . PI_regex , timeout = timeout )
34
35
except TIMEOUT :
35
36
self .quit ()
36
37
raise TimeoutError ("Server took to long to respond." )
@@ -39,20 +40,20 @@ def _get_next_PI(self, expect=None, timeout=-1):
39
40
40
41
try :
41
42
pi = PI .parse (self .stream .after )
42
- except SCSCPError :
43
+ except SCSCPConnectionError :
43
44
self .quit ()
44
45
raise
45
46
self .log .debug ("Received PI: %s" % pi )
46
47
47
48
if expect is not None and pi .key not in expect :
48
49
if pi .key == 'quit' :
49
50
self .quit ()
50
- raise SCSCPError ("Server closed session (reason: %s)." % pi .attrs .get ('reason' ))
51
+ raise SCSCPConnectionError ("Server closed session (reason: %s)." % pi .attrs .get ('reason' ), pi )
51
52
if pi .key == 'info' :
52
53
self .log .info ("SCSCP info: %s " % pi .attrs .get ('info' ))
53
54
continue
54
55
else :
55
- raise SCSCPError ("Server sent unexpected message: %s" % pi .key )
56
+ raise SCSCPConnectionError ("Server sent unexpected message: %s" % pi .key , pi )
56
57
else :
57
58
return pi
58
59
@@ -70,7 +71,7 @@ def connect(self):
70
71
if ('scscp_versions' not in pi .attrs
71
72
or b'1.3' not in pi .attrs ['scscp_versions' ].split ()):
72
73
self .quit ()
73
- raise SCSCPError ("Unsupported SCSCP versions %s." % pi .attrs .get ('scscp_versions' ))
74
+ raise SCSCPConnectionError ("Unsupported SCSCP versions %s." % pi .attrs .get ('scscp_versions' ), pi )
74
75
75
76
self .service_info = pi .attrs
76
77
@@ -79,7 +80,7 @@ def connect(self):
79
80
pi = self ._get_next_PI (['' ])
80
81
if pi .attrs .get ('version' ) != b'1.3' :
81
82
self .quit ()
82
- raise SCSCPError ("Server sent unexpected response." )
83
+ raise SCSCPConnectionError ("Server sent unexpected response." , pi )
83
84
84
85
self .status = self .CONNECTED
85
86
@@ -103,7 +104,7 @@ def receive(self, timeout=-1):
103
104
while True :
104
105
pi = self ._get_next_PI (['end' , 'cancel' , 'info' ], timeout = timeout )
105
106
if pi .key == 'cancel' :
106
- raise SCSCPCancel ()
107
+ raise SCSCPCancel ('Server canceled transmission' )
107
108
108
109
msg += self .stream .before
109
110
if pi .key == 'info' :
@@ -132,4 +133,3 @@ def info(self, info):
132
133
def terminate (self , id ):
133
134
""" Send SCSCP terminate message """
134
135
self ._send_PI ('terminate' , call_id = id )
135
-
0 commit comments