Skip to content

Instantly share code, notes, and snippets.

@dword4
Created August 24, 2022 18:45
Show Gist options
  • Select an option

  • Save dword4/c44fcb3bb07a4e447808d0535925a2d3 to your computer and use it in GitHub Desktop.

Select an option

Save dword4/c44fcb3bb07a4e447808d0535925a2d3 to your computer and use it in GitHub Desktop.

Revisions

  1. dword4 created this gist Aug 24, 2022.
    29 changes: 29 additions & 0 deletions code.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env python3

    class command(object):
    def ratelimit(*args, **kwargs):
    limit = args[0]
    def ratelimit_wrapper(func):
    print(f"rate: {limit}")
    print("begin: ratelimit_wrapper")
    # some stuff
    print("end: ratelimit_wrapper")
    return func
    return ratelimit_wrapper


    class animals(object):

    @command.ratelimit(10)
    def cat(self):
    print("meow")

    @command.ratelimit(5)
    def dog(self):
    print("woof")
    zoo = animals()
    zoo.cat()

    zoo.dog()

    zoo.cat()
    10 changes: 10 additions & 0 deletions output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    ./dec.py
    rate: 10
    begin: ratelimit_wrapper
    end: ratelimit_wrapper
    rate: 5
    begin: ratelimit_wrapper
    end: ratelimit_wrapper
    meow
    woof
    meow