コード例 #1
0
def test_service_start():
    process = pyservice.load_process(
        'tests.processes.simple_process.SimpleProcess')
    service = pyservice.Service(process)
    service.start()
    assert process <> None, process
    assert service <> None, service
コード例 #2
0
ファイル: db.py プロジェクト: jasontrigg0/python-db
def main():
    USE_SERVICE = False
    if USE_SERVICE:
        pyservice.Service('python-db',
                          daemon_main=execute_query,
                          client_receiver=lambda x: display_output(x)).run()
    else:
        out = execute_query(sys.argv)
        display_output(out)
コード例 #3
0
def service(api):
    ''' Return a service with a simple api '''
    return pyservice.Service(**api)
コード例 #4
0
 def test_run_process1(self):
     process2 = pyservice.load_process(
         'tests.processes.few_simple_process.SimpleProcess2')
     service2 = pyservice.Service(process2)
     service2.start()
コード例 #5
0
from examples import load_api, basic_wsgi
import pyservice

service = pyservice.Service(**load_api('echo/api.json'))


@service.operation("greet")
def greet(request, response, context):
    name = request.name
    city = request.city
    if not name:
        raise service.exceptions.InvalidName("Surely you have a name!")
    if not city:
        raise service.exceptions.InvalidCity(
            "Please tell me where you're from.")
    response.greeting = "Hello, {}!".format(name)
    response.question = "How's the weather in {}?".format(city)


@service.operation("echo")
def echo(request, response, context):
    response.value = request.value


# Let's add a plugin for auth.  This is an "operation" scope because we need
# access to the operation parameters.  The "request" scope is for pre/post
# plugins, that need to ensure the request has been serialized before they
# close (such as sqlalchemy)

# For now we'll only authenticate calls to the echo operation,
# with some super secret credentials