Page 1 of 1

Translating the following Decorator functions

Posted: Sun Mar 09, 2014 4:57 pm
by lilzz
In Python
@A
@B
def func:

would become func=A( ) (B ( ) (func) )

So the following definitions

Code: Select all

@request("GET", "*/integer")
    @response("%d")
    def portRead(self):
        return self.__portRead__()

 def __portRead__(self):
        raise NotImplementedError
    
would become request("GET", "*/integer") (response("%d") (portRead())

My question
1)is request() and response () functions? I couldn't find their function definition anywhere.
To me, seem like they are more like Http REST calls rather function. How would that relate to the template decorator function I listed above?

2)_portRead_ is nothing there except raise exception. Is that right?

Re: Translating the following Decorator functions

Posted: Tue Mar 11, 2014 10:41 pm
by paddyg
Out of context your code will not work, apart from the indentation you will get 'request' is not defined. The chances are there was an import further up with a module that contained the definitions of the decorator objects (so for your q1, they only have to be 'callable', they could be defined as classes with a __call__ method).

Those decorator objects will contain code that does something using the arguments passed to them and inserts the portRead function code somewhere inside them. Like this