Fix formatting of examples in blog post.
This commit is contained in:
@@ -55,6 +55,7 @@ primary pattern for this was:
|
|||||||
```
|
```
|
||||||
import wrapt
|
import wrapt
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
@wrapt.decorator
|
@wrapt.decorator
|
||||||
def universal(wrapped, instance, args, kwargs):
|
def universal(wrapped, instance, args, kwargs):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
@@ -138,6 +139,7 @@ In effect you are doing:
|
|||||||
class Example(object):
|
class Example(object):
|
||||||
def name(self):
|
def name(self):
|
||||||
return 'name'
|
return 'name'
|
||||||
|
|
||||||
Example.name = universal(Example.name)
|
Example.name = universal(Example.name)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -155,6 +157,7 @@ class Example(object):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return 'name'
|
return 'name'
|
||||||
print type(name)
|
print type(name)
|
||||||
|
|
||||||
print type(Example.name)
|
print type(Example.name)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -195,6 +198,7 @@ To add the wrapper function to a target function we now use the
|
|||||||
class Example(object):
|
class Example(object):
|
||||||
def name(self):
|
def name(self):
|
||||||
return 'name'
|
return 'name'
|
||||||
|
|
||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
wrapt.wrap_function_wrapper(Example, 'name', wrapper)
|
wrapt.wrap_function_wrapper(Example, 'name', wrapper)
|
||||||
@@ -207,6 +211,7 @@ done:
|
|||||||
import example
|
import example
|
||||||
|
|
||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
wrapt.wrap_function_wrapper(example, 'Example.name', wrapper)
|
wrapt.wrap_function_wrapper(example, 'Example.name', wrapper)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -219,6 +224,7 @@ of the module.
|
|||||||
|
|
||||||
```
|
```
|
||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
wrapt.wrap_function_wrapper('example', 'Example.name', wrapper)
|
wrapt.wrap_function_wrapper('example', 'Example.name', wrapper)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -262,6 +268,7 @@ If you come along later and have:
|
|||||||
|
|
||||||
```
|
```
|
||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
@wrapt.patch_function_wrapper('example', 'function')
|
@wrapt.patch_function_wrapper('example', 'function')
|
||||||
def wrapper(wrapped, instance, args, kwargs):
|
def wrapper(wrapped, instance, args, kwargs):
|
||||||
return wrapped(*args, **kwargs)
|
return wrapped(*args, **kwargs)
|
||||||
|
Reference in New Issue
Block a user