# Path: chant/tornado_chant.py
# def run_async(func):
#     def async_func(*args, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def open(self):
#     def on_close(self):
#     def json_response(self, data):
#     def error_response(self, msg):
#     def on_message(self, client_data):
#     def get_current_user(self):
#     def subscribed_rooms(self, values=False):
#     def chant_authenticate(self, session_key, callback=None):
#     def chant_post(self, data, callback=None):
#     def chant_rooms(self, data, callback=None):
#     def chant_typing(self, data, callback=None):
#     def chant_history(self, data, callback=None):
#     def chant_notify(self, data, callback=None):
#     def chant_blacklist(self, data, callback=None):
#     def __init__(self):
# class DummyRequest(object):
# class ResponseDict(dict):
# class ErrorResponse(ResponseDict):
# class CommandNotAllowedResponse(ErrorResponse):
# class RateLimitExceededResponse(ErrorResponse):
# class ServerFullResponse(ErrorResponse):
# class UnauthenticatedResponse(ErrorResponse):
# class SuccessResponse(ResponseDict):
# class RoomsResponse(SuccessResponse):
# class AuthResponseAccept(SuccessResponse):
# class AuthResponseDecline(ErrorResponse):
# class MessageResponse(SuccessResponse):
# class HistoryResponse(SuccessResponse):
# class TypingResponse(SuccessResponse):
# class NotifyResponse(SuccessResponse):
# class BlacklistResponse(SuccessResponse):
# class MessagesHandler(WebSocketHandler):
# class ChantApplication(Application):


import signal
import time
import tornado.httpserver
import tornado.ioloop
from django.core.management.base import BaseCommand, CommandError
from chant.tornado_chant import application
# -*- coding: utf-8 -*-




class Command(BaseCommand):
    args = '[port_number]'
    help = 'Starts the Tornado application for message handling.'

    def sig_handler(self, sig, frame):
        """Catch signal and init callback"""
        tornado.ioloop.IOLoop.instance().add_callback(self.shutdown)

    def shutdown(self):
        """Stop server and add callback to stop i/o loop"""
        self.http_server.stop()

        io_loop = tornado.ioloop.IOLoop.instance()
        io_loop.add_timeout(time.time() + 1, io_loop.stop)

    def handle(self, *args, **options):
        if len(args) == 1:
            try:
                port = int(args[0])
            except ValueError:
                raise CommandError('Invalid port number specified')
        else:
            port = 8888


# Path: chant/tornado_chant.py
# def run_async(func):
#     def async_func(*args, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def open(self):
#     def on_close(self):
#     def json_response(self, data):
#     def error_response(self, msg):
#     def on_message(self, client_data):
#     def get_current_user(self):
#     def subscribed_rooms(self, values=False):
#     def chant_authenticate(self, session_key, callback=None):
#     def chant_post(self, data, callback=None):
#     def chant_rooms(self, data, callback=None):
#     def chant_typing(self, data, callback=None):
#     def chant_history(self, data, callback=None):
#     def chant_notify(self, data, callback=None):
#     def chant_blacklist(self, data, callback=None):
#     def __init__(self):
# class DummyRequest(object):
# class ResponseDict(dict):
# class ErrorResponse(ResponseDict):
# class CommandNotAllowedResponse(ErrorResponse):
# class RateLimitExceededResponse(ErrorResponse):
# class ServerFullResponse(ErrorResponse):
# class UnauthenticatedResponse(ErrorResponse):
# class SuccessResponse(ResponseDict):
# class RoomsResponse(SuccessResponse):
# class AuthResponseAccept(SuccessResponse):
# class AuthResponseDecline(ErrorResponse):
# class MessageResponse(SuccessResponse):
# class HistoryResponse(SuccessResponse):
# class TypingResponse(SuccessResponse):
# class NotifyResponse(SuccessResponse):
# class BlacklistResponse(SuccessResponse):
# class MessagesHandler(WebSocketHandler):
# class ChantApplication(Application):


# Path: chant/management/commands/startchant.py
import signal
import time
import tornado.httpserver
import tornado.ioloop
from django.core.management.base import BaseCommand, CommandError
from chant.tornado_chant import application

# -*- coding: utf-8 -*-




class Command(BaseCommand):
    args = '[port_number]'
    help = 'Starts the Tornado application for message handling.'

    def sig_handler(self, sig, frame):
        """Catch signal and init callback"""
        tornado.ioloop.IOLoop.instance().add_callback(self.shutdown)

    def shutdown(self):
        """Stop server and add callback to stop i/o loop"""
        self.http_server.stop()

        io_loop = tornado.ioloop.IOLoop.instance()
        io_loop.add_timeout(time.time() + 1, io_loop.stop)

    def handle(self, *args, **options):
        if len(args) == 1:
            try:
                port = int(args[0])
            except ValueError:
                raise CommandError('Invalid port number specified')
        else:
            port = 8888


        self.http_server = tornado.httpserver.HTTPServer(application)