# Path: tornado/log.py
# def define_logging_options(options=None):
#     if options is None:
#         # late import to prevent cycle
#         from tornado.options import options
#     options.define("logging", default="info",
#            help=("Set the Python log level. If 'none', tornado won't touch the "
#                  "logging configuration."),
#            metavar="debug|info|warning|error|none")
#     options.define("log_to_stderr", type=bool, default=None,
#            help=("Send log output to stderr (colorized if possible). "
#                  "By default use stderr if --log_file_prefix is not set and "
#                  "no other logging is configured."))
#     options.define("log_file_prefix", type=str, default=None, metavar="PATH",
#            help=("Path prefix for log files. "
#                  "Note that if you are running multiple tornado processes, "
#                  "log_file_prefix must be different for each of them (e.g. "
#                  "include the port number)"))
#     options.define("log_file_max_size", type=int, default=100 * 1000 * 1000,
#            help="max size of log files before rollover")
#     options.define("log_file_num_backups", type=int, default=10,
#            help="number of log files to keep")
# 
#     options.add_parse_callback(enable_pretty_logging)
# 
# Path: tornado/stack_context.py
# class _State(threading.local):
# class StackContext(object):
# class ExceptionStackContext(object):
# class NullContext(object):
# class _StackContextWrapper(functools.partial):
#     def __init__(self):
#     def __init__(self, context_factory, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __init__(self, exception_handler, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def wrap(fn):
#     def wrapped(*args, **kwargs):
# def _nested(*managers):


import datetime
import re
import sys
import os
import textwrap
from tornado.escape import _unicode
from tornado.log import define_logging_options
from tornado import stack_context
        by_group = {}
        for option in self._options.itervalues():
            by_group.setdefault(option.group_name, []).append(option)

        for filename, o in sorted(by_group.items()):
            if filename:
                print >> file, "\n%s options:\n" % os.path.normpath(filename)
            o.sort(key=lambda option: option.name)
            for option in o:
                prefix = option.name
                if option.metavar:
                    prefix += "=" + option.metavar
                description = option.help or ""
                if option.default is not None and option.default != '':
                    description += " (default %s)" % option.default
                lines = textwrap.wrap(description, 79 - 35)
                if len(prefix) > 30 or len(lines) == 0:
                    lines.insert(0, '')
                print >> file, "  --%-30s %s" % (prefix, lines[0])
                for line in lines[1:]:
                    print >> file, "%-34s %s" % (' ', line)
        print >> file

    def _help_callback(self, value):
        if value:
            self.print_help()
            sys.exit(0)

    def add_parse_callback(self, callback):
        """Adds a parse callback, to be invoked when option parsing is done."""

# Path: tornado/log.py
# def define_logging_options(options=None):
#     if options is None:
#         # late import to prevent cycle
#         from tornado.options import options
#     options.define("logging", default="info",
#            help=("Set the Python log level. If 'none', tornado won't touch the "
#                  "logging configuration."),
#            metavar="debug|info|warning|error|none")
#     options.define("log_to_stderr", type=bool, default=None,
#            help=("Send log output to stderr (colorized if possible). "
#                  "By default use stderr if --log_file_prefix is not set and "
#                  "no other logging is configured."))
#     options.define("log_file_prefix", type=str, default=None, metavar="PATH",
#            help=("Path prefix for log files. "
#                  "Note that if you are running multiple tornado processes, "
#                  "log_file_prefix must be different for each of them (e.g. "
#                  "include the port number)"))
#     options.define("log_file_max_size", type=int, default=100 * 1000 * 1000,
#            help="max size of log files before rollover")
#     options.define("log_file_num_backups", type=int, default=10,
#            help="number of log files to keep")
# 
#     options.add_parse_callback(enable_pretty_logging)
# 
# Path: tornado/stack_context.py
# class _State(threading.local):
# class StackContext(object):
# class ExceptionStackContext(object):
# class NullContext(object):
# class _StackContextWrapper(functools.partial):
#     def __init__(self):
#     def __init__(self, context_factory, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __init__(self, exception_handler, _active_cell=None):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def wrap(fn):
#     def wrapped(*args, **kwargs):
# def _nested(*managers):


# Path: tornado/options.py
import datetime
import re
import sys
import os
import textwrap
from tornado.escape import _unicode
from tornado.log import define_logging_options
from tornado import stack_context

        by_group = {}
        for option in self._options.itervalues():
            by_group.setdefault(option.group_name, []).append(option)

        for filename, o in sorted(by_group.items()):
            if filename:
                print >> file, "\n%s options:\n" % os.path.normpath(filename)
            o.sort(key=lambda option: option.name)
            for option in o:
                prefix = option.name
                if option.metavar:
                    prefix += "=" + option.metavar
                description = option.help or ""
                if option.default is not None and option.default != '':
                    description += " (default %s)" % option.default
                lines = textwrap.wrap(description, 79 - 35)
                if len(prefix) > 30 or len(lines) == 0:
                    lines.insert(0, '')
                print >> file, "  --%-30s %s" % (prefix, lines[0])
                for line in lines[1:]:
                    print >> file, "%-34s %s" % (' ', line)
        print >> file

    def _help_callback(self, value):
        if value:
            self.print_help()
            sys.exit(0)

    def add_parse_callback(self, callback):
        """Adds a parse callback, to be invoked when option parsing is done."""

        self._parse_callbacks.append(stack_context.wrap(callback))