Package osh :: Package command :: Module reverse
[frames] | no frames]

Source Code for Module osh.command.reverse

 1  # osh 
 2  # Copyright (C) Jack Orenstein <jao@geophile.com> 
 3  # 
 4  # This program is free software; you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published by 
 6  # the Free Software Foundation; either version 2 of the License, or 
 7  # (at your option) any later version. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with this program; if not, write to the Free Software 
16  # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
17   
18  """C{reverse} 
19   
20  Input objects are sent to the output stream in the opposite order, (last-in first-out). 
21  """ 
22   
23  import osh.function 
24  import osh.core 
25   
26  # CLI 
27 -def _reverse():
28 return _Reverse()
29 30 # API
31 -def reverse():
32 """Input objects are sent to the output stream in the opposite order, (last-in first-out). 33 """ 34 return _Reverse()
35
36 -class _Reverse(osh.core.Op):
37 38 _list = None 39 40 41 # object interface 42
43 - def __init__(self):
44 osh.core.Op.__init__(self, '', (0, 0))
45 46 47 # BaseOp interface 48
49 - def doc(self):
50 return __doc__
51
52 - def setup(self):
53 self._list = []
54
55 - def receive(self, object):
56 self._list.append(object)
57
58 - def receive_complete(self):
59 self._list.reverse() 60 for object in self._list: 61 self.send(object) 62 seld.send_complete()
63