Esempio n. 1
0
 def write_bytes(self, s):
     n = 0
     while n < len(s):
         r = self.__sk.send(s[n:])
         if r == 0:
             raise core.NasFailedResult("connection closed by remote end")
         n += r
Esempio n. 2
0
 def read_bytes(self, length):
     ret = b''
     while len(ret) < length:
         s = self.__sk.recv(length - len(ret))
         if len(s) == 0:
             raise core.NasFailedResult("connection closed by remote end")
         ret += s
     return ret
Esempio n. 3
0
 def _exec_cmd_iter(self, cmd: Iterable) -> Generator:
     if not isinstance(cmd, (list, tuple)):
         raise TypeError
     for k, v in self.talk_iter(cmd):
         if k == '!done':
             break
         elif k == '!trap':
             raise core.NasFailedResult(v.get('=message'))
         if v:
             yield v
Esempio n. 4
0
 def _exec_cmd(self, cmd: Iterable) -> Dict:
     if not isinstance(cmd, (list, tuple)):
         raise TypeError
     r = dict()
     for k, v in self.talk_iter(cmd):
         if k == '!done':
             break
         elif k == '!trap':
             raise core.NasFailedResult(v.get('=message'))
         r[k] = v or None
     return r
Esempio n. 5
0
 def __init__(self, login: str, password: str, ip: str, port: int,
              enabled: bool, *args, **kwargs):
     if not enabled:
         raise core.NasFailedResult(_('Gateway disabled'))
     try:
         core.BaseTransmitter.__init__(
             self, login=login,
             password=password,
             ip=ip, port=port,
             *args, **kwargs
         )
         ApiRos.__init__(self, ip, port)
         self.login(username=login, pwd=password)
     except ConnectionRefusedError:
         raise core.NasNetworkError('Connection to %s is Refused' % ip)