1 / 15

AspectJ-style advice for Python functions

AspectJ-style advice for Python functions. Zhenkuang He Tolga Cerrah. Overview. Motivation/Goals Advised functions/Pointcuts Advice Exceptions Demo Future Work. Motivation/Goals. To use the functionality of the decorators to make Python look more like AspectJ.

goldy
Download Presentation

AspectJ-style advice for Python functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AspectJ-style advice for Python functions Zhenkuang He Tolga Cerrah

  2. Overview • Motivation/Goals • Advised functions/Pointcuts • Advice • Exceptions • Demo • Future Work

  3. Motivation/Goals To use the functionality of the decoratorsto make Python look more like AspectJ. The main goal is to come up with a way to implement pointcuts and advices in Python to make it similar to AspectJ.

  4. Advised functions • @Aspect() • Setup the function path dictionary • pathDict{} # Function's name : Actual function • @Aspect( “PointCut_Name” ) • If there is given a pointcut name, setup the point cut dictionary • pointcutDict{} # PointCut name : Functions in PointCut

  5. Pointcuts • @Pointcut(“..”,”..”, ...) • Parameters can be function names • Parameters can be PointCut names @Pointcut(“a”,”b”) @Pointcut(“pc1”,”Dec”,”a”)

  6. Pointcuts • If there is a pointcut, get all the advised functions of that pointcut • If not, just get the advised functions • Initialize/Update the pointcut dictionary

  7. Advice • @After( “..”,”..”, … ) • AfterDict{} • @Before( “..”,”..”, … ) • BeforeDict{} • @Around( “..” ) • AroundDict{} • __call__ @Aspect • Proceed()

  8. @After • AfterDict{} ( BeforeDict{}, AroundDict{} ) • Key: Function to be advised • Value: set of advised functions • If there is a pointcut, get all the advised functions of that pointcut. • If not, just get the advised functions

  9. @After • Setup the function path dictionary of advice function • Update the "After" advice dictionary • Every step is the same for @Before and @Around except this step

  10. __call__ @Aspect • Check the "Before" advice, • If we do have, run those before the function • Check the "Around" advice • If we do have, run it instead the function • Store the advised function and its arguments • If we do not have, just run the original function • Check the "After" advice • If we do have, run those after the function

  11. Proceed() • If no argument is given, run the advised function with its own arguments • If not, run it with the given arguments

  12. Exceptions • Advice Error • raised when the function decorated with @Before, @After or @Around doesn’t advice any other function • Aspect Error • raised when a function being advised hasn’t beenannotated with @Aspect or defined

  13. Demo • Test case 1, 2, 3, 4, 5

  14. Future Work Functions themselves can be passed as parameters instead of just their name string. More exceptions can be covered such as one that checks if Proceed() is called inside a function decorated with @Around.

  15. Questions?

More Related