1 # -----------------------------------------------------------------------
2 # Copyright (C) 2008 Equinox Software, Inc.
3 # Bill Erickson <erickson@esilibrary.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # -----------------------------------------------------------------------
22 from osrf.app import Application
24 class Example(Application):
25 ''' Example OpenSRF application. '''
27 # ---------------------------------------------------------
28 # Register a new method for this application
29 # ---------------------------------------------------------
30 Application.register_method(
31 api_name = 'opensrf.py-example.reverse', # published API name for the method
32 method = 'reverse', # name of def that implements this method
33 argc = 1, # expects a single argument
34 stream = True # returns a stream of results. can be called atomic-ly
37 # ---------------------------------------------------------
38 # This method implements the API call registered above
39 # ---------------------------------------------------------
40 def reverse(self, request, message=''):
41 ''' Returns the given string in reverse order one character at a time
42 @param type:string Message to reverse
43 @return type:string The reversed message, one character at a time. '''
44 idx = len(message) - 1
46 request.respond(message[idx])
49 # ---------------------------------------------------------
50 # These example methods override methods from
51 # osrf.app.Application. They are not required.
52 # ---------------------------------------------------------
53 def global_init(self):
54 osrf.log.log_debug("Running global init handler for %s" % __name__)
57 osrf.log.log_debug("Running child init handler for process %d" % os.getpid())
60 osrf.log.log_debug("Running child exit handler for process %d" % os.getpid())
63 # ---------------------------------------------------------
64 # Now register an instance of this class as an application
65 # ---------------------------------------------------------
66 Application.register_app(Example())