示例#1
0
#!/usr/bin/env python

import barrister
import sys
import copy
import time

trans = barrister.HttpTransport("http://localhost:7667/content")
client = barrister.Client(trans)

#
# Test 1 - Try adding a page with incorrect types.  Note that server.py
#          has no type validation code.  Type enforcement is done
#          automatically by Barrister based on the IDL

invalid_add_page = [
    # use an int for authorId
    [1, "title", "body", "sports"],
    # pass a null title
    ["author-1", None, "body", "sports"],
    # pass a float for body
    ["author-1", "title", 32.3, "sports"],
    # pass a bool for category
    ["author-1", "title", "body", True],
    # pass an invalid enum value
    ["author-1", "title", "body", "op-ed"]
]

for page_data in invalid_add_page:
    try:
        client.ContentService.addPage(*page_data)
示例#2
0
#!/usr/bin/env python

import sys
import barrister
import codecs
import logging
try:
    import json
except:
    import simplejson as json

logging.basicConfig()
logging.getLogger("barrister").setLevel(logging.DEBUG)

trans = barrister.HttpTransport("http://localhost:9233/")
client = barrister.Client(trans, validate_request=False)
batch = None

f = open(sys.argv[1])
out = codecs.open(sys.argv[2], "w", "utf-8")


def get_and_log_result(iface, func, params, result, error):
    status = "ok"
    resp = result

    if error != None:
        status = "rpcerr"
        resp = error.code
        print "RPCERR: %s" % error.msg
示例#3
0
#!/usr/bin/env python

import barrister
import sys

trans = barrister.HttpTransport(sys.argv[1])
client = barrister.Client(trans)

print "1+5.1=%.1f" % client.Calculator.add(1, 5.1)
print "8-1.1=%.1f" % client.Calculator.subtract(8, 1.1)
#!/usr/bin/env python
import barrister
import urllib2
import sys

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, 'http://localhost:3000/','admin','admin')
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)

trans        = barrister.HttpTransport("http://localhost:3000/v1/todos", handlers=[auth_handler])
client       = barrister.Client(trans)

try:
  result = client.TodoManager.createTodo({ "title" : "Call Mom", "completed" : False })
  print result
except barrister.RpcException as e:
  print "err.code=%d" % e.code
示例#5
0
#!/usr/bin/env python

import barrister
import urllib2
import sys

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, 'http://localhost:7667/', 'johndoe',
                          'johnpass')
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)

trans = barrister.HttpTransport("http://localhost:7667/contact",
                                handlers=[auth_handler])
client = barrister.Client(trans)

contact = {
    "contactId": "1234",
    "username": "******",
    "firstName": "Mary",
    "lastName": "Smith"
}

contactId = client.ContactService.put(contact)
print "put contact: %s" % contactId

contact2 = client.ContactService.get(contactId)
assert contact2 == contact

deleted = client.ContactService.remove(contactId)
assert deleted == True
示例#6
0
 def __init__(self, address):
     trans = barrister.HttpTransport(address)
     self.client = barrister.Client(trans)
示例#7
0
#!/usr/bin/env python
import barrister

trans = barrister.HttpTransport("http://localhost:3000/v1/todos")
client = barrister.Client(trans)

batch = client.start_batch()
batch.TodoManager.createTodo({"title": "Call Mom", "completed": False})
batch.TodoManager.createTodo({"title": "Call Dad", "completed": False})
batch.TodoManager.createTodo({"title": "Wash car", "completed": False})
batch.TodoManager.createTodo({"title": "Eat Ham", "completed": False})

results = batch.send()
for res in results:
    # either res.error or res.result will be set
    if res.error:
        # res.error is a barrister.RpcException, so you can raise it if desired
        print "err.code=%d" % res.error.code
    else:
        # result from a successful call
        print res.result
    new_individuals = []

    for i in range(0, noIndividuals):
        chromosome = []
        onlyIndividual = sample['sample'][i]

        for j in range(0, len(onlyIndividual['chromosome'])):
            chromosome.append(onlyIndividual['chromosome'][j] + 100)
        individual = {'chromosome': chromosome}
        new_individuals.append(individual)

    return {'sample_id': sample_id, 'sample': new_individuals}


# Conexion con el Server
trans = barrister.HttpTransport("http://localhost:1818/")
client = barrister.Client(trans)

# Parametros
namePop = "popTest"

# Crear, Inicializar y Preparar la Poblracion
result = client.namePopulations.createPopulation(namePop)
print result

# Insertar la Poblacion Inicial
putSample = createPopulation(50)
putSample = json.dumps(putSample)
PutSample = client.Population.put_sample(namePop, putSample)
print PutSample
示例#9
0
#!/usr/bin/env python

import barrister

trans  = barrister.HttpTransport("http://localhost:7667/batch")
client = barrister.Client(trans)

print client.Echo.echo("hello")
try:
    client.Echo.echo("err")
except barrister.RpcException as e:
    print "err.code=%d" % e.code

batch = client.start_batch()
batch.Echo.echo("batch 0")
batch.Echo.echo("batch 1")
batch.Echo.echo("err")
batch.Echo.echo("batch 2")
batch.Echo.echo("batch 3")

results = batch.send()
for res in results:
    if res.result:
        print res.result
    else:
        # res.error is a barrister.RpcException
        # you can throw it here if desired
        print "err.code=%d" % res.error.code