@@ -4720,6 +4720,8 @@ def __init__(self, svc: iService, spb: bytes, host: str):
4720
4720
self .spb : bytes = spb
4721
4721
#: Server host
4722
4722
self .host : str = host
4723
+ #: Service output mode (line or eof)
4724
+ self .mode : SrvInfoCode = SrvInfoCode .TO_EOF
4723
4725
#: Response buffer used to comunicate with service
4724
4726
self .response : CBuffer = CBuffer (USHRT_MAX )
4725
4727
self ._eof : bool = False
@@ -4778,13 +4780,19 @@ def _fetch_line(self, timeout: int=-1) -> Optional[str]:
4778
4780
def _read_output (self , * , init : str = '' , timeout : int = - 1 ) -> None :
4779
4781
assert self ._svc is not None
4780
4782
self .response .clear ()
4781
- self ._svc .query (self ._make_request (timeout ), bytes ([SrvInfoCode . TO_EOF ]), self .response .raw )
4783
+ self ._svc .query (self ._make_request (timeout ), bytes ([self . mode ]), self .response .raw )
4782
4784
tag = self .response .get_tag ()
4783
- if tag != SrvInfoCode . TO_EOF : # pragma: no cover
4785
+ if tag != self . mode : # pragma: no cover
4784
4786
raise InterfaceError (f"Service responded with error code: { tag } " )
4785
- init += self .response .read_sized_string ()
4787
+ data = self .response .read_sized_string ()
4788
+ init += data
4789
+ if data and self .mode is SrvInfoCode .LINE :
4790
+ init += '\n '
4786
4791
self .__line_buffer = init .splitlines (keepends = True )
4787
- self ._eof = self .response .get_tag () == isc_info_end
4792
+ if self .mode is SrvInfoCode .TO_EOF :
4793
+ self ._eof = self .response .get_tag () == isc_info_end
4794
+ else :
4795
+ self ._eof = not data
4788
4796
def _read_all_binary_output (self , * , timeout : int = - 1 ) -> bytes :
4789
4797
assert self ._svc is not None
4790
4798
send = self ._make_request (timeout )
@@ -4793,8 +4801,7 @@ def _read_all_binary_output(self, *, timeout: int=-1) -> bytes:
4793
4801
while not eof :
4794
4802
self .response .clear ()
4795
4803
self ._svc .query (send , bytes ([SrvInfoCode .TO_EOF ]), self .response .raw )
4796
- tag = self .response .get_tag ()
4797
- if tag != SrvInfoCode .TO_EOF : # pragma: no cover
4804
+ if (tag := self .response .get_tag ()) != SrvInfoCode .TO_EOF : # pragma: no cover
4798
4805
raise InterfaceError (f"Service responded with error code: { tag } " )
4799
4806
result .append (self .response .read_bytes ())
4800
4807
eof = self .response .get_tag () == isc_info_end
@@ -4806,12 +4813,10 @@ def _read_next_binary_output(self, *, timeout: int=-1) -> bytes:
4806
4813
send = self ._make_request (timeout )
4807
4814
self .response .clear ()
4808
4815
self ._svc .query (send , bytes ([SrvInfoCode .TO_EOF ]), self .response .raw )
4809
- tag = self .response .get_tag ()
4810
- if tag != SrvInfoCode .TO_EOF : # pragma: no cover
4816
+ if (tag := self .response .get_tag ()) != SrvInfoCode .TO_EOF : # pragma: no cover
4811
4817
raise InterfaceError (f"Service responded with error code: { tag } " )
4812
4818
result = self .response .read_bytes ()
4813
- tag = self .response .get_tag ()
4814
- self ._eof = tag == isc_info_end
4819
+ self ._eof = self .response .get_tag () == isc_info_end
4815
4820
return result
4816
4821
def is_running (self ) -> bool :
4817
4822
"""Returns True if service is running.
0 commit comments