Exemple #1
0
# chatty3.py

"[Decorated]"

import decorators,customdec; decorators.decorated()

class C:
    def f():
        "[chattymethod2, staticmethod]"

c=C()


Exemple #2
0
# example1.py

import decorators


def do_nothing(self):
    "No magic docstring here"


dec_do_nothing = decorators.decorated(do_nothing)


def identity(x):
    "[staticmethod]"
    return x


dec_identity = decorators.decorated(identity)


def name(cls):
    "[classmethod]"
    return cls.__name__


dec_name = decorators.decorated(name)


class OldStyle:
    do_nothing = dec_do_nothing
    identity = dec_identity
Exemple #3
0
# module.py

"Magically decorated module"

import decorators,sys

thismodule=sys.modules[__name__]

class MyClass: "[Decorated]"

newmod=decorators.decorated(thismodule)


Exemple #4
0
"[Decorated]"

import decorators,customdec; decorators.decorated()

class desc(object):
    def __get__(self,obj,cls):
        print obj,cls
        
class C(object):
    def f(cls):
        "[classmethod]"
        print cls
    g=desc()


C.g
C().g
Exemple #5
0
# example2.py

from decorators import decorated
from example1 import do_nothing, identity, name


class B(object):
    "This is a regular class"


B = decorated(B)  # does nothing


class C(B):
    "[Decorated]"
    do_nothing = do_nothing
    identity = identity
    name = name


C = decorated(C)  # regenerates the class converting methods in decorators
c = C()


class D:  # old style
    "[Decorated]"

    def identity(x):
        "[staticmethod]"
        return x
Exemple #6
0
# example1.py

import decorators

def do_nothing(self):
   "No magic docstring here"
dec_do_nothing=decorators.decorated(do_nothing)

def identity(x):
    "[staticmethod]"
    return x
dec_identity=decorators.decorated(identity) 

def name(cls):
    "[classmethod]"
    return cls.__name__
dec_name=decorators.decorated(name)

class OldStyle:
    do_nothing=dec_do_nothing
    identity=dec_identity

class NewStyle(object):
    name=dec_name

o=OldStyle() # creates an old style instance
n=NewStyle() # creates a new style instance


Exemple #7
0
# chatty3.py

"[Decorated]"

import decorators, customdec
decorators.decorated()


class C:
    def f():
        "[chattymethod2, staticmethod]"


c = C()
Exemple #8
0
# module.py

"Magically decorated module"

import decorators, sys

thismodule = sys.modules[__name__]


class MyClass:
    "[Decorated]"


newmod = decorators.decorated(thismodule)
Exemple #9
0
# example2.py

from decorators import decorated
from example1 import do_nothing,identity,name

class B(object):
    "This is a regular class"

B=decorated(B) # does nothing

class C(B):
   "[Decorated]"
   do_nothing=do_nothing
   identity=identity
   name=name

C=decorated(C) # regenerates the class converting methods in decorators
c=C()



class D: # old style
    "[Decorated]"
    def identity(x):
        "[staticmethod]"
        return x

D=decorated(D)

d=D()