Feature request : give access to the environ dictionnary

Asked by Greg on 2011-10-25

Hello,

I couldn't find any way to access the environ from a ladonized method.
In particular, I wanted to access REMOTE_ADDR variable.

I fix my own copy of Ladon code to get the environ as a class constructor parameter like this :
server/dispatcher.py:96:
service_class_instance = getattr(service_module, method.sinfo.serivcename)(export_dict)

Hence, I can write code like that:
class MyService:
    def __init__(environ):
      self.environ = environ

   @ladonize(...)
   def myMethod(self, ...)
      doSomething(environ['REMOTE_ADDR'])

Well, my code will fail if the service constructor takes no parameters but is it possible to have a similar feature integrated in Ladon trunk ?

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
No assignee Edit question
Solved by:
Greg
Solved:
2011-10-25
Last query:
2011-10-25
Last reply:
2011-10-25
jsgaarde (jakob-simon-gaarde) said : #1

Hi Greg.

It's actually very easy I have just not documentated it yet - sorry :-(
All you have to do is add the kwyword-argument parameter to your service method. This tells the framework that you wish to have the request environment passed on to the method. I added an example below:

from ladon.ladonizer import ladonize

class ClientProbeService(object):

 @ladonize(rtype=str)
 def extract_remote_addr(self,**exports):
  """
  Fetch the client's remote address
  @rtype: The address
  """
  return exports['REMOTE_ADDR']

Best Regards
Jakob Simon-Gaarde

Greg (gregoire-dlg) said : #2

Great. Thanks !

It would be good if you had something like a reference documentation in addition of the website examples.

Greg.