def process_python_objects(data, filepath=None):
def _process(value):<EOL><INDENT>if isinstance(value, dict):<EOL><INDENT>for k, v in list(value.items()):<EOL><INDENT>value[k] = _process(v)<EOL><DEDENT>return value<EOL><DEDENT>elif isfunction(value):<EOL><INDENT>func = value<EOL>if hasattr(func, "<STR_LIT>"):<EOL><INDENT>import types<EOL>fn = types.FunctionType(func.__code__,<EOL>func.__globals__.copy(),<EOL>name=func.__name__,<EOL>argdefs=func.__defaults__,<EOL>closure=func.__closure__)<EOL>fn.__globals__["<STR_LIT>"] = EarlyThis(data)<EOL>fn.__globals__.update(get_objects())<EOL>spec = getargspec(func)<EOL>args = spec.args or []<EOL>if len(args) not in (<NUM_LIT:0>, <NUM_LIT:1>):<EOL><INDENT>raise ResourceError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if args:<EOL><INDENT>value_ = fn(data)<EOL><DEDENT>else:<EOL><INDENT>value_ = fn()<EOL><DEDENT>return _process(value_)<EOL><DEDENT>elif hasattr(func, "<STR_LIT>"):<EOL><INDENT>return SourceCode(func=func, filepath=filepath,<EOL>eval_as_function=True)<EOL><DEDENT>elif func.__name__ in package_rex_keys:<EOL><INDENT>return SourceCode(func=func, filepath=filepath,<EOL>eval_as_function=False)<EOL><DEDENT>else:<EOL><INDENT>return func<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return value<EOL><DEDENT><DEDENT>def _trim(value):<EOL><INDENT>if isinstance(value, dict):<EOL><INDENT>for k, v in list(value.items()):<EOL><INDENT>if isfunction(v):<EOL><INDENT>if v.__name__ == "<STR_LIT>":<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>del value[k]<EOL><DEDENT><DEDENT>elif ismodule(v) or k.startswith("<STR_LIT>"):<EOL><INDENT>del value[k]<EOL><DEDENT>else:<EOL><INDENT>value[k] = _trim(v)<EOL><DEDENT><DEDENT><DEDENT>return value<EOL><DEDENT>data = _process(data)<EOL>data = _trim(data)<EOL>return data<EOL>
Replace certain values in the given package data dict.

    Does things like:
    * evaluates @early decorated functions, and replaces with return value;
    * converts functions into `SourceCode` instances so they can be serialized
      out to installed packages, and evaluated later;
    * strips some values (modules, __-leading variables) that are never to be
      part of installed packages.

    Returns:
        dict: Updated dict.