tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

toy-example.py (888B)


      1 import pluggy
      2 
      3 
      4 hookspec = pluggy.HookspecMarker("myproject")
      5 hookimpl = pluggy.HookimplMarker("myproject")
      6 
      7 
      8 class MySpec:
      9    """A hook specification namespace."""
     10 
     11    @hookspec
     12    def myhook(self, arg1, arg2):
     13        """My special little hook that you can customize."""
     14 
     15 
     16 class Plugin_1:
     17    """A hook implementation namespace."""
     18 
     19    @hookimpl
     20    def myhook(self, arg1, arg2):
     21        print("inside Plugin_1.myhook()")
     22        return arg1 + arg2
     23 
     24 
     25 class Plugin_2:
     26    """A 2nd hook implementation namespace."""
     27 
     28    @hookimpl
     29    def myhook(self, arg1, arg2):
     30        print("inside Plugin_2.myhook()")
     31        return arg1 - arg2
     32 
     33 
     34 # create a manager and add the spec
     35 pm = pluggy.PluginManager("myproject")
     36 pm.add_hookspecs(MySpec)
     37 # register plugins
     38 pm.register(Plugin_1())
     39 pm.register(Plugin_2())
     40 # call our `myhook` hook
     41 results = pm.hook.myhook(arg1=1, arg2=2)
     42 print(results)