Ejemplo n.º 1
0
Archivo: ipy.py Proyecto: DawidvC/Logix
def initInteractive(ipy, baselang):
    package = __name__[:__name__.rfind(".")]
    logix = sys.modules[package]

    ipy.locals['logix'] = logix

    global _ipy
    _ipy = ipy

    logix.init()
    
    # {{{ optimisations
    if 0:
        import psyco
        import compiler
        psyco.bind(language.Language)
        psyco.bind(compiler.pycodegen, rec=10)

    if 0:
        import optimize
        import compiler
        optimize.bind_all(compiler)
        optimize.bind_all(parser)
    # }}}

    if baselang:
        ipy.locals['__currentlang__'] = logix.baselang
    else:
        mod = logix.imp('%s.std' % package, {})
        tmpstd = language.tmpLanguage(mod.std, '__main__')
        ipy.locals['__currentlang__'] = tmpstd
        ipy.locals[tmpstd.__impl__.name] = tmpstd
        logix.stdlang = mod.std

    print "(type logix.license for more information)"
    print "Welcome to Logix"
Ejemplo n.º 2
0
def initInteractive(ipy, baselang):
    package = __name__[:__name__.rfind(".")]
    logix = sys.modules[package]

    ipy.locals['logix'] = logix

    global _ipy
    _ipy = ipy

    logix.init()

    # {{{ optimisations
    if 0:
        import psyco
        import compiler
        psyco.bind(language.Language)
        psyco.bind(compiler.pycodegen, rec=10)

    if 0:
        import optimize
        import compiler
        optimize.bind_all(compiler)
        optimize.bind_all(parser)
    # }}}

    if baselang:
        ipy.locals['__currentlang__'] = logix.baselang
    else:
        mod = logix.imp('%s.std' % package, {})
        tmpstd = language.tmpLanguage(mod.std, '__main__')
        ipy.locals['__currentlang__'] = tmpstd
        ipy.locals[tmpstd.__impl__.name] = tmpstd
        logix.stdlang = mod.std

    print "(type logix.license for more information)"
    print "Welcome to Logix"
Ejemplo n.º 3
0
        _globals = self._globals
        try:
            rel_value = _pyeval(rel_value, _globals, {})
            constant = True
        except:
            constant = False

        if constant:
            def _eval_expression(var_values):
                return _abs(rel_value  - _pyeval(expression, _globals, var_values))
        else:
            def _eval_expression(var_values):
                return _abs(_pyeval(rel_value,  _globals, var_values) -
                            _pyeval(expression, _globals, var_values))

        select = self._select
        def _relative_rank(objects, var_values={}):
            return select(_eval_expression, objects, count, var_values,
                          distinct=distinct, reverse=reverse)

        return _relative_rank

    VALID_FUNCTIONS = frozenset(func for func in locals() if func[0] != '_')


VIEW_FUNCTIONS = ViewFunctions('node')

import sys
bind_all(sys.modules[__name__])
del sys, bind_all
Ejemplo n.º 4
0
        self._close_tag(u'apply')

    def _open_tag(self, name, attr=NO_ATTR):
        self.parser.startElementNS((MATHML_NAMESPACE_URI, name), name, attr)

    def _close_tag(self, name):
        self.parser.endElementNS((MATHML_NAMESPACE_URI, name), name)

    def _write_element(self, name, content=None, attr=NO_ATTR):
        parser = self.parser
        tag = (MATHML_NAMESPACE_URI, name)

        parser.startElementNS(tag, name, attr)
        if content:
            parser.characters(content)
        parser.endElementNS(tag, name)


try:
    import sys
    from optimize import bind_all
    bind_all(sys.modules[__name__])
    del sys, bind_all
except:
    pass

if __name__ == '__main__':
    import doctest
    doctest.testmod()
Ejemplo n.º 5
0
        keys = self._keys
        if not reorder:
            for key in other:
                if key not in keys:
                    keys.append(key)
        else:
            for key in other:
                if key in keys:
                    keys.remove(key)
                keys.append(key)

    def values(self):
        return [self[key] for key in self._keys]


