# Path: pyke/knowledge_engine.py
#     class chain(object):
# class CanNotProve(StandardError):
# class engine(object):
#         def __new__(cls, *args):
#         def from_iterable(i):
#     def __init__(self, *search_paths, **kws):
#     def _create_target_pkg(self, path, target_pkgs):
#     def get_ask_module(self):
#     def reset(self):
#     def get_kb(self, kb_name, _new_class = None):
#     def get_rb(self, rb_name):
#     def get_create(self, rb_name, parent = None, exclude_list = ()):
#     def get_ke(self, kb_name, entity_name):
#     def add_universal_fact(self, kb_name, fact_name, args):
#     def add_case_specific_fact(self, kb_name, fact_name, args):
#     def assert_(self, kb_name, entity_name, args):
#     def activate(self, *rb_names):
#     def lookup(self, kb_name, entity_name, pat_context, patterns):
#     def prove_goal(self, goal_str, **args):
#     def prove_1_goal(self, goal_str, **args):
#     def prove(self, kb_name, entity_name, pat_context, patterns):
#     def prove_n(self, kb_name, entity_name, fixed_args = (), num_returns = 0):
#         def gen():
#     def prove_1(self, kb_name, entity_name, fixed_args = (), num_returns = 0):
#     def print_stats(self, f = sys.stdout):
#     def trace(self, rb_name, rule_name):
#     def untrace(self, rb_name, rule_name):
# def _get_target_pkg(target_name):
# def _pythonify_path(path):
# def _is_package_dir(path):
# def in_sys_path(path):
# 
# Path: pyke/krb_traceback.py
# def print_tb(traceback, limit=None, file=None):
# def print_exception(type, value, traceback, limit=None, file=None):
# def print_exc(limit=None, file=None):
# def format_exc(limit=None):
# def print_last(limit=None, file=None):
# def print_stack(f=None, limit=None, file=None):
# def extract_tb(tb, limit=None):
# def extract_stack(f=None, limit=None):
# def format_exception(type, value, traceback, limit=None):
# def format_tb(tb, limit=None):
# def format_stack(f=None, limit=None):
# def convert_lineno(module, lineno):
# def convert_tb(extracted_tb):
# 
# Path: pyke/pattern.py
# class pattern(object):
#     def __ne__(self, b): return not (self == b)
# 
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#         return self.match_pattern(bindings, my_context, pattern_b, b_context)
# 
#     def lookup(self, context, allow_variable_in_ans = False):
#         return self
# 
# Path: pyke/contexts.py
# class simple_context(object):
# class bc_context(simple_context):
# class variable(pattern.pattern):
# class anonymous(variable):
#     def __init__(self):
#     def dump(self):
#     def bind(self, var_name, var_context, val, val_context = None):
#     def is_bound(self, var):
#     def lookup_data(self, var_name, allow_vars = False, final = None):
#     def lookup(self, var, allow_variable_in_ans = False):
#     def mark(self, save_all_undo = False):
#     def end_save_all_undo(self):
#     def undo_to_mark(self, mark, *var_names_to_undo):
#     def done(self):
#     def _unbind(self, var_name):
#     def __init__(self, rule):
#     def name(self): return self.rule.name
#     def __repr__(self):
#     def create_plan(self, final = None):
#     def __new__(cls, name):
#     def __init__(self, name):
#     def __repr__(self): return '$' + self.name
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
#     def __init__(self, name):
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):


