# Path: amfast/remoting/cherrypy_channel.py
# class CherryPyChannel(HttpChannel):
#     """An AMF messaging channel that can be used with CherryPy HTTP framework.
# 
#     Instantiate a CherryPyChannel object and
#     mount the __call__ method to the URL where
#     AMF messaging should be available from. 
# 
#     You can also use a WsgiChannel instance by
#     grafting it to the CherryPy tree with
#     the command cherrypy.tree.graft.
# 
#     Using WsgiChannel will be more efficient, but you
#     won't have access to any of CherryPy's built-in tools
#     such as cookie-based sessions.
# 
#     """
# 
#     @cherrypy.expose
#     @cherrypy.tools.amfhook()
#     def __call__(self):
#         try:
#             c_len = int(cherrypy.request.headers['Content-Length'])
#             raw_request = cherrypy.request.rfile.read(c_len)
#         except KeyError:
#             raw_request = cherrypy.request.rfile
# 
#         response = self.invoke(self.decode(raw_request))
#         cherrypy.response.headers['Content-Type'] = self.CONTENT_TYPE
#         return self.encode(response)
# 
# class CherryPyChannelSet(ChannelSet):
#     """A ChannelSet for use with CherryPy."""
# 
#     def __init__(self, *args, **kwargs):
#         self.clean_scheduled = False
#         ChannelSet.__init__(self, *args, **kwargs)
# 
#     def scheduleClean(self):
#         """Overridden to use CherryPy's Monitor functionality."""
#         if self.clean_scheduled is False:
#             cleaner = cp_plugins.Monitor(cherrypy.engine, self.clean, self.clean_freq)
#             cleaner.name = "ConnectionCleaner"
#             cleaner.subscribe()
#             self.clean_scheduled = True
# 
#     def mapChannel(self, channel):
#         """Overridden so that channel is added as an attribute."""
#         if hasattr(self, channel.name):
#             raise ChannelError("Reserved attribute name '%s' cannot be used as a channel name." % channel.name)
# 
#         ChannelSet.mapChannel(self, channel)
# 
#         setattr(self, channel.name, channel.__call__)


import os
import optparse
import logging
import sys
import cherrypy
import amfast
from amfast.remoting.cherrypy_channel import CherryPyChannel, CherryPyChannelSet
    handler.setLevel(logging.DEBUG)
    amfast.logger.addHandler(handler)

    cp_options = {
        'global':
        {
            'server.socket_port': int(options.port),
            'server.socket_host': str(options.domain),
        },
        '/':
        {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.join(os.getcwd(), '../flex/deploy')
        }
    }

    # Create ChannelSet
    channel_set = App(notify_connections=True)

    # Clients connect every x seconds
    # to polling channels to check for messages.
    # If messages are available, they are
    # returned to the client.
    polling_channel = CherryPyChannel('amf')
    channel_set.mapChannel(polling_channel)

    # Long-poll channels do not return
    # a response to the client until
    # a message is available, or channel.max_interval
    # is reached.

# Path: amfast/remoting/cherrypy_channel.py
# class CherryPyChannel(HttpChannel):
#     """An AMF messaging channel that can be used with CherryPy HTTP framework.
# 
#     Instantiate a CherryPyChannel object and
#     mount the __call__ method to the URL where
#     AMF messaging should be available from. 
# 
#     You can also use a WsgiChannel instance by
#     grafting it to the CherryPy tree with
#     the command cherrypy.tree.graft.
# 
#     Using WsgiChannel will be more efficient, but you
#     won't have access to any of CherryPy's built-in tools
#     such as cookie-based sessions.
# 
#     """
# 
#     @cherrypy.expose
#     @cherrypy.tools.amfhook()
#     def __call__(self):
#         try:
#             c_len = int(cherrypy.request.headers['Content-Length'])
#             raw_request = cherrypy.request.rfile.read(c_len)
#         except KeyError:
#             raw_request = cherrypy.request.rfile
# 
#         response = self.invoke(self.decode(raw_request))
#         cherrypy.response.headers['Content-Type'] = self.CONTENT_TYPE
#         return self.encode(response)
# 
# class CherryPyChannelSet(ChannelSet):
#     """A ChannelSet for use with CherryPy."""
# 
#     def __init__(self, *args, **kwargs):
#         self.clean_scheduled = False
#         ChannelSet.__init__(self, *args, **kwargs)
# 
#     def scheduleClean(self):
#         """Overridden to use CherryPy's Monitor functionality."""
#         if self.clean_scheduled is False:
#             cleaner = cp_plugins.Monitor(cherrypy.engine, self.clean, self.clean_freq)
#             cleaner.name = "ConnectionCleaner"
#             cleaner.subscribe()
#             self.clean_scheduled = True
# 
#     def mapChannel(self, channel):
#         """Overridden so that channel is added as an attribute."""
#         if hasattr(self, channel.name):
#             raise ChannelError("Reserved attribute name '%s' cannot be used as a channel name." % channel.name)
# 
#         ChannelSet.mapChannel(self, channel)
# 
#         setattr(self, channel.name, channel.__call__)


# Path: examples/messaging/python/cp_server.py
import os
import optparse
import logging
import sys
import cherrypy
import amfast
from amfast.remoting.cherrypy_channel import CherryPyChannel, CherryPyChannelSet

    handler.setLevel(logging.DEBUG)
    amfast.logger.addHandler(handler)

    cp_options = {
        'global':
        {
            'server.socket_port': int(options.port),
            'server.socket_host': str(options.domain),
        },
        '/':
        {
            'tools.staticdir.on': True,
            'tools.staticdir.dir': os.path.join(os.getcwd(), '../flex/deploy')
        }
    }

    # Create ChannelSet
    channel_set = App(notify_connections=True)

    # Clients connect every x seconds
    # to polling channels to check for messages.
    # If messages are available, they are
    # returned to the client.
    polling_channel = CherryPyChannel('amf')
    channel_set.mapChannel(polling_channel)

    # Long-poll channels do not return
    # a response to the client until
    # a message is available, or channel.max_interval
    # is reached.

    long_poll_channel = CherryPyChannel('longPoll', wait_interval=90)