]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/python/osrf/apps/example.py
updated some docs
[OpenSRF.git] / src / python / osrf / apps / example.py
1 # -----------------------------------------------------------------------
2 # Copyright (C) 2008  Equinox Software, Inc.
3 # Bill Erickson <erickson@esilibrary.com>
4 #
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.
9 #
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.
14 #
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  
18 # 02110-1301, USA
19 # -----------------------------------------------------------------------
20 import os
21 import osrf.log
22 from osrf.app import Application
23
24 class Example(Application):
25     ''' Example OpenSRF application. '''
26
27     Application.register_method(
28         api_name = 'opensrf.py-example.reverse',
29         method = 'reverse',
30         argc = 1,
31         stream = True
32     )
33
34     def reverse(self, request, message=''):
35         ''' Returns the given string in reverse order one character at a time
36             @param type:string Message to reverse 
37             @return type:string The reversed message, one character at a time.  '''
38         idx = len(message) - 1
39         while idx >= 0:
40             request.respond(message[idx])
41             idx -= 1
42
43     def global_init(self):
44         osrf.log.log_debug("Running global init handler for %s" % __name__)
45
46     def child_init(self):
47         osrf.log.log_debug("Running child init handler for process %d" % os.getpid())
48
49     def child_exit(self):
50         osrf.log.log_debug("Running child exit handler for process %d" % os.getpid())
51
52 Application.register_app(Example())
53
54