import types
from pyke import knowledge_engine, krb_traceback, pattern, contexts
    False
    >>> is_rest_var('*$foo')
    True
    >>> is_rest_var('*$')
    False
    >>> is_rest_var('*')
    False
    >>> is_rest_var('')
    False
    '''
    return isinstance(data, types.StringTypes) and len(data) > 2 and \
           data.startswith('*$') and (data[2].isalpha() or data[2] == '_')

def as_pattern(data):
    if isinstance(data, tuple) and is_pattern(data):
        if is_rest_var(data[-1]):
            name = data[-1][2:]
            if name[0] == '_':
                rest_var = contexts.anonymous(name)
            else:
                rest_var = contexts.variable(name)
            return pattern.pattern_tuple(tuple(as_pattern(element)
                                               for element in data[:-1]),
                                         rest_var)
        return pattern.pattern_tuple(tuple(as_pattern(element)
                                           for element in data))
    if isinstance(data, types.StringTypes) and is_pattern(data):
        name = data[1:]
        if name[0] == '_': return contexts.anonymous(name)
        return contexts.variable(name)

# Path: pyke/knowledge_engine.py
#     class chain(object):
# class CanNotProve(StandardError):
# class engine(object):
#         def __new__(cls, *args):
#         def from_iterable(i):
#     def __init__(self, *search_paths, **kws):
#     def _create_target_pkg(self, path, target_pkgs):
#     def get_ask_module(self):
#     def reset(self):
#     def get_kb(self, kb_name, _new_class = None):
#     def get_rb(self, rb_name):
#     def get_create(self, rb_name, parent = None, exclude_list = ()):
#     def get_ke(self, kb_name, entity_name):
#     def add_universal_fact(self, kb_name, fact_name, args):
#     def add_case_specific_fact(self, kb_name, fact_name, args):
#     def assert_(self, kb_name, entity_name, args):
#     def activate(self, *rb_names):
#     def lookup(self, kb_name, entity_name, pat_context, patterns):
#     def prove_goal(self, goal_str, **args):
#     def prove_1_goal(self, goal_str, **args):
#     def prove(self, kb_name, entity_name, pat_context, patterns):
#     def prove_n(self, kb_name, entity_name, fixed_args = (), num_returns = 0):
#         def gen():
#     def prove_1(self, kb_name, entity_name, fixed_args = (), num_returns = 0):
#     def print_stats(self, f = sys.stdout):
#     def trace(self, rb_name, rule_name):
#     def untrace(self, rb_name, rule_name):
# def _get_target_pkg(target_name):
# def _pythonify_path(path):
# def _is_package_dir(path):
# def in_sys_path(path):
# 
# Path: pyke/krb_traceback.py
# def print_tb(traceback, limit=None, file=None):
# def print_exception(type, value, traceback, limit=None, file=None):
# def print_exc(limit=None, file=None):
# def format_exc(limit=None):
# def print_last(limit=None, file=None):
# def print_stack(f=None, limit=None, file=None):
# def extract_tb(tb, limit=None):
# def extract_stack(f=None, limit=None):
# def format_exception(type, value, traceback, limit=None):
# def format_tb(tb, limit=None):
# def format_stack(f=None, limit=None):
# def convert_lineno(module, lineno):
# def convert_tb(extracted_tb):
# 
# Path: pyke/pattern.py
# class pattern(object):
#     def __ne__(self, b): return not (self == b)
# 
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#         return self.match_pattern(bindings, my_context, pattern_b, b_context)
# 
#     def lookup(self, context, allow_variable_in_ans = False):
#         return self
# 
# Path: pyke/contexts.py
# class simple_context(object):
# class bc_context(simple_context):
# class variable(pattern.pattern):
# class anonymous(variable):
#     def __init__(self):
#     def dump(self):
#     def bind(self, var_name, var_context, val, val_context = None):
#     def is_bound(self, var):
#     def lookup_data(self, var_name, allow_vars = False, final = None):
#     def lookup(self, var, allow_variable_in_ans = False):
#     def mark(self, save_all_undo = False):
#     def end_save_all_undo(self):
#     def undo_to_mark(self, mark, *var_names_to_undo):
#     def done(self):
#     def _unbind(self, var_name):
#     def __init__(self, rule):
#     def name(self): return self.rule.name
#     def __repr__(self):
#     def create_plan(self, final = None):
#     def __new__(cls, name):
#     def __init__(self, name):
#     def __repr__(self): return '$' + self.name
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def simple_match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):
#     def __init__(self, name):
#     def lookup(self, my_context, allow_variable_in_ans = False):
#     def match_data(self, bindings, my_context, data):
#     def match_pattern(self, bindings, my_context, pattern_b, b_context):
#     def as_data(self, my_context, allow_vars = False, final = None):
#     def is_data(self, my_context):


# Path: pyke/test.py
import types
from pyke import knowledge_engine, krb_traceback, pattern, contexts

    False
    >>> is_rest_var('*$foo')
    True
    >>> is_rest_var('*$')
    False
    >>> is_rest_var('*')
    False
    >>> is_rest_var('')
    False
    '''
    return isinstance(data, types.StringTypes) and len(data) > 2 and \
           data.startswith('*$') and (data[2].isalpha() or data[2] == '_')

def as_pattern(data):
    if isinstance(data, tuple) and is_pattern(data):
        if is_rest_var(data[-1]):
            name = data[-1][2:]
            if name[0] == '_':
                rest_var = contexts.anonymous(name)
            else:
                rest_var = contexts.variable(name)
            return pattern.pattern_tuple(tuple(as_pattern(element)
                                               for element in data[:-1]),
                                         rest_var)
        return pattern.pattern_tuple(tuple(as_pattern(element)
                                           for element in data))
    if isinstance(data, types.StringTypes) and is_pattern(data):
        name = data[1:]
        if name[0] == '_': return contexts.anonymous(name)
        return contexts.variable(name)

    return pattern.pattern_literal(data)