Example #1
0
    def test_import():
        def some_function():
            return "hello, polyglot world!"
        polyglot.export_value(some_function)
        imported_fun0 = polyglot.import_value("some_function")
        assert imported_fun0 is some_function
        assert imported_fun0() == "hello, polyglot world!"

        polyglot.export_value("same_function", some_function)
        imported_fun1 = polyglot.import_value("same_function")
        assert imported_fun1 is some_function
        assert imported_fun1() == "hello, polyglot world!"
Example #2
0
 def test_import():
     imported_cext = polyglot.import_value("python_cext")
     import python_cext
     assert imported_cext is python_cext
Example #3
0
def main():
    log = polyglot.import_value('log')
    log.info("echo-python running")
    return polyglot.import_value('arguments')
Example #4
0
# import site
# import numpy as np
# x = np.empty([3,2], dtype = int)
# print (x)

import polyglot
print(polyglot.import_value('name') + ': Hello Python!')
x = 1
x
Example #5
0
import io
import re
import traceback
import giphypop

from polyglot import export_value, import_value
from urllib import request
from urllib.parse import urlencode


SLASH_COMMAND_RE = re.compile("/([^ ]+)")
IMG_URL_RE = re.compile(b'(<img[^>]+alt=""[^>]+>)')

r_plot = import_value('toPlot')

def transform_message(sender, msg):
    match = SLASH_COMMAND_RE.match(msg)
    if match:
        try:
            command = match.group(1)
            args = msg.split(maxsplit=1)[1]
            if command == "img":
                req = request.Request(
                    f"http://www.google.de/search?{urlencode({'tbm': 'isch', 'q': args})}",
                    headers={'User-Agent': 'Dillo/3.0.5'},
                )
                with request.urlopen(req) as resp:
                    m = IMG_URL_RE.search(resp.read())
                    if m:
                        return m.group(0).decode("utf-8")
                    else:
Example #6
0
def getOpId(name):
    func = polyglot.import_value("@getOp" + name)
    op = func()
    return op
Example #7
0
polyglot.eval(path="calc-pyext.bc", language="llvm")


def getOpId(name):
    func = polyglot.import_value("@getOp" + name)
    op = func()
    return op


op_add = getOpId("Add")
op_sub = getOpId("Sub")
op_mul = getOpId("Mul")
op_div = getOpId("Div")
op_print = getOpId("Print")

c_op = polyglot.import_value("@doOp")
c_push = polyglot.import_value("@pushNumber")
c_result = polyglot.import_value("@getResult")


def stack_entry_printer(num):
    print('->', str(num))


for operand in argv[1:]:
    if '+' == operand:
        c_op(op_add, stack_entry_printer)
    elif '-' == operand:
        c_op(op_sub, stack_entry_printer)
    elif '*' == operand:
        c_op(op_mul, stack_entry_printer)