Exemplo n.º 1
0
def get_restricted_environment(writer, p=None):
    """
    Given the provided parser object, construct an environment dictionary.
    """
    class _print_(object):
        def write(self, s):
            writer(s)

    class _write_(object):
        def __init__(self, obj):
            object.__setattr__(self, 'obj', obj)

        def __setattr__(self, name, value):
            """
            Private attribute protection using is_frame_access_allowed()
            """
            set_protected_attribute(self.obj, name, value)

        def __setitem__(self, key, value):
            """
            Passthrough property access.
            """
            self.obj[key] = value

    safe_builtins['__import__'] = restricted_import

    for name in ['dict', 'getattr', 'hasattr']:
        safe_builtins[name] = __builtins__[name]

    env = dict(
        _apply_=lambda f, *a, **kw: f(*a, **kw),
        _print_=lambda: _print_(),
        _write_=_write_,
        _getattr_=get_protected_attribute,
        _getitem_=lambda obj, key: obj[key],
        _getiter_=lambda obj: iter(obj),
        _unpack_sequence_=guarded_unpack_sequence,
        __import__=restricted_import,
        __builtins__=safe_builtins,
    )

    from antioch import plugins
    for plugin in plugins.iterate():
        for name, func in list(plugin.get_environment().items()):
            if (hasattr(func, 'im_func')):
                func.__func__.__name__ = name
            else:
                func.__name__ = name
            api(func) if callable(func) else None

    for name, func in list(api.locals.items()):
        env[name] = func(p)

    for name in dir(errors):
        if not (name.endswith('Error')):
            continue
        cls = getattr(errors, name)
        env[name] = cls

    return env
Exemplo n.º 2
0
def get_restricted_environment(writer, p=None):
    """
    Given the provided parser object, construct an environment dictionary.
    """
    class _print_(object):
        def write(self, s):
            writer(s)
    
    class _write_(object):
        def __init__(self, obj):
            object.__setattr__(self, 'obj', obj)
        
        def __setattr__(self, name, value):
            """
            Private attribute protection using is_frame_access_allowed()
            """
            set_protected_attribute(self.obj, name, value)
        
        def __setitem__(self, key, value):
            """
            Passthrough property access.
            """
            self.obj[key] = value
    
    safe_builtins['__import__'] = restricted_import
    
    for name in ['dict', 'getattr', 'hasattr']:
        safe_builtins[name] = __builtins__[name]
    
    env = dict(
        _apply_            = lambda f,*a,**kw: f(*a, **kw),
        _print_            = lambda: _print_(),
        _write_            = _write_,
        _getattr_        = get_protected_attribute,
        _getitem_        = lambda obj, key: obj[key],
        _getiter_        = lambda obj: iter(obj),
        __import__        = restricted_import,
        __builtins__    = safe_builtins,
    )
    
    from antioch import plugins
    for plugin in plugins.iterate():
        for name, func in plugin.get_environment().items():
            if(hasattr(func, 'im_func')):
                func.im_func.func_name = name
            else:
                func.func_name = name
            api(func) if callable(func) else None
    
    for name, func in api.locals.items():
        env[name] = func(p)
    
    for name in dir(errors):
        if not(name.endswith('Error')):
            continue
        cls = getattr(errors, name)
        env[name] = cls
    
    return env
Exemplo n.º 3
0
def client(request):
    """
    Return the main client window.
    """
    return shortcuts.render_to_response('client/client.html', dict(
        title           = "antioch client",
        scripts         = [p.script_url for p in plugins.iterate() if p and p.script_url],
    ), context_instance=template.RequestContext(request))
Exemplo n.º 4
0
def client(request):
    """
    Return the main client window.
    """
    return shortcuts.render(request, 'client/client.html', dict(
        title           = "antioch client",
        scripts         = [p.script_url for p in plugins.iterate() if p and p.script_url],
    ))
Exemplo n.º 5
0
def client(request):
    """
    Return the main client window.
    """
    return shortcuts.render(
        request, 'client/client.html',
        dict(
            title="antioch client",
            scripts=[
                p.script_url for p in plugins.iterate() if p and p.script_url
            ],
        ))
Exemplo n.º 6
0
def initialize_plugins(connection):
    for plugin in plugins.iterate():
        with exchange.ObjectExchange(connection) as x:
            if not (callable(getattr(plugin, 'initialize', None))):
                continue
            plugin.initialize(x)
Exemplo n.º 7
0
def initialize_plugins(connection):
    for plugin in plugins.iterate():
        with exchange.ObjectExchange(connection) as x:
            if not(callable(getattr(plugin, 'initialize', None))): 
                continue
            plugin.initialize(x)