Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/venusian/advice.py : 83%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1##############################################################################
2#
3# Copyright (c) 2003 Zope Corporation and Contributors.
4# All Rights Reserved.
5#
6# This software is subject to the provisions of the Zope Public License,
7# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11# FOR A PARTICULAR PURPOSE.
12#
13##############################################################################
14"""Class advice.
16This module was adapted from 'protocols.advice', part of the Python
17Enterprise Application Kit (PEAK). Please notify the PEAK authors
18(pje@telecommunity.com and tsarna@sarna.org) if bugs are found or
19Zope-specific changes are required, so that the PEAK version of this module
20can be kept in sync.
22PEAK is a Python application framework that interoperates with (but does
23not require) Zope 3 and Twisted. It provides tools for manipulating UML
24models, object-relational persistence, aspect-oriented programming, and more.
25Visit the PEAK home page at http://peak.telecommunity.com for more information.
27$Id: advice.py 25177 2004-06-02 13:17:31Z jim $
28"""
30import inspect
31import sys
34def getFrameInfo(frame):
35 """Return (kind,module,locals,globals) for a frame
37 'kind' is one of "exec", "module", "class", "function call", or "unknown".
38 """
40 f_locals = frame.f_locals
41 f_globals = frame.f_globals
43 sameNamespace = f_locals is f_globals
44 hasModule = "__module__" in f_locals
45 hasName = "__name__" in f_globals
47 sameName = hasModule and hasName
48 sameName = sameName and f_globals["__name__"] == f_locals["__module__"]
50 module = hasName and sys.modules.get(f_globals["__name__"]) or None
52 namespaceIsModule = module and module.__dict__ is f_globals
54 frameinfo = inspect.getframeinfo(frame)
55 try:
56 sourceline = frameinfo[3][0].strip()
57 except: # pragma NO COVER
58 # dont understand circumstance here, 3rdparty code without comment
59 sourceline = frameinfo[3]
61 codeinfo = frameinfo[0], frameinfo[1], frameinfo[2], sourceline
63 if not namespaceIsModule: # pragma no COVER
64 # some kind of funky exec
65 kind = "exec" # don't know how to repeat this scenario
66 elif sameNamespace and not hasModule:
67 kind = "module"
68 elif sameName and not sameNamespace:
69 kind = "class"
70 elif not sameNamespace:
71 kind = "function call"
72 else: # pragma NO COVER
73 # How can you have f_locals is f_globals, and have '__module__' set?
74 # This is probably module-level code, but with a '__module__' variable.
75 kind = "unknown"
76 return kind, module, f_locals, f_globals, codeinfo