Esempio n. 1
0
from cython_npm.cythoncompile import require
Wallet = require('../easy_blockchain/wallet').Wallet
# from easy_blockchain.wallet import Wallet
Block = require('../easy_blockchain/blockchain').Block
BlockChain = require('../easy_blockchain/blockchain').BlockChain
# from easy_blockchain.blockchain import Block, BlockChain# Create the first user
wallet = Wallet()
user01 = wallet.getPublicKey()
user01
trans01 = wallet.create_transaction('test01', 1, 0.5, 'user01 send 1')
trans02 = trans01.copy()  # create a forgery attack
print('Check if a forgery attack have same as real transaction')
print('trans01 == trans02', trans01 == trans02)
from cython_npm.cythoncompile import require
from functools import wraps
import json
module = require('../../microservices_connector/Interservices')
Microservice = module.Microservice

# app = Flask(__name__)
Micro = Microservice(__name__, port=5010)

# run a normal function in python
print('one cat here')


# test return string
@Micro.route('/str')
@Micro.reply
def string1(a, key):
    return a + '-' + key


# test return multiple string
@Micro.route('/str2')
@Micro.reply
def string2(a, b, key):
    return a, key, b + '-' + key


# test return Integer and float
@Micro.route('/int')
@Micro.reply
def int1(a, key):
Esempio n. 3
0
# Add this line to the beginning of relative.py file
import sys, os
# sys.path.append('..')
# from cython_modules.cypm import require
# b = require('./build_example')
# b.hello.Hello()
from importlib import reload
from cython_npm.cythoncompile import require

def import_path(fullpath, recompile=False):
    """ 
    Import a file with full path specification. Allows one to
    import from anywhere, something __import__ does not do. 
    """
    path, filename = os.path.split(fullpath)
    filename, ext = os.path.splitext(filename)
    sys.path.append(path)
    module = __import__(filename)
    if recompile:
        reload(module)  # Might be out of date
    del sys.path[-1]
    return module

# here = import_path(
#     '/Users/minhtuannguyen/MyWorking/Privates/cython/cython-npm/test/here')
h = require('./')
h.hello.Hello()
h.secondapp.goodbye()
Esempio n. 4
0
import asyncio
import websockets

from cython_npm.cythoncompile import require
minisocket = require('../../microservices_connector/minisocket')

# ws = minisocket.SocketClient(host='localhost:8765',url='/hello/minhtuan')
def hello(ws):
    greeting = '?'
    while greeting != 'exit':
        name = input("What's your name? ")
        ws.send(name)
        greeting = ws.recv()
        print(f"< {greeting}")
        if name == 'exit':
            break

# hello(ws)

ws = minisocket.SocketClient(host='localhost:8765', url='/render')
ws.send('test render socket')
x = ws.recv()
# ws.send('other things')
# ws.send('other things')
ws.send(None)
print(x)
# from minisocket import SocketServer
from microservices_connector.Interservices import Microservice
import threading, time
from cython_npm.cythoncompile import require
SocketServer = require('../../microservices_connector/minisocket').SocketServer

sk = SocketServer(__name__)
app = Microservice('Flask_app').app


@app.route('/')
def helloworld():
    time.sleep(2)
    return 'Sleep 2s before response'


@sk.route('/hello/<name>')
def test(message, name):
    print(message, 'hello:' + name)
    return 'hello:' + message


@sk.route('/xinchao')
def test2(message):
    print(message, 'End:')
    return 'xinchao:' + message


@sk.render('/render')
async def test3(ws, message):
    print(message, 'received')