Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
async_chat Class Reference
Inheritance diagram for async_chat:
dispatcher SMTPChannel

Public Member Functions

def __init__
 
def set_terminator
 
def get_terminator
 
def handle_read
 
def handle_write
 
def handle_close
 
def push
 
def push_with_producer
 
def readable
 
def writable
 
def close_when_done
 
def refill_buffer
 
def initiate_send
 
def discard_buffers
 
- Public Member Functions inherited from dispatcher
def __init__
 
def __repr__
 
def add_channel
 
def del_channel
 
def create_socket
 
def set_socket
 

Data Fields

 ac_in_buffer
 
 ac_out_buffer
 
 producer_fifo
 
 terminator
 
- Data Fields inherited from dispatcher
 connected
 
 socket
 
 family_and_type
 

Static Public Attributes

int ac_in_buffer_size = 4096
 
int ac_out_buffer_size = 4096
 
- Static Public Attributes inherited from dispatcher
int debug = 0
 
int connected = 0
 
int accepting = 0
 
int closing = 0
 
 addr = None
 

Detailed Description

This is an abstract class.  You must derive from this class, and add
the two methods collect_incoming_data() and found_terminator()

Definition at line 52 of file asynchat.py.

Constructor & Destructor Documentation

def __init__ (   self,
  conn = None 
)

Definition at line 61 of file asynchat.py.

61 
62  def __init__ (self, conn=None):
63  self.ac_in_buffer = ''
64  self.ac_out_buffer = ''
65  self.producer_fifo = fifo()
66  asyncore.dispatcher.__init__ (self, conn)

Member Function Documentation

def close_when_done (   self)

Definition at line 173 of file asynchat.py.

174  def close_when_done (self):
175  "automatically close this channel once the outgoing queue is empty"
176  self.producer_fifo.push (None)
def discard_buffers (   self)

Definition at line 221 of file asynchat.py.

References async_chat.ac_in_buffer, async_chat.ac_out_buffer, and async_chat.producer_fifo.

222  def discard_buffers (self):
223  # Emergencies only!
224  self.ac_in_buffer = ''
225  self.ac_out_buffer = ''
226  while self.producer_fifo:
227  self.producer_fifo.pop()
228 
def get_terminator (   self)

Definition at line 71 of file asynchat.py.

References async_chat.terminator.

71 
72  def get_terminator (self):
73  return self.terminator
def handle_close (   self)

Definition at line 148 of file asynchat.py.

References FileWrapper.close(), StringIO.close(), Shelf.close(), Chunk.close(), _Subfile.close(), SGMLParser.close(), openrsrc.close(), URLopener.close(), _socketobject.close(), SSLFakeSocket.close(), _Hqxcoderengine.close(), SSLFakeFile.close(), FileInput.close(), TemporaryFileWrapper.close(), _fileobject.close(), _Rlecoderengine.close(), Wave_read.close(), HTTPResponse.close(), BinHex.close(), GzipFile.close(), Telnet.close(), Au_read.close(), OpenerDirector.close(), _Hqxdecoderengine.close(), DialogBox.close(), SgmlopParser.close(), Aifc_read.close(), _Rledecoderengine.close(), HTTPConnection.close(), ExpatParser.close(), BaseHandler.close(), Au_write.close(), Wave_write.close(), ZipFile.close(), HexBin.close(), TestSGMLParser.close(), file_wrapper.close(), FTP.close(), Unmarshaller.close(), SMTP.close(), ftpwrapper.close(), HTTP.close(), addbase.close(), and addclosehook.close().

149  def handle_close (self):
150  self.close()
def handle_read (   self)

Definition at line 79 of file asynchat.py.

References async_chat.ac_in_buffer, async_chat.ac_in_buffer_size, SMTPChannel.collect_incoming_data(), SMTPChannel.found_terminator(), async_chat.get_terminator(), OpenerDirector.handle_error, BaseServer.handle_error(), file_wrapper.recv(), FakeSocket.recv(), and async_chat.terminator.

79 
80  def handle_read (self):
81 
82  try:
83  data = self.recv (self.ac_in_buffer_size)
84  except socket.error, why:
85  self.handle_error()
86  return
87 
88  self.ac_in_buffer = self.ac_in_buffer + data
89 
90  # Continue to search for self.terminator in self.ac_in_buffer,
91  # while calling self.collect_incoming_data. The while loop
92  # is necessary because we might read several data+terminator
93  # combos with a single recv(1024).
94 
95  while self.ac_in_buffer:
96  lb = len(self.ac_in_buffer)
97  terminator = self.get_terminator()
98  if terminator is None:
99  # no terminator, collect it all
100  self.collect_incoming_data (self.ac_in_buffer)
101  self.ac_in_buffer = ''
102  elif type(terminator) == type(0):
103  # numeric terminator
104  n = terminator
105  if lb < n:
106  self.collect_incoming_data (self.ac_in_buffer)
107  self.ac_in_buffer = ''
108  self.terminator = self.terminator - lb
109  else:
110  self.collect_incoming_data (self.ac_in_buffer[:n])
111  self.ac_in_buffer = self.ac_in_buffer[n:]
112  self.terminator = 0
113  self.found_terminator()
114  else:
115  # 3 cases:
116  # 1) end of buffer matches terminator exactly:
117  # collect data, transition
118  # 2) end of buffer matches some prefix:
119  # collect data to the prefix
120  # 3) end of buffer does not match any prefix:
121  # collect data
122  terminator_len = len(terminator)
123  index = self.ac_in_buffer.find(terminator)
124  if index != -1:
125  # we found the terminator
126  if index > 0:
127  # don't bother reporting the empty string (source of subtle bugs)
128  self.collect_incoming_data (self.ac_in_buffer[:index])
129  self.ac_in_buffer = self.ac_in_buffer[index+terminator_len:]
130  # This does the Right Thing if the terminator is changed here.
131  self.found_terminator()
132  else:
133  # check for a prefix of the terminator
134  index = find_prefix_at_end (self.ac_in_buffer, terminator)
135  if index:
136  if index != lb:
137  # we found a prefix, collect up to the prefix
138  self.collect_incoming_data (self.ac_in_buffer[:-index])
139  self.ac_in_buffer = self.ac_in_buffer[-index:]
140  break
141  else:
142  # no prefix, collect it all
143  self.collect_incoming_data (self.ac_in_buffer)
144  self.ac_in_buffer = ''
def handle_write (   self)

