Package Peach :: Module publisher
[hide private]

Source Code for Module Peach.publisher

  1   
  2  ''' 
  3  Base Publisher object implementation. 
  4   
  5  @author: Michael Eddington 
  6  @version: $Id: Peach.publisher-pysrc.html 1138 2008-08-16 19:39:03Z meddingt $ 
  7  ''' 
  8   
  9  # 
 10  # Copyright (c) 2005-2008 Michael Eddington 
 11  # Copyright (c) 2004-2005 IOActive Inc. 
 12  # 
 13  # Permission is hereby granted, free of charge, to any person obtaining a copy  
 14  # of this software and associated documentation files (the "Software"), to deal 
 15  # in the Software without restriction, including without limitation the rights  
 16  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 17  # copies of the Software, and to permit persons to whom the Software is  
 18  # furnished to do so, subject to the following conditions: 
 19  # 
 20  # The above copyright notice and this permission notice shall be included in     
 21  # all copies or substantial portions of the Software. 
 22  # 
 23  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 24  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 25  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
 26  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 27  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 28  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 29  # SOFTWARE. 
 30  # 
 31   
 32  # Authors: 
 33  #   Michael Eddington (mike@phed.org) 
 34   
 35  # $Id: Peach.publisher-pysrc.html 1138 2008-08-16 19:39:03Z meddingt $ 
 36   
37 -class Publisher:
38 ''' 39 The Publisher object(s) implement a way to send and/or receave 40 data by some means. This could be a TCP connection, a filehandle, or 41 SQL, etc. 42 43 There are two "types" of publishers, stream based and call based. This 44 base class supports both types. 45 46 To support stream based publishing implement everything but "call". 47 48 To support call based publishing implement start, stop, and call. 49 50 Note: A publisher can support both stream and call based publishing. 51 ''' 52
53 - def start(self):
54 ''' 55 Change state such that send/receave will work. For Tcp this 56 could be connecting to a remote host 57 ''' 58 pass
59
60 - def stop(self):
61 ''' 62 Change state such that send/receave will not work. For Tcp this 63 could be closing a connection, for a file it might be closing the 64 file handle. 65 ''' 66 pass
67
68 - def send(self, data):
69 ''' 70 Publish some data 71 72 @type data: string 73 @param data: Data to publish 74 ''' 75 raise PeachException("Action 'send' not supported by publisher")
76
77 - def receive(self, size = None):
78 ''' 79 Receive some data. 80 81 @type size: integer 82 @param size: Number of bytes to return 83 @rtype: string 84 @return: data received 85 ''' 86 raise PeachException("Action 'receive' not supported by publisher")
87
88 - def call(self, method, args):
89 ''' 90 Call a method using arguments. 91 92 @type method: string 93 @param method: Method to call 94 @type args: Array 95 @param args: Array of strings as arguments 96 @rtype: string 97 @return: data returned (if any) 98 ''' 99 raise PeachException("Action 'call' not supported by publisher")
100
101 - def property(self, property, value = None):
102 ''' 103 Get or set property 104 105 @type property: string 106 @param property: Name of method to invoke 107 @type value: object 108 @param value: Value to set. If None, return property instead 109 ''' 110 raise PeachException("Action 'property' not supported by publisher")
111
112 - def accept(self):
113 ''' 114 Accept incoming connection. Blocks until incoming connection 115 occurs. 116 ''' 117 118 raise PeachException("Action 'accept' not supported by publisher")
119
120 - def close(self):
121 ''' 122 Close current stream/connection. 123 ''' 124 raise PeachException("Action 'close' not supported by publisher")
125 126
127 -class PublisherStartError(Exception):
128 ''' 129 Exception thrown if error occurs during start call 130 ''' 131 pass
132
133 -class PublisherStopError(Exception):
134 ''' 135 Exception thrown if error occurs during stop call 136 ''' 137 pass
138 139 from Peach.Engine.common import * 140
141 -class PublisherSoftException(SoftException):
142 ''' 143 Recoverable exception occured in the Publisher. 144 ''' 145 pass
146
147 -class Timeout(SoftException):
148 - def __init__(self, msg):
149 self.msg = msg
150
151 - def __str__(self):
152 return self.msg
153 154 # end 155