コード例 #1
0
ファイル: chatty3.py プロジェクト: pganti/micheles
# chatty3.py

"[Decorated]"

import decorators,customdec; decorators.decorated()

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

c=C()


コード例 #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
コード例 #3
0
ファイル: module.py プロジェクト: pganti/micheles
# module.py

"Magically decorated module"

import decorators,sys

thismodule=sys.modules[__name__]

class MyClass: "[Decorated]"

newmod=decorators.decorated(thismodule)


コード例 #4
0
ファイル: x.py プロジェクト: pganti/micheles
"[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
コード例 #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
コード例 #6
0
ファイル: example1.py プロジェクト: pganti/micheles
# 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


コード例 #7
0
# chatty3.py

"[Decorated]"

import decorators, customdec
decorators.decorated()


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


c = C()
コード例 #8
0
# module.py

"Magically decorated module"

import decorators, sys

thismodule = sys.modules[__name__]


class MyClass:
    "[Decorated]"


newmod = decorators.decorated(thismodule)
コード例 #9
0
ファイル: example2.py プロジェクト: pganti/micheles
# 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()