Package pulp :: Package messaging :: Module decorators
[hide private]
[frames] | no frames]

Source Code for Module pulp.messaging.decorators

 1  # 
 2  # Copyright (c) 2010 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  """ 
17  Provides decorator classes & funcitons. 
18  """ 
19   
20 -class Remote:
21 """ 22 @cvar classes: A list of remoted classes. 23 @cvar methods: A list of remoted methods. 24 @cvar stubs: A dict of stubs. 25 """ 26 classes = [] 27 methods = [] 28 stubs = {}
29 30
31 -def remote(cls):
32 """ 33 Decorator used to register remotable classes. 34 @param cls: A class to register. 35 @type cls: python class. 36 """ 37 Remote.classes.append(cls) 38 return cls
39
40 -def remotemethod(fn):
41 """ 42 @param fn: A function related to an instancemethod. 43 @type fn: function 44 Decorator used to register methods that may 45 be invoked remotely. 46 """ 47 Remote.methods.append(fn) 48 return fn
49
50 -def mayinvoke(im):
51 """ 52 Get whether the specified instance method (im) 53 may be invoked remotely. 54 @param im: An instance method. 55 @type im: instancemethod 56 @return: True if exposed via @remotemethod decorator. 57 @rtype: bool 58 """ 59 return im.im_func in Remote.methods
60
61 -def stub(ns):
62 """ 63 Decorator used to register sub classes. 64 @param ns: The stub namespace. 65 @type ns: str. 66 """ 67 def decorator(cls): 68 Remote.stubs[ns] = cls 69 return cls
70 return decorator 71