Ejemplo n.º 1
0
def first_evlp():
    try:
        yield sleep(1)
        yield req()
        yield launch(second)
    finally:
        eventloop.halt()
Ejemplo n.º 2
0
def first_evlp():
  try:
    yield sleep(1)
    yield req()
    yield launch(second)
  finally:
    eventloop.halt()
Ejemplo n.º 3
0
def req():
    client = HttpClient()
    try:
        resp = yield client.request('http://www.google.com/')
        print resp.code, resp.body
    finally:
        eventloop.halt()
Ejemplo n.º 4
0
 def _run_async(ctx):
     try:
         yield fn()
     except Exception:
         traceback.print_exc(file=sys.stdout)
         ctx['exit_code'] = 1
     finally:
         eventloop.halt()
Ejemplo n.º 5
0
def do_echos():
    try:
        client = Client()
        yield client.connect('localhost', 8000)
        t = time.time()
        for x in xrange(10000):
            msg = "hello, world #%s!" % x
            yield client.write(msg + '\r\n')
            echo_result = yield client.read_until("\r\n")
            assert echo_result.strip() == "you said: %s" % msg
        print '10000 loops in %.2fs' % (time.time() - t)
    finally:
        eventloop.halt()
def do_echos():
    try:
        client = Client()
        yield client.connect('localhost', 8000)
        t = time.time()
        for x in xrange(10000):
            msg = "hello, world #%s!" % x
            yield client.write(msg + '\r\n')
            echo_result = yield client.read_until("\r\n")
            assert echo_result.strip() == "you said: %s" % msg
        print '10000 loops in %.2fs' % (time.time() - t)
    finally:
        client.close()
        eventloop.halt()
Ejemplo n.º 7
0
def req():
    client = HttpClient()
    try:
        yield client.connect("www.google.com", 80)
        resp = yield client.request('/')
        print resp.code, repr(resp.body)
        resp = yield client.request('http://www.google.com/')
        print resp.code, repr(resp.body)
        client.close()
        yield client.connect("localhost", 80)
        resp = yield client.request('/')
        print resp.code, repr(resp.body)
        resp = yield client.request('http://localhost/')
        print resp.code, repr(resp.body)
    finally:
        eventloop.halt()
Ejemplo n.º 8
0
def req():
    client = HttpClient()
    try:
        yield client.connect("www.google.com", 80)
        resp = yield client.request('/')
        print resp.code, repr(resp.body)
        resp = yield client.request('http://www.google.com/')
        print resp.code, repr(resp.body)
        client.close()
        yield client.connect("localhost", 80)
        resp = yield client.request('/')
        print resp.code, repr(resp.body)
        resp = yield client.request('http://localhost/')
        print resp.code, repr(resp.body)
    finally:
        eventloop.halt()
Ejemplo n.º 9
0
def run(tests, verbose=False):
    global _fail_count

    try:
        #print tests
        results = []
        start_time = time.time()
        for test in tests:
            result = yield test(verbose)
            results.append(result)
        duration = time.time() - start_time
        print
        print "----------------------------------------------------------------------"
        print "Ran %s tests in %.3fs" % (len(tests), duration)
        print
        _fail_count = 0
        for result in results:
            if result['type'] != "SUCCESS":
                _fail_count += 1
                test = result['test']
                print "======================================================================"
                print "%s %s (%s)" % (result['type'],
                                      test.__doc__ or test.__name__,
                                      __file__)
                print "----------------------------------------------------------------------"
                print result['tb']
                if result['stdout']:
                    print "-------------------- >> begin captured stdout << ---------------------"
                    print result['stdout']
                    print "--------------------- >> end captured stdout << ----------------------"
                if result['stderr']:
                    print "-------------------- >> begin captured stderr << ---------------------"
                    print result['stderr']
                    print "--------------------- >> end captured stderr << ----------------------"
                if result['log']:
                    print "-------------------- >> begin captured log << ---------------------"
                    print result['log']
                    print "--------------------- >> end captured log << ----------------------"
        if not _fail_count:
            print "OK"
    finally:
        from monocle.stack import eventloop
        eventloop.halt()
Ejemplo n.º 10
0
def run(tests, verbose=False):
    global _fail_count

    try:
        #print tests
        results = []
        start_time = time.time()
        for test in tests:
            result = yield test(verbose)
            results.append(result)
        duration = time.time() - start_time
        print
        print "----------------------------------------------------------------------"
        print "Ran %s tests in %.3fs" % (len(tests), duration)
        print
        _fail_count = 0
        for result in results:
            if result['type'] != "SUCCESS":
                _fail_count += 1
                test = result['test']
                print "======================================================================"
                print "%s %s (%s)" % (result['type'], test.__doc__
                                      or test.__name__, __file__)
                print "----------------------------------------------------------------------"
                print result['tb']
                if result['stdout']:
                    print "-------------------- >> begin captured stdout << ---------------------"
                    print result['stdout']
                    print "--------------------- >> end captured stdout << ----------------------"
                if result['stderr']:
                    print "-------------------- >> begin captured stderr << ---------------------"
                    print result['stderr']
                    print "--------------------- >> end captured stderr << ----------------------"
                if result['log']:
                    print "-------------------- >> begin captured log << ---------------------"
                    print result['log']
                    print "--------------------- >> end captured log << ----------------------"
        if not _fail_count:
            print "OK"
    finally:
        from monocle.stack import eventloop
        eventloop.halt()
Ejemplo n.º 11
0
def send(dir, coin, to):
 try:
  receipt=Send(None, pub, epoch(), coin, loadPublic(to))
  receipt.setPrivate(priv)
  receipt.sign()

  receipts=Receipts()
  receipts.load(dir+'/receipts.dat')
  receipts.add(receipt)

  smsg=json.dumps(receipt.save(True))

  print('sending')
  client=Client()
  yield client.connect('localhost', 7050)
  yield client.write(smsg+"\n")

  s=yield client.read_until("\n")
  msg=json.loads(s)
  receipt=Receive()
  receipt.load(msg)

  if receipt.cmd!='receive':
    print('Unknown command: '+str(receipt.cmd))
    return
  if receipt.args.save_pkcs1('DER')!=pub.save_pkcs1('DER'):
    print('Not me')
    return
  if not rsa.verify(str(receipt.sig), receipt.pub):
    print('Not verified')
    return

  cs.save(dir+'/coins.dat')
  receipts.add(receipt)
  print('saving '+str(len(receipts.receipts)))
  receipts.save(dir+'/receipts.dat')

  eventloop.halt()
 except Exception, e:
  print('Exception:')
  print(e)
  traceback.print_exc()
Ejemplo n.º 12
0
def main():
    c = Client()
    """
    yield c.connect('google.com', 80)
    yield c.write("GET / HTTP/1.0\r\n\r\n")
    x = None
    c.timeout = 0
    try:
        x = yield c.read(40000)
    except Exception, e:
        print str(e)
    print x
    """
    c.timeout = 1
    yield c.connect('google.com', 80)
    yield c.write("GET / HTTP/1.0\r\n\r\n")
    c.timeout = 0
    x = yield c.read(40000)
    print(x)
    eventloop.halt()
Ejemplo n.º 13
0
 def wrapper(chan):
     r = yield target(*args, **kwargs)
     yield chan.send(r)
     eventloop.halt()
Ejemplo n.º 14
0
def print_every_two_seconds():
    for i in xrange(5):
        print "2"
        yield sleep(2)
    eventloop.halt()
Ejemplo n.º 15
0
 def wrapper(chan):
     r = yield target(*args, **kwargs)
     yield chan.send(r)
     eventloop.halt()