Get a namespace (revealed or ready) and optionally its history.
    Only return an expired namespace if asked.
    If current_block is None, any namespace is returned (expired or not)
    If current_block is not None and only_revealed is False, then a namespace can be returned before it was revealed.
    -- if include_expired is False, then a namespace can be returned only if current_block is less than the expire block
    -- otherwise, any namespace can be returned

def namedb_get_namespace( cur, namespace_id, current_block, include_expired=False, include_history=True, only_revealed=True):
    """
    Get a namespace (revealed or ready) and optionally its history.
    Only return an expired namespace if asked.
    If current_block is None, any namespace is returned (expired or not)
    If current_block is not None and only_revealed is False, then a namespace can be returned before it was revealed.
    -- if include_expired is False, then a namespace can be returned only if current_block is less than the expire block
    -- otherwise, any namespace can be returned
    """

    include_expired_query = ""
    include_expired_args = ()

    min_age_query = ""
    min_age_args = ()

    if only_revealed:
        # requier lower bound on age
        min_age_query = " AND namespaces.reveal_block <= ?"
        min_age_args = (current_block,)

    if not include_expired:
        assert current_block is not None
        # require upper bound on age
        include_expired_query = " AND ? < namespaces.reveal_block + ?"
        include_expired_args = (current_block, NAMESPACE_REVEAL_EXPIRE)

    if current_block is None:
        # no bounds on age
        min_age_query = ""
        min_age_args = ()

    select_query = "SELECT * FROM namespaces WHERE namespace_id = ? AND " + \
                   "((op = ?) OR (op = ? %s %s))" % (min_age_query, include_expired_query)

    args = (namespace_id, NAMESPACE_READY, NAMESPACE_REVEAL) + min_age_args + include_expired_args

    log.debug(namedb_format_query(select_query, args))

    namespace_rows = namedb_query_execute( cur, select_query, args )

    namespace_row = namespace_rows.fetchone()
    if namespace_row is None:
        # no such namespace 
        return None 

    namespace = {}
    namespace.update( namespace_row )

    if include_history:
        hist = namedb_get_history( cur, namespace_id )
        namespace['history'] = hist

    namespace = op_decanonicalize(op_get_opcode_name(namespace['op']), namespace)
    return namespace