optimize.bind_all(odict)

## # Bind the docstrings from dict to odict.
## for k, v in odict.__dict__.iteritems():
##     if k != '_keys' and hasattr(v, '__doc__') and v.__doc__ is None:
##         v.__doc__ = getattr(dict, v.__name__).__doc__

# Copyright (C) 2001-2006 Orbtech, L.L.C.
#
# Schevo
# http://schevo.org/
#
# Orbtech
# 709 East Jackson Road
# Saint Louis, MO  63119-4241
# http://orbtech.com/
Ejemplo n.º 6
0
        super(TermParsing, self).register_converter(converter_type, converter)

    def parse(self, term, input_type):
        "Convert a parse tree into a term of the given input type."
        converter = self._converters[input_type]
        return converter.parse(term)


term_parsers = TermParsing()

parser = InfixTermParser().p_arithmetic_exp()
term_parsers.register_converter('infix_bool',      InfixBoolExpressionParser().p_bool_exp())
term_parsers.register_converter('infix_term',      parser)
term_parsers.register_converter('infix_term_list', ListParser(parser).p_list())
del parser

try:
    import sys
    from optimize import bind_all
    bind_all(sys.modules[__name__])
    import pyparsing
    bind_all(pyparsing)
    del sys, bind_all
except:
    pass


if __name__ == '__main__':
    import doctest
    doctest.testmod()
Ejemplo n.º 7
0
            if isinstance(a, dict): #positional arg is dictionary
                for k in a:
                    self[k] = a[k]
            else: #positional arg is sequence of duples (k,v)
                for k, v in a:
                    self[k] = v

        for k in kwa:
            self[k] = kwa[k]


    def values(self):
        return [self[key] for key in self._keys]


optimize.bind_all(odict)


def TestPickle():
    """tests ability of odict to be pickled and unpickled 


       New-style types can provide a __getnewargs__() method that is used for protocol 2.

       Note that last phrase about requiring protocol 2.  Your
       example works if you add a third parameter to pickle.dump()
       with the value of 2.  Version 2 is not default.

    """
    import pickle
    import StringIO
Ejemplo n.º 8
0
        super(TermParsing, self).register_converter(converter_type, converter)

    def parse(self, term, input_type):
        "Convert a parse tree into a term of the given input type."
        converter = self._converters[input_type]
        return converter.parse(term)


term_parsers = TermParsing()

parser = InfixTermParser().p_arithmetic_exp()
term_parsers.register_converter('infix_bool',      InfixBoolExpressionParser().p_bool_exp())
term_parsers.register_converter('infix_term',      parser)
term_parsers.register_converter('infix_term_list', ListParser(parser).p_list())
del parser

try:
    import sys
    from optimize import bind_all
    bind_all(sys.modules[__name__])
    import pyparsing
    bind_all(pyparsing)
    del sys, bind_all
except:
    pass


if __name__ == '__main__':
    import doctest
    doctest.testmod()
Ejemplo n.º 9
0
           Don't need __getattr__ override because __getattribute__ always
           looks in instance.__dict__ as last resort if can't find in 
           class.__dict__ descriptor or elsewhere
        """
        try: #see if super class already has attribute so don't shadow
            super(Data,self).__getattribute__(key)
        except AttributeError: #super doesn't have it so put in dictionary
            if (key in self.__dict__) or REO_IdentPub.match(key): #don't do check if already there
                self.__dict__.__setitem__(key,value)
            else:
                raise AttributeError("Invalid attribute name '%s'" % key)
        else: #pass on to superclass
            super(Data,self).__setattr__(key,value)

optimize.bind_all(Data)

def resolvePath(store, ipath, ival=None, iown=None, act=None):
    """ Returns resolved Share or Node instance from path
        path may be path name of share or node
        or reference toShare or Node instance
        
        store is reference to current Store
        act is reference to associated act needed
        
        If path is a pathname string and resolves to a Share and init is not None
        Then init is used to initialize the share values. Init should be a dict of
            fields and values
            If own is True then .update(init) is used
            Otherwise .create(init) is used