def register(handler,
             op,
             safe_init      = None,
             at_start       = None,
             name           = None,
             at_stop        = None,
             static         = False,
             root           = None,
             replacement    = None,
             charset        = DEFAULT_CHARSET,
             content_type   = None,
             to_auth        = False,
             to_log         = True):
    """
    Register a command
    @handler: function to execute when the command is received
    @op: http method(s)
    @safe_init: called by the safe_init() function of this module
    @at_start: called once just before the server starts
    @at_stop: called once just before the server stops
    @name: name of the command (if not name, handler.__name__ is used)
    @static: render static file
    @root: root path
    @replacement: rewrite path when name is regexp
    @charset: charset
    @content_type: content_type
    @to_auth: use basic authentification if True
    @to_log: log request if True

    prototypes:
        handler(args)
        safe_init(options)
        at_start(options)
        at_stop()
    """
    ref_cmd = _NCMD
    is_reg  = False

    if isinstance(name, re._pattern_type):
        key         = name.pattern
        ref_cmd     = _RCMD
        is_reg      = True
    elif name:
        key         = name
        replacement = None
    else:
        key         = handler.__name__
        name        = handler.__name__
        replacement = None

    methods = []

    if not isinstance(op, (list, tuple)):
        op = [op.upper()]

    for x in op:
        x = x.upper()
        if x not in _METHODS:
            raise ValueError("unknown HTTP method: %r" % x)

        if static and x not in ('GET', 'HEAD'):
            raise ValueError("Static must be GET, HEAD command")

        methods.append(x)

    if not methods:
        raise ValueError("Missing HTTP method")

    if static and not root:
        raise ValueError("Missing root argument for static")

    cmd = Command(name,
                  handler,
                  methods,
                  safe_init,
                  at_start,
                  at_stop,
                  static,
                  root,
                  replacement,
                  charset,
                  content_type,
                  to_auth,
                  to_log)

    for method in methods:
        if not is_reg:
            mkey = "%s /%s" % (method, key)
        else:
            mkey = "%s %s" % (method, key)

        if mkey in _COMMANDS:
            raise ValueError("%s is already registred" % name)
        _COMMANDS[mkey] = cmd
        ref_cmd[mkey]   = _COMMANDS[mkey]