Definition at line 145 of file asynchat.py.

References async_chat.initiate_send().

146  def handle_write (self):
147  self.initiate_send ()
def initiate_send (   self)

Definition at line 204 of file asynchat.py.

References async_chat.ac_out_buffer, async_chat.ac_out_buffer_size, dispatcher.connected, OpenerDirector.handle_error, BaseServer.handle_error(), async_chat.refill_buffer(), SSLFakeSocket.send(), SMTP.send(), HTTPConnection.send(), dispatcher_with_send.send(), file_wrapper.send(), FakeSocket.send(), and HTTP.send.

205  def initiate_send (self):
206  obs = self.ac_out_buffer_size
207  # try to refill the buffer
208  if (len (self.ac_out_buffer) < obs):
209  self.refill_buffer()
210 
211  if self.ac_out_buffer and self.connected:
212  # try to send the buffer
213  try:
214  num_sent = self.send (self.ac_out_buffer[:obs])
215  if num_sent:
216  self.ac_out_buffer = self.ac_out_buffer[num_sent:]
217 
218  except socket.error, why:
219  self.handle_error()
220  return
def push (   self,
  data 
)

Definition at line 151 of file asynchat.py.

References async_chat.initiate_send().

152  def push (self, data):
153  self.producer_fifo.push (simple_producer (data))
154  self.initiate_send()
def push_with_producer (   self,
  producer 
)

Definition at line 155 of file asynchat.py.

References async_chat.initiate_send().

156  def push_with_producer (self, producer):
157  self.producer_fifo.push (producer)
158  self.initiate_send()
def readable (   self)

Definition at line 159 of file asynchat.py.

References async_chat.ac_in_buffer, and async_chat.ac_in_buffer_size.

160  def readable (self):
161  "predicate for inclusion in the readable for select()"
162  return (len(self.ac_in_buffer) <= self.ac_in_buffer_size)
def refill_buffer (   self)

Definition at line 179 of file asynchat.py.

References async_chat.ac_out_buffer, FileWrapper.close(), StringIO.close(), Shelf.close(), Chunk.close(), _Subfile.close(), SGMLParser.close(), openrsrc.close(), URLopener.close(), _socketobject.close(), SSLFakeSocket.close(), _Hqxcoderengine.close(), SSLFakeFile.close(), FileInput.close(), TemporaryFileWrapper.close(), _fileobject.close(), _Rlecoderengine.close(), Wave_read.close(), HTTPResponse.close(), BinHex.close(), GzipFile.close(), Telnet.close(), Au_read.close(), OpenerDirector.close(), _Hqxdecoderengine.close(), DialogBox.close(), SgmlopParser.close(), Aifc_read.close(), _Rledecoderengine.close(), HTTPConnection.close(), ExpatParser.close(), BaseHandler.close(), Au_write.close(), Wave_write.close(), ZipFile.close(), HexBin.close(), TestSGMLParser.close(), file_wrapper.close(), FTP.close(), Unmarshaller.close(), SMTP.close(), ftpwrapper.close(), HTTP.close(), addbase.close(), addclosehook.close(), and async_chat.producer_fifo.

180  def refill_buffer (self):
181  _string_type = type('')
182  while 1:
183  if len(self.producer_fifo):
184  p = self.producer_fifo.first()
185  # a 'None' in the producer fifo is a sentinel,
186  # telling us to close the channel.
187  if p is None:
188  if not self.ac_out_buffer:
189  self.producer_fifo.pop()
190  self.close()
191  return
192  elif type(p) is _string_type:
193  self.producer_fifo.pop()
194  self.ac_out_buffer = self.ac_out_buffer + p
195  return
196  data = p.more()
197  if data:
198  self.ac_out_buffer = self.ac_out_buffer + data
199  return
200  else:
201  self.producer_fifo.pop()
202  else:
203  return
def set_terminator (   self,
  term 
)

Definition at line 67 of file asynchat.py.

67 
68  def set_terminator (self, term):
69  "Set the input delimiter. Can be a fixed string of any length, an integer, or None"
70  self.terminator = term
def writable (   self)

Definition at line 163 of file asynchat.py.

References async_chat.ac_out_buffer, and dispatcher.connected.

164  def writable (self):
165  "predicate for inclusion in the writable for select()"
166  # return len(self.ac_out_buffer) or len(self.producer_fifo) or (not self.connected)
167  # this is about twice as fast, though not as clear.
168  return not (
169  (self.ac_out_buffer == '') and
170  self.producer_fifo.is_empty() and
171  self.connected
172  )

Field Documentation

ac_in_buffer

Definition at line 62 of file asynchat.py.

int ac_in_buffer_size = 4096
static

Definition at line 58 of file asynchat.py.

ac_out_buffer

Definition at line 63 of file asynchat.py.

int ac_out_buffer_size = 4096
static

Definition at line 59 of file asynchat.py.

producer_fifo

Definition at line 64 of file asynchat.py.

terminator

Definition at line 69 of file asynchat.py.


The documentation for this class was generated from the following file: