本文整理汇总了Python中sys._getframe函数的典型用法代码示例。如果您正苦于以下问题:Python _getframe函数的具体用法?Python _getframe怎么用?Python _getframe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_getframe函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_newdevice
def update_newdevice(self,res):
'''添加新的小机到数据库'''
dbcon = QueryDB().get_dbconn()
mirco_devices = QueryDB.get_devices_table(res.vendor)
if not mirco_devices.exists(engine):
mirco_devices.create(engine)
s = sql.select([mirco_devices.c.devid]).where(mirco_devices.c.devid == res.tuid)
row = ''
try:
result = dbcon.execute(s)
row = result.fetchall()
except:
self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
ipadr = int(binascii.hexlify(socket.inet_aton(res.host[0])),16) & 0xFFFFFFFF
ipprt = res.host[1] & 0xFFFF
#print "host %d:%d" % (ipadr,ipprt)
data = ''
if res.attrs.has_key(STUN_ATTRIBUTE_DATA):
data = res.attrs[STUN_ATTRIBUTE_DATA][-1]
if not row: # 找不到这个UUID 就插入新的
ins = mirco_devices.insert().values(devid=res.tuid,is_active=True,
is_online=True,chost=[ipadr,ipprt],data=data,last_login_time=datetime.now())
try:
result = dbcon.execute(ins)
except:
self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
#print "insert new devices result fetchall"
else:
upd = mirco_devices.update().values(is_online=True,chost = [ipadr,ipprt],data=data,
last_login_time=datetime.now()).where(mirco_devices.c.devid == res.tuid)
try:
result = dbcon.execute(upd)
except:
self.errqueue.send(','.join([LOG_ERROR_DB,res.tuid,str(sys._getframe().f_lineno)]))
示例2: find_chain
def find_chain(obj, predicate, edge_func, max_depth=20, extra_ignore=()):
queue = [obj]
depth = {id(obj): 0}
parent = {id(obj): None}
ignore = set(extra_ignore)
ignore.add(id(extra_ignore))
ignore.add(id(queue))
ignore.add(id(depth))
ignore.add(id(parent))
ignore.add(id(ignore))
ignore.add(id(sys._getframe())) # this function
ignore.add(id(sys._getframe(1))) # find_chain/find_backref_chain, most likely
gc.collect()
while queue:
target = queue.pop(0)
if predicate(target):
chain = [target]
while parent[id(target)] is not None:
target = parent[id(target)]
chain.append(target)
return chain
tdepth = depth[id(target)]
if tdepth < max_depth:
referrers = edge_func(target)
ignore.add(id(referrers))
for source in referrers:
if id(source) in ignore:
continue
if id(source) not in depth:
depth[id(source)] = tdepth + 1
parent[id(source)] = target
queue.append(source)
return [obj] # not found
示例3: write_hash_manifests
def write_hash_manifests(self):
if not self.manifests_updated:
return False
today = datetime.datetime.strftime(
datetime.datetime.now(), "%Y%m%d%H%M%S")
for alg in set(self.algorithms):
manifest_path = os.path.join(self.path, 'manifest-{}.txt'.format(alg))
copy_manifest_path = os.path.join(self.path, 'manifest-{}-{}.old'.format(alg, today))
try:
shutil.copyfile(manifest_path, copy_manifest_path)
except:
LOGGER.error("Do not have permission to write new manifests")
else:
self.add_premisevent(process = "Copy Bag Manifest",
msg = "{} copied to {} before writing new manifest".format(
os.path.basename(manifest_path),
os.path.basename(copy_manifest_path)),
outcome = "Pass", sw_agent = sys._getframe().f_code.co_name)
try:
with open(manifest_path, 'w') as manifest:
for payload_file, hashes in self.entries.items():
if payload_file.startswith("data" + os.sep):
manifest.write("{} {}\n".format(hashes[alg], bagit._encode_filename(payload_file)))
except:
LOGGER.error("Do not have permission to overwrite hash manifests")
else:
LOGGER.info("{} written".format(manifest_path))
self.add_premisevent(process = "Write Bag Manifest",
msg = "{} written as a result of new or updated payload files".format(
os.path.basename(manifest_path)),
outcome = "Pass", sw_agent = sys._getframe().f_code.co_name)
return True
示例4: find_diff
def find_diff(self):
"""
Find the difference between the set from mySQL and ip network namespace.
"""
count = 0
try:
for agent in self.agents:
in_agent = [x for x in self.net_in_agent[agent] if x not in self.net_in_ns[agent]]
in_ns = [x for x in self.net_in_ns[agent] if x not in self.net_in_agent[agent]]
if len(in_agent) + len(in_ns) > 0:
print("DHCP agent in %s:" % self.agents[agent]['host'])
for net in in_agent:
if net in self.networks:
print(" %s %s is in mySQL but not in ip-netns" %
(net, self.networks[net]))
else:
print(" %s is in mySQL but not in net-list" % net)
count = count + 1
for net in in_ns:
if net in self.networks:
print(" %s %s is in ip-netns but not in mySQL" %
(net, self.networks[net]))
else:
print(" %s is in ip-netns but not in net-list" % net)
count = count + 1
except:
logger.warning("%s:%s() %d: %s %s", self.__class__.__name__,
sys._getframe().f_code.co_name, sys._getframe().f_lineno,
sys.exc_info()[0], sys.exc_info()[1])
raise
finally:
print("Found %d discrepancies in network-to-agent between mySQL and IP network namespace" % count)
示例5: __init__
def __init__(self, depth=1, moduleLevel = False, allowed_scope=None):
scope, module, f_locals, f_globals, codeinfo = \
getFrameInfo(sys._getframe(depth+1))
if allowed_scope and scope not in allowed_scope:
raise TypeError("This directive is not allowed "
"to run in this scope: %s"%scope)
if scope == 'module':
self.name = f_locals['__name__']
else:
self.name = codeinfo[2]
self.locals = f_locals
self.scope = scope
self.module = module
self.codeinfo = codeinfo
api.mods.add(self.module.__name__)
if depth > 1:
_, mod, _, _, ci = getFrameInfo(sys._getframe(2))
self.hash = (module.__name__, codeinfo[1], mod.__name__, ci[1])
else:
self.hash = (module.__name__, codeinfo[1])
示例6: stop_download
def stop_download(download_id):
log.log(__name__, sys._getframe().f_code.co_name, 'download_id %d' % download_id, log.LEVEL_DEBUG)
download_to_stop = ManageDownload.get_download_by_id(download_id)
log.log(__name__, sys._getframe().f_code.co_name, 'download to stop %s' % (download_to_stop.to_string()), log.LEVEL_DEBUG)
ManageDownload.stop_download(download_to_stop)
示例7: pl
def pl(value):
print sys._getframe().f_code.co_name
print 'value'
print type(value)
print value
print 'length: ' + str( len(value))
sys.exit('X')
示例8: send_events_local
def send_events_local():
global results
client = MongoClient()
mongodb = client[MONGODB_NAME]
start_time = time.time()
valid_events = 0
# Store raw event information
for event in results:
#entry = {}
#for key in event.keys():
# entry[key] = event[key]
# flag indicating whether this item has been processed.
# entry["processed"] = 0
event["processed"] = 0
collection = mongodb[EVENTS_COL]
# get a list of event types to keep:
# everything that starts with EVT defined in common.py
temp_list = [CONF[key] for key in CONF if key.startswith("EVT")]
events_type_list = list(chain(*temp_list))
if get_prop(event, "TYPE_EVENT") in events_type_list:
collection.insert(event)
valid_events += 1
print "=========== INCOMING EVENTS", len(results), "total,", valid_events, "valid. ============="
print sys._getframe().f_code.co_name, "COMPLETED", (time.time() - start_time), "seconds"
示例9: test_catch_unknown_pairs
def test_catch_unknown_pairs(self):
print sys._getframe().f_code.co_name
pdb_id = '3a3w'
nob_out = nbo.run(pdb_id)
expected = [pdb_id] + ['-2']*3
expected = ','.join(expected)
self.assertEqual(nob_out[:len(expected)],expected)
示例10: me_him
def me_him(self,value,color="purple"):
"""
me_him - determines current function prepends class name and displays caller function
"""
if self.output_caller:
self.color="".join(color)
self._me="".join(sys._getframe(1).f_code.co_name)
self._him="".join(sys._getframe(2).f_code.co_name)
self._me_him="".join(value)+"."+self._me+self.colors['default']+self._him+"\x1b[00m"
self._lineno=inspect.currentframe().f_back.f_lineno
if self.colors_active:
try:
if self.colors[color] and self.has_colors:
if self.show_lineno_caller:
if self.break_all:
sys.stdout.write("\n"+str(self._lineno)+": "+self.colors[self.color] + self._me_him + "\x1b[00m\n")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
sys.stdout.write(str(self._lineno)+": "+self.colors[self.color] + self._me_him + "\x1b[00m")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
if self.break_all:
sys.stdout.write("\n"+self.colors[self.color] + self._me_him + "\x1b[00m\n")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
sys.stdout.write(self.colors[self.color] + self._me_him + "\x1b[00m")
sys.stdout.write(self.colors['default']+" "+"\x1b[00m")#one space seperator
else:
sys.stdout.write(self._me_him)
except (KeyError, e):
sys.stdout.write(self._me_him)
else:
sys.stdout.write(self._me_him)
示例11: _find
def _find(self, name, type_=CausalSpace):
try:
for frame in range(0,63):
if name in sys._getframe(frame).f_locals:
if isinstance(sys._getframe(frame).f_locals[name], type_):
return sys._getframe(frame).f_locals[name]
except:pass
示例12: debug
def debug(f):
if zen_settings.get('debug'):
# sublime.log_commands(True)
frame = sys._getframe(1)
if 'debug' in frame.f_code.co_name : frame = sys._getframe(2)
line = frame.f_lineno
print 'debug:ZenCoding.%s:%s:' % (__name__, line), f
示例13: _merge_psi4_qcel_apis
def _merge_psi4_qcel_apis(args, kwargs):
"""Outer shim to allow both Psi4-style and QCA-style testing interfaces through the same function.
Notes
-----
`kwargs` modified (and returned) in-place
"""
def process_digits(digits):
if digits >= 1:
return 10**-digits
return digits
if len(args) == 0:
kwargs['label'] = sys._getframe().f_back.f_back.f_code.co_name
elif len(args) == 1:
if isinstance(args[0], str):
kwargs['label'] = args[0]
else:
kwargs['atol'] = process_digits(args[0])
kwargs['label'] = sys._getframe().f_back.f_back.f_code.co_name
if 'verbose' in kwargs:
kwargs['quiet'] = (kwargs.pop('verbose') < 1)
elif len(args) == 2:
kwargs['atol'] = process_digits(args[0])
kwargs['label'] = args[1]
if 'verbose' in kwargs:
kwargs['quiet'] = (kwargs.pop('verbose') < 1)
else:
raise ValueError("""Not following either Psi4 or QCElemental API pattern for comparison.""")
示例14: get_plugin_source
def get_plugin_source(module=None, stacklevel=None):
"""Returns the :class:`PluginSource` for the current module or the given
module. The module can be provided by name (in which case an import
will be attempted) or as a module object.
If no plugin source can be discovered, the return value from this method
is `None`.
This function can be very useful if additional data has been attached
to the plugin source. For instance this could allow plugins to get
access to a back reference to the application that created them.
:param module: optionally the module to locate the plugin source of.
:param stacklevel: defines how many levels up the module should search
for before it discovers the plugin frame. The
default is 0. This can be useful for writing wrappers
around this function.
"""
if module is None:
frm = sys._getframe((stacklevel or 0) + 1)
name = frm.f_globals['__name__']
glob = frm.f_globals
elif isinstance(module, string_types):
frm = sys._getframe(1)
name = module
glob = __import__(module, frm.f_globals,
frm.f_locals, ['__dict__']).__dict__
else:
name = module.__name__
glob = module.__dict__
return _discover_space(name, glob)
示例15: unpacktype
def unpacktype(binstr, member, mtype):
offset = member[1]
size = member[2]
fmt = ''
if mtype == STR:
fmt = str(size) + 's'
elif mtype == INT:
fmt = 'I' if size == 4 else 'Q'
elif mtype == SHT:
fmt = 'H'
else:
calling_fxn = sys._getframe(1)
stderr.write("ERROR %s.%s tried to unpack the unknown type %d.\n" % (
callingclass(calling_fxn), calling_fxn.f_code.co_name, mtype))
return None
if struct.calcsize(fmt) != len(binstr[offset:size + offset]):
calling_fxn = sys._getframe(1)
stderr.write("ERROR %s.%s tried to unpack '%s' (fmt size: %d) from %d bytes.\n" % (
callingclass(calling_fxn), calling_fxn.f_code.co_name, fmt, struct.calcsize(fmt),
len(binstr[offset:size + offset])))
return None
return struct.unpack(fmt, binstr[offset:size + offset])[0]