本文整理匯總了Python中inspect.currentframe方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.currentframe方法的具體用法?Python inspect.currentframe怎麽用?Python inspect.currentframe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類inspect
的用法示例。
在下文中一共展示了inspect.currentframe方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_logger
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def get_logger(filename):
logging.basicConfig(filename=f"{filename}", filemode='a', format="%(message)s")
logging.warning(f"[{datetime.datetime.now()}] {'=' * 10}")
def log(message, error=True):
func = inspect.currentframe().f_back.f_code
final_msg = "(%s:%i) %s" % (
func.co_name,
func.co_firstlineno,
message
)
if error:
logging.warning(final_msg)
print(f"[ERROR] {final_msg}")
else:
print(final_msg)
return log
示例2: __advice_stack_frame_protection
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def __advice_stack_frame_protection(self, frame):
"""
Overriding of this is only permitted if and only if your name is
Megumin and you have a pet/familiar named Chomusuke.
"""
if frame is None:
logger.debug(
'currentframe() returned None; frame protection disabled')
return
f_back = frame.f_back
while f_back:
if f_back.f_code is self.handle.__code__:
raise RuntimeError(
"indirect invocation of '%s' by 'handle' is forbidden" %
frame.f_code.co_name,
)
f_back = f_back.f_back
示例3: __init__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def __init__(self, dialog_state: StatePropertyAccessor = None):
if dialog_state is None:
frame = inspect.currentframe().f_back
try:
# try to access the caller's "self"
try:
self_obj = frame.f_locals["self"]
except KeyError:
raise TypeError("DialogSet(): dialog_state cannot be None.")
# Only ComponentDialog can initialize with None dialog_state
# pylint: disable=import-outside-toplevel
from .component_dialog import ComponentDialog
if not isinstance(self_obj, ComponentDialog):
raise TypeError("DialogSet(): dialog_state cannot be None.")
finally:
# make sure to clean up the frame at the end to avoid ref cycles
del frame
self._dialog_state = dialog_state
# self.__telemetry_client = NullBotTelemetryClient.Instance;
self._dialogs: Dict[str, object] = {}
示例4: execute_only_once
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def execute_only_once():
"""
Each called in the code to this function is guaranteed to return True the
first time and False afterwards.
Returns:
bool: whether this is the first time this function gets called from this line of code.
Example:
.. code-block:: python
if execute_only_once():
# do something only once
"""
f = inspect.currentframe().f_back
ident = (f.f_code.co_filename, f.f_lineno)
if ident in _EXECUTE_HISTORY:
return False
_EXECUTE_HISTORY.add(ident)
return True
示例5: produce
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def produce(self, topic, doc, payload):
"""
Produce a new event.
:param topic: The topic of the produced event.
:param doc: The document to which the event belongs.
:param payload: The file pointer beloning to the document.
:type topic: ``str``
:type doc: ``gransk.core.Document``
:type payload: ``file``
"""
caller = inspect.currentframe().f_back.f_locals['self'].__module__
listeners = self.listeners.get(topic, [])
filename = os.path.basename(doc.path)
for listener, callback in listeners:
LOGGER.debug('[%s] %s -> %s (%s)', topic, caller, listener, filename)
callback(doc, payload)
if len(listeners) == 0:
LOGGER.debug('[%s] %s -> no listeners (%s)', topic, caller, filename)
示例6: getChannelData_Name
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_Name(self, channel):
"""Get the product name.
Retrieves the product name of the device connected to channel. The name
is returned as an ASCII string.
Args:
channel (int): The channel you are interested in
Returns:
name (string): The product name
"""
self.fn = inspect.currentframe().f_code.co_name
name = ct.create_string_buffer(80)
self.dll.canGetChannelData(channel,
canCHANNELDATA_DEVDESCR_ASCII,
ct.byref(name), ct.sizeof(name))
buf_type = ct.c_uint * 1
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CHAN_NO_ON_CARD,
ct.byref(buf), ct.sizeof(buf))
return "%s (channel %d)" % (name.value, buf[0])
示例7: getChannelData_Chan_No_On_Card
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_Chan_No_On_Card(self, channel):
"""Get the channel number on the card.
Retrieves the channel number, as numbered locally on the card, device
connected to channel.
Args:
channel (int): The channel you are interested in
Returns:
number (int): The local channel number
"""
self.fn = inspect.currentframe().f_code.co_name
number = ct.c_ulong()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CHAN_NO_ON_CARD,
ct.byref(number), ct.sizeof(number))
buf_type = ct.c_uint * 1
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CHAN_NO_ON_CARD,
ct.byref(buf), ct.sizeof(buf))
return number.value
示例8: getChannelData_CardNumber
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_CardNumber(self, channel):
"""Get the card number
Retrieves the card's number in the computer. Each card type is numbered
separately. For example, the first PCIEcan card in a machine will have
number 0, the second PCIEcan number 1, etc.
Args:
channel (int): The channel you are interested in
Returns:
card_number (int): The device's card number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_NUMBER,
ct.byref(buf), ct.sizeof(buf))
return buf.value
示例9: getChannelData_EAN_short
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_EAN_short(self, channel):
"""Get short EAN code
Retrieves the short EAN number, aka product number, for the device
connected to channel. If there is no EAN number, "00000-0" will be
returned.
Args:
channel (int): The channel you are interested in
Returns:
ean (str): The device's shortened EAN number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong * 2
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_UPC_NO,
ct.byref(buf), ct.sizeof(buf))
(ean_lo, ean_hi) = struct.unpack('LL', buf)
return "%04x-%x" % ((ean_lo >> 4) & 0xffff, ean_lo & 0xf)
示例10: getChannelData_Serial
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_Serial(self, channel):
"""Get device serial number
Retrieves the serial number for the device connected to channel. If the
device does not have a serial number, 0 is returned.
Args:
channel (int): The channel you are interested in
Returns:
serial (int): The device serial number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong * 2
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_SERIAL_NO,
ct.byref(buf), ct.sizeof(buf))
(serial_lo, serial_hi) = struct.unpack('LL', buf)
# serial_hi is always 0
return serial_lo
示例11: getChannelData_DriverName
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_DriverName(self, channel):
"""Get device driver name
Retrieves the name of the device driver (e.g. "kcany") for the device
connected to channel. The device driver names have no special meanings
and may change from a release to another.
Args:
channel (int): The channel you are interested in
Returns:
name (str): The device driver name
"""
self.fn = inspect.currentframe().f_code.co_name
name = ct.create_string_buffer(80)
self.dll.canGetChannelData(channel,
canCHANNELDATA_DRIVER_NAME,
ct.byref(name), ct.sizeof(name))
return name.value
示例12: getChannelData_Firmware
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_Firmware(self, channel):
"""Get device firmware version
Retrieves the firmvare version numbers for the device connected to
channel.
Args:
channel (int): The channel you are interested in
Returns:
major (int): The major version number
minor (int): The minor version number
build (int): The build number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ushort * 4
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_FIRMWARE_REV,
ct.byref(buf), ct.sizeof(buf))
(build, release, minor, major) = struct.unpack('HHHH', buf)
return (major, minor, build)
示例13: setBusParamsFd
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def setBusParamsFd(self, freq_brs, tseg1_brs=0, tseg2_brs=0, sjw_brs=0):
"""Set bus timing parameters for BRS in CAN FD
This function sets the bus timing parameters used in BRS (Bit rate
switch) mode for the current CANlib channel.
The library provides default values for tseg1_brs, tseg2_brs and
sjw_brs when freq is specified to one of the pre-defined constants,
canFD_BITRATE_xxx.
If freq is any other value, no default values are supplied by the
library.
Args:
freq_brs: Bitrate in bit/s.
tseg1_brs: Number of quanta from (but not including) the Sync Segment to
the sampling point.
tseg2_brs: Number of quanta from the sampling point to the end of the bit.
sjw_brs: The Synchronization Jump Width.
"""
self.canlib.fn = inspect.currentframe().f_code.co_name
self.dll.canSetBusParamsFd(self.handle, freq_brs, tseg1_brs, tseg2_brs,
sjw_brs)
示例14: getChannelData_EAN
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def getChannelData_EAN(self, channel):
"""Get EAN code
Retrieves the EAN number for the device connected to channel. If there
is no EAN number, "00-00000-00000-0" will be returned.
Args:
channel (int): The channel you are interested in
Returns:
ean (str): The device's EAN number
"""
self.fn = inspect.currentframe().f_code.co_name
buf_type = ct.c_ulong * 2
buf = buf_type()
self.dll.canGetChannelData(channel,
canCHANNELDATA_CARD_UPC_NO,
ct.byref(buf), ct.sizeof(buf))
(ean_lo, ean_hi) = struct.unpack('LL', buf)
return "%02x-%05x-%05x-%x" % (ean_hi >> 12,
((ean_hi & 0xfff) << 8) | (ean_lo >> 24),
(ean_lo >> 4) & 0xfffff, ean_lo & 0xf)
示例15: __init__
# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import currentframe [as 別名]
def __init__(self, ignore=None, maxdepth=2, maxparents=10):
self.ignore = ignore or []
self.ignore.append(inspect.currentframe().f_back)
self.maxdepth = maxdepth
self.maxparents = maxparents