# ex:ts=4
#
# Coolwater Medusa:
#     patch for flexible socket map service to asyncore, asynchat
#
# $LinuxKorea: cw_medusa.py,v 2.4 2001/10/29 08:55:12 perky Exp $
#

import asyncore
import asynchat
import socket

class dispatcher_mixin:
	
	def __init__(self, sock=None, map=None):
		if map is not None:
			self.map = map
		asyncore.dispatcher.__init__(self, sock, map)
	
	def add_channel (self, map=None):
		if map is None and hasattr(self, 'map'):
			map = self.map
		asyncore.dispatcher.add_channel(self, map)
	
	def del_channel (self, map=None):
		if map is None and hasattr(self, 'map'):
			map = self.map
		asyncore.dispatcher.del_channel(self, map)
		
	def create_socket (self, family, type, map=None):
		self.family_and_type = family, type
		self.socket = socket.socket (family, type)
		self.socket.setblocking(0)
		self._fileno = self.socket.fileno()
		self.add_channel(map)

class async_chat_mixin:
	
	def __init__ (self, conn=None, map=None):
		self.ac_in_buffer = ''
		self.ac_out_buffer = ''
		self.producer_fifo = asynchat.fifo()
		dispatcher_mixin.__init__ (self, conn, map)


class dispatcher(dispatcher_mixin, asyncore.dispatcher):
	pass

class async_chat(async_chat_mixin, dispatcher_mixin, asynchat.async_chat):
	pass

