예제 #1
0
 def test_inside_function_call(self):
     from zope.interface.advice import getFrameInfo
     kind, module, f_locals, f_globals = getFrameInfo(sys._getframe())
     self.assertEqual(kind, "function call")
     self.assertTrue(f_locals is locals()) # ???
     for d in module.__dict__, f_globals:
         self.assertTrue(d is globals())
예제 #2
0
def _update_info(name,attr,data):
    from zope.interface.advice import getFrameInfo, addClassAdvisor
    kind, module, _locals, _globals = getFrameInfo(sys._getframe(2))

    if kind=='exec':
        # Fix for class-in-doctest-exec
        if '__module__' in _locals and _locals is not _globals:
            kind="class"

    if kind != "class":
        raise SyntaxError(
            name+"() must be called in the body of a class statement"
        )

    info = _locals.setdefault(attr,{})
    for k,v in data.items():
        if k in info:
            raise ValueError("%r defined multiple times for this class" % (k,))
        info[k] = v
예제 #3
0
class NewStyleClass:
    __metaclass__ = type
    classLevelFrameInfo = getFrameInfo(sys._getframe())
예제 #4
0
 class ClassicClass:
     __metaclass__ = ClassType
     classLevelFrameInfo = getFrameInfo(sys._getframe())
예제 #5
0
from zope.interface.advice import addClassAdvisor
from zope.interface.advice import getFrameInfo

my_globals = globals()


def ping(log, value):
    def pong(klass):
        log.append((value, klass))
        return [klass]

    addClassAdvisor(pong)


try:
    from types import ClassType

    class ClassicClass:
        __metaclass__ = ClassType
        classLevelFrameInfo = getFrameInfo(sys._getframe())
except ImportError:
    ClassicClass = None


class NewStyleClass:
    __metaclass__ = type
    classLevelFrameInfo = getFrameInfo(sys._getframe())


moduleLevelFrameInfo = getFrameInfo(sys._getframe())
예제 #6
0
##############################################################################
import sys

from zope.interface.advice import addClassAdvisor
from zope.interface.advice import getFrameInfo

my_globals = globals()

def ping(log, value):

    def pong(klass):
        log.append((value,klass))
        return [klass]

    addClassAdvisor(pong)

try:
    from types import ClassType

    class ClassicClass:
        __metaclass__ = ClassType
        classLevelFrameInfo = getFrameInfo(sys._getframe())
except ImportError:
    ClassicClass = None

class NewStyleClass:
    __metaclass__ = type
    classLevelFrameInfo = getFrameInfo(sys._getframe())

moduleLevelFrameInfo = getFrameInfo(sys._getframe())
예제 #7
0
 def checkCallInfo(self):
     kind, module, f_locals, f_globals = getFrameInfo(sys._getframe())
     self.assertEquals(kind, "function call")
     self.assert_(f_locals is locals()) # ???
     for d in module.__dict__, f_globals:
         self.assert_(d is globals())
 def checkCallInfo(self):
     kind, module, f_locals, f_globals = getFrameInfo(sys._getframe())
     self.assertEquals(kind, "function call")
     self.assert_(f_locals is locals())  # ???
     for d in module.__dict__, f_globals:
         self.assert_(d is globals())