1

I have a class defined as this:

class ClientAPi

   def __init__(self, host): 
      self.host = host

   def foo(self, foo):
      return self._foo(foo)
   @property
   def _foo(self):
     return bind_api(
            api=self,
            path='/foo',
            allowed_param=['foo'])

where bind_api is https://github.com/tweepy/tweepy/blob/master/tweepy/binder.py actually.. this is the pattern in tweepy library https://github.com/tweepy/tweepy/blob/master/tweepy/api.py

How does this works? I am unable to understand the flow.. I mean how does the variable foo is transmitted from foo() to _foo()..?

Also, now.. some of the paths for my api has changed.. instead of host:port/foo now it is host:port/v1/foo Is there a way I can annotate these methods with some decorator..such that methods which have this decorator has its path='/foo' to path=/v1/foo

So for example

class ClientAPi

   def __init__(self, host): 
      self.host = host

   def foo(self, foo):
      return self._foo(foo)

   @new_api('v1')
   @property
   def _foo(self):
     return bind_api(
            api=self,
            path='/foo',
            allowed_param=['foo'])

changes path from '/foo' to '/v1/foo'

frazman
  • 32,081
  • 75
  • 184
  • 269
  • possible duplicate of [How does the @property decorator work?](http://stackoverflow.com/questions/17330160/how-does-the-property-decorator-work) – metatoaster Jul 10 '15 at 01:59
  • I don't think your `new_api` decorator can be made to work, since it would need to somehow alter constants set inside the function's code. – celticminstrel Jul 10 '15 at 02:09
  • @metatoaster :Can any one explain to me that when I do the call self._foo(foo) in function foo.. but the _foo(self) function doesnt accepts any arguments.. how do i catch the args which I am passing from the main function to property function? – frazman Jul 10 '15 at 02:11
  • Look at the [code that you linked](https://github.com/tweepy/tweepy/blob/master/tweepy/binder.py#L238) and see that the return object is `_call` which is a function that can be called. – metatoaster Jul 10 '15 at 02:15

0 Answers0