コード例 #1
0
ファイル: function.py プロジェクト: geophile/osh
 def __init__(self, function_spec, namespace=core.__dict__):
     """Creates a Function.
     - function_spec: String specification of a function. Uses lambda notation,
       but the 'lambda' keyword is optional.
     - namespace: The default is reasonable; there's been no need to
       override it so far.
     """
     if type(function_spec) in (types.FunctionType, types.BuiltinFunctionType):
         self._function = function_spec
     else:
         self._function_spec = function_spec
         lambda_expression = self.parse(function_spec.strip())
         # Create a namespace including symbols defined by the current osh invocation.
         namespace = copy.copy(namespace)
         namespace.update(core.namespace())
         self._function = eval(lambda_expression, namespace)
コード例 #2
0
"""

import sys
import types

from args import Option
import apiparser
import core
import config
import error
import command
import command.f
from builtins import *

# Get symbols defined in .oshrc
globals().update(core.namespace())

def _import_package(package_name):
    package = globals()[package_name]
    for module_name in package.__all__:
        exec('import %s.%s' % (package_name, module_name))
        mod = getattr(package, module_name)
        for element_name in dir(mod):
            if not element_name.startswith('_'):
                element = getattr(mod, element_name)
                if type(element) is types.FunctionType:
                    globals()[element_name] = element

def create_commands(package_name, command_names):
    commands = {}
    for command_name in command_names: