@@ -4720,6 +4720,8 @@ def __init__(self, svc: iService, spb: bytes, host: str):
47204720 self .spb : bytes = spb
47214721 #: Server host
47224722 self .host : str = host
4723+ #: Service output mode (line or eof)
4724+ self .mode : SrvInfoCode = SrvInfoCode .TO_EOF
47234725 #: Response buffer used to comunicate with service
47244726 self .response : CBuffer = CBuffer (USHRT_MAX )
47254727 self ._eof : bool = False
@@ -4778,13 +4780,19 @@ def _fetch_line(self, timeout: int=-1) -> Optional[str]:
47784780 def _read_output (self , * , init : str = '' , timeout : int = - 1 ) -> None :
47794781 assert self ._svc is not None
47804782 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 )
47824784 tag = self .response .get_tag ()
4783- if tag != SrvInfoCode . TO_EOF : # pragma: no cover
4785+ if tag != self . mode : # pragma: no cover
47844786 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 '
47864791 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
47884796 def _read_all_binary_output (self , * , timeout : int = - 1 ) -> bytes :
47894797 assert self ._svc is not None
47904798 send = self ._make_request (timeout )
@@ -4793,8 +4801,7 @@ def _read_all_binary_output(self, *, timeout: int=-1) -> bytes:
47934801 while not eof :
47944802 self .response .clear ()
47954803 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
47984805 raise InterfaceError (f"Service responded with error code: { tag } " )
47994806 result .append (self .response .read_bytes ())
48004807 eof = self .response .get_tag () == isc_info_end
@@ -4806,12 +4813,10 @@ def _read_next_binary_output(self, *, timeout: int=-1) -> bytes:
48064813 send = self ._make_request (timeout )
48074814 self .response .clear ()
48084815 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
48114817 raise InterfaceError (f"Service responded with error code: { tag } " )
48124818 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
48154820 return result
48164821 def is_running (self ) -> bool :
48174822 """Returns True if service is running.
0 commit comments