1212from scan .commands .command import Command
1313from scan .util .xml_helper import indent
1414
15- class CommandSequence (object ):
15+ class CommandSequence (list ):
1616 """A sequence of scan commands
1717
1818 Basically a list of commands,
@@ -22,19 +22,16 @@ class CommandSequence(object):
2222 :param commands: One or more commands, or existing list of commands.
2323 """
2424 def __init__ (self , * commands ):
25- self .commands = []
26- for command in commands :
27- # Append individual command
28- if isinstance (command , Command ):
29- self .commands .append (command )
30- else :
31- # Assume iterable tuple, list, set, .. and append its content
32- self .commands += list (command )
25+ super (CommandSequence , self ).__init__ ()
26+ self .append (* commands )
3327
34- def __len__ (self ):
35- """:return: Number of commands"""
36- return len (self .commands )
37-
28+ def __iadd__ (self , other ):
29+ if isinstance (other , list ):
30+ self .append (* other )
31+ else :
32+ self .append (other )
33+ return self
34+
3835 def append (self , * commands ):
3936 """Append more commands to the sequence
4037
@@ -43,15 +40,15 @@ def append(self, *commands):
4340 for command in commands :
4441 # Append individual command
4542 if isinstance (command , Command ):
46- self . commands .append (command )
43+ super ( CommandSequence , self ) .append (command )
4744 else :
4845 # Assume iterable tuple, list, set, .. and append its content
49- self .commands += list (command )
46+ self .append ( list (command ) )
5047
5148 def genSCN (self ):
5249 """:return: Command in XML format suitable for scan server"""
5350 scn = ET .Element ('commands' )
54- for c in self . commands :
51+ for c in self :
5552 scn .append (c .genXML ())
5653
5754 indent (scn )
@@ -72,11 +69,11 @@ def format(self):
7269 ]
7370
7471 """
75- if len (self . commands ) == 0 :
72+ if len (self ) == 0 :
7673 return "[]"
7774
7875 result = "["
79- for cmd in self . commands :
76+ for cmd in self :
8077 result += "\n " + cmd .format (1 )
8178 result += "\n ]"
8279 return result
@@ -85,7 +82,7 @@ def __str__(self):
8582 return self .format ()
8683
8784 def __repr__ (self ):
88- return "CommandSequence(" + str (self . commands ) + ")"
85+ return "CommandSequence(" + str (self ) + ")"
8986
9087
9188if __name__ == "__main__" :
0 commit comments