Package Peach :: Package Generators :: Module null
[hide private]

Source Code for Module Peach.Generators.null

  1   
  2  ''' 
  3  These Generators evaluate to empty strings but are usefull for displaying status 
  4  messages and other random stuff. 
  5   
  6  @author: Michael Eddington 
  7  @version: $Id: Peach.Generators.null-pysrc.html 1138 2008-08-16 19:39:03Z meddingt $ 
  8  ''' 
  9   
 10  # 
 11  # Copyright (c) 2005 Michael Eddington 
 12  # Copyright (c) 2004-2005 IOActive Inc. 
 13  # 
 14  # Permission is hereby granted, free of charge, to any person obtaining a copy  
 15  # of this software and associated documentation files (the "Software"), to deal 
 16  # in the Software without restriction, including without limitation the rights  
 17  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 18  # copies of the Software, and to permit persons to whom the Software is  
 19  # furnished to do so, subject to the following conditions: 
 20  # 
 21  # The above copyright notice and this permission notice shall be included in     
 22  # all copies or substantial portions of the Software. 
 23  # 
 24  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 25  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 26  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
 27  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 28  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 29  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 30  # SOFTWARE. 
 31  # 
 32   
 33  # Authors: 
 34  #   Michael Eddington (mike@phed.org) 
 35   
 36  # $Id: Peach.Generators.null-pysrc.html 1138 2008-08-16 19:39:03Z meddingt $ 
 37   
 38   
 39  from Peach import generator 
 40  import sys 
 41   
 42  #__all__ = ["PrintStdout", "PrintStderr"] 
 43   
44 -class PrintStdout(generator.Generator):
45 ''' 46 Logical value of empty string, but will display a value to stdout 47 when called. Usefull for displaying status messages. 48 ''' 49 50 _msg = None 51 _generator = None 52
53 - def __init__(self, msg, generator = None):
54 ''' 55 @type msg: string 56 @param msg: Value to output 57 @type generator: Generator 58 @param generator: Generator to wrap 59 ''' 60 self._msg = msg 61 self._generator = generator
62
63 - def getRawValue(self):
64 print self._msg 65 66 if self._generator: 67 return self._generator.getRawValue() 68 69 return ''
70
71 - def next(self):
72 if self._generator: 73 self._generator.next() 74 else: 75 raise generator.GeneratorCompleted("PrintStdout")
76 77
78 -class PrintStderr(generator.Generator):
79 ''' 80 Logical value of empty string, but will display a value to stderr 81 when called. Usefull for displaying status messages. 82 ''' 83 84 _msg = None 85 _generator = None 86
87 - def __init__(self, msg, generator = None):
88 ''' 89 @type msg: string 90 @param msg: Value to output 91 @type generator: Generator 92 @param generator: Generator to wrap 93 ''' 94 self._msg = msg 95 self._generator = generator
96
97 - def getRawValue(self):
98 sys.stderr.write(self._msg + '\n') 99 100 if self._generator: 101 return self._generator.getRawValue() 102 103 return ''
104
105 - def next(self):
106 if self._generator: 107 self._generator.next() 108 else: 109 raise generator.GeneratorCompleted("PrintStderr")
110 111 112 # end 113