Exemple #1
0
def main(serv_dict,
         exec_func,
         name='none',
         base_dir='.',
         arg_list=[],
         defaults={},
         prefork=None):

    log = coro.coroutine_logger(name)
    fmt = GreenFormatter()

    log.setLevel(logging.DEBUG)
    #
    # check for argument collisions
    #
    extra = set(map(lambda i: i.strip('='), arg_list))
    base = set(map(lambda i: i.strip('='), BASE_COMMAND_LINE_ARGS))
    both = tuple(extra & base)

    if both:
        raise AttributeError(
            'Collision between standard and extended command line arguments',
            both)

    progname = sys.argv[0]
    #
    # internal parameter defaults
    #
    max_fd = defaults.get('max_fd', SERVER_MAX_FD)
    loglevel = 'INFO'
    logdir = None
    logfile = None
    pidfile = None
    dofork = False
    linewrap = True
    #
    # setup defaults for true/false parameters
    #
    parameters = {}

    for key in filter(lambda i: not i.endswith('='), arg_list):
        parameters[key] = False

    dirname = os.path.dirname(os.path.abspath(progname))
    os.chdir(dirname)

    try:
        list, args = getopt.getopt(sys.argv[1:], [],
                                   BASE_COMMAND_LINE_ARGS + arg_list)
    except getopt.error, why:
        usage(progname, why)
        return None
Exemple #2
0
def main(
    serv_dict, exec_func,
    name = 'none', base_dir = '.', arg_list = [], defaults = {},
    prefork = None):

    log = coro.coroutine_logger(name)
    fmt = GreenFormatter()

    log.setLevel(logging.DEBUG)
    #
    # check for argument collisions
    #
    extra = set(map(lambda i: i.strip('='), arg_list))
    base  = set(map(lambda i: i.strip('='), BASE_COMMAND_LINE_ARGS))
    both  = tuple(extra & base)

    if both:
        raise AttributeError(
            'Collision between standard and extended command line arguments',
            both)

    progname = sys.argv[0]
    #
    # internal parameter defaults
    #
    max_fd   = defaults.get('max_fd', SERVER_MAX_FD)
    loglevel = 'INFO'
    logdir   = None
    logfile  = None
    pidfile  = None
    dofork   = False
    linewrap = True
    #
    # setup defaults for true/false parameters
    #
    parameters = {}

    for key in filter(lambda i: not i.endswith('='), arg_list):
        parameters[key] = False

    dirname  = os.path.dirname(os.path.abspath(progname))
    os.chdir(dirname)

    try:
        list, args = getopt.getopt(
            sys.argv[1:],
            [],
            BASE_COMMAND_LINE_ARGS + arg_list)
    except getopt.error, why:
        usage(progname, why)
        return None
Exemple #3
0
 def actually_send():
     socket = FakeSocket(bytes)
     waiter = coro.coroutine_cond()
     server = FakeServer(waiter)
     log = coro.coroutine_logger("tests")
     output = cStringIO.StringIO()
     log.addHandler(logging.StreamHandler(output))
     http = corohttpd.HttpProtocol(args=(socket, ("<fake>", 0), server, [site]), log=log)
     http.start()
     waiter.wait(0.01)
     if socket.pushed.startswith("HTTP/1.1 500"):
         output.seek(0)
         print output.read()
     result.append(socket.pushed)
 def actually_send():
     socket = FakeSocket(bytes)
     waiter = coro.coroutine_cond()
     server = FakeServer(waiter)
     log = coro.coroutine_logger('tests')
     output = cStringIO.StringIO()
     log.addHandler(logging.StreamHandler(output))
     http = corohttpd.HttpProtocol(args=(socket, ('<fake>', 0), server,
                                         [site]),
                                   log=log)
     http.start()
     waiter.wait(0.01)
     if socket.pushed.startswith('HTTP/1.1 500'):
         output.seek(0)
         print output.read()
     result.append(socket.pushed)