[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-79]

Message.add() can take many args
a bit of cleanup to Message:  add() can now take any number of params, and
will add them all in order (using type guessing).
This commit is contained in:
Robey Pointer 2004-09-11 20:35:19 +00:00
parent caa1f88105
commit 026425c117
1 changed files with 11 additions and 10 deletions

View File

@ -59,7 +59,7 @@ class Message (object):
@rtype: string @rtype: string
""" """
return 'Message(' + repr(self.packet) + ')' return 'paramiko.Message(' + repr(self.packet) + ')'
def get_remainder(self): def get_remainder(self):
""" """
@ -116,10 +116,7 @@ class Message (object):
@rtype: bool @rtype: bool
""" """
b = self.get_bytes(1) b = self.get_bytes(1)
if b == '\x00': return b != '\x00'
return False
else:
return True
def get_int(self): def get_int(self):
""" """
@ -233,19 +230,23 @@ class Message (object):
self.packet = self.packet + out self.packet = self.packet + out
return self return self
def add(self, i): def _add(self, i):
if type(i) == types.StringType: if type(i) is str:
return self.add_string(i) return self.add_string(i)
elif type(i) == types.IntType: elif type(i) is int:
return self.add_int(i) return self.add_int(i)
elif type(i) == types.LongType: elif type(i) is long:
if i > 0xffffffffL: if i > 0xffffffffL:
return self.add_mpint(i) return self.add_mpint(i)
else: else:
return self.add_int(i) return self.add_int(i)
elif type(i) is bool: elif type(i) is bool:
return self.add_boolean(i) return self.add_boolean(i)
elif type(i) == types.ListType: elif type(i) is list:
return self.add_list(i) return self.add_list(i)
else: else:
raise exception('Unknown type') raise exception('Unknown type')
def add(self, *seq):
for item in seq:
self._add(item)