python类currentframe()的实例源码

config.py 文件源码 项目:core-framework 作者: RedhawkSDR 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __ImportModule( module_name, asName=None ):
    """
    Import a python module as needed into the global namespace. This can be accomplished
    programatically and inside a method or class.

    @param module_name : name of the module to load x.y.z
    @return module : python module object that was loaded
    """
    module = __import__(module_name)
    for layer in module_name.split('.')[1:]:
        module = getattr(module,layer)
    if asName:
        for x in range( len(inspect.stack()) ):
            inspect.currentframe(x).f_globals[asName]=module
    return module
png.py 文件源码 项目:Projects 作者: it2school 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def mycallersname():
    """Returns the name of the caller of the caller of this function
    (hence the name of the caller of the function in which
    "mycallersname()" textually appears).  Returns None if this cannot
    be determined."""

    # http://docs.python.org/library/inspect.html#the-interpreter-stack
    import inspect

    frame = inspect.currentframe()
    if not frame:
        return None
    frame_,filename_,lineno_,funname,linelist_,listi_ = (
      inspect.getouterframes(frame)[2])
    return funname
recipe-440685.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def call_contextual_template(template):
    # this is the magic line    
    frame = inspect.currentframe().f_back

    # again, we don't care about efficiency, it's not the point here
    d = dict(frame.f_globals)
    d.update(frame.f_locals)

    return call_template(template,d)
debugging.py 文件源码 项目:risk-slim 作者: ustunb 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def ipsh():
    ipshell = InteractiveShellEmbed(config=cfg, banner1=banner_msg, exit_msg=exit_msg)
    frame = inspect.currentframe().f_back
    msg   = 'Stopped at {0.f_code.co_filename} at line {0.f_lineno}'.format(frame)
    # Go back one level!
    # This is needed because the call to ipshell is inside the function ipsh()
    ipshell(msg, stack_depth=2)
utils.py 文件源码 项目:zmirror 作者: aploium 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def current_line_number():
    """Returns the current line number in our program.
    :return: current line number
    :rtype: int
    """
    import inspect
    return inspect.currentframe().f_back.f_lineno
install.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
install.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
install.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
install.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
formatizer.py 文件源码 项目:formatizer 作者: fgimian 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def f(format_string):
    caller_frame = inspect.currentframe().f_back
    caller_globals = caller_frame.f_globals
    caller_locals = caller_frame.f_locals
    lf = LiteralFormatter()
    return lf.format(format_string, caller_globals, caller_locals)
install.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
png.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def mycallersname():
    """Returns the name of the caller of the caller of this function
    (hence the name of the caller of the function in which
    "mycallersname()" textually appears).  Returns None if this cannot
    be determined."""

    # http://docs.python.org/library/inspect.html#the-interpreter-stack
    import inspect

    frame = inspect.currentframe()
    if not frame:
        return None
    frame_,filename_,lineno_,funname,linelist_,listi_ = (
      inspect.getouterframes(frame)[2])
    return funname
debug.py 文件源码 项目:django-virtual-pos 作者: intelligenia 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _prepare_debuglog_message(message, caller_level=2):
    # Por si acaso se le mete una cadena de tipo str,
    # este módulo es capaz de detectar eso y convertirla a UTF8
    if type(message) == str:
        message = unicode(message, "UTF-8")

    # Hora
    now = timezone.now()

    # Contexto desde el que se ha llamado
    curframe = inspect.currentframe()

    # Objeto frame que llamó a dlprint
    calframes = inspect.getouterframes(curframe, caller_level)
    caller_frame = calframes[2][0]
    caller_name = calframes[2][3]

    # Ruta del archivo que llamó a dlprint
    filename_path = caller_frame.f_code.co_filename
    filename = filename_path.split("/")[-1]

    # Obtención del mensaje
    return u"DjangoVirtualPOS: {0} {1} \"{2}\" at {3}:{5} in {6} ({4}:{5})\n".format(
        now.strftime("%Y-%m-%d %H:%M:%S %Z"), settings.DOMAIN, message,
                     filename, filename_path, caller_frame.f_lineno, caller_name
    )


# Prints the debug message
align.py 文件源码 项目:nn4nlp-code 作者: neubig 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def fully_aligned_distance(p1, p2):
    """compares each one to its' best mapping"""
    word2word = align_yields(p1, p2)
    nodes1 = set(node for node in p1.layer(layer1.LAYER_ID).all if is_comparable(node))
    nodes2 = set(node for node in p2.layer(layer1.LAYER_ID).all if is_comparable(node))
    first = align_nodes(nodes1, nodes2, word2word)
    word2word = reverse_mapping(word2word)
    second = align_nodes(nodes2, nodes1, word2word)

    count1 = len(set((i, j) for (i, j) in first.items() if compare(i, j)))
    count2 = len(set((i, j) for (i, j) in second.items() if compare(i, j)))
    print(inspect.currentframe().f_code.co_name, " returns ", two_sided_f(count1, count2, len(nodes1), len(nodes2)))
    return two_sided_f(count1, count2, len(nodes1), len(nodes2))
align.py 文件源码 项目:nn4nlp-code 作者: neubig 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def token_distance(p1, p2, map_by=buttom_up_by_levels_align):
    """compares considering only the main relation of each node"""
    count1 = token_matches(p1, p2, map_by)
    count2 = token_matches(p2, p1, map_by)
    nodes1 = set(node for node in p1.layer(layer1.LAYER_ID).all
                 if is_comparable(node) and label(node) in MAIN_RELATIONS)
    nodes2 = set(node for node in p2.layer(layer1.LAYER_ID).all
                 if is_comparable(node) and label(node) in MAIN_RELATIONS)
    print(inspect.currentframe().f_code.co_name)
    print("counts", count1, count2)
    print("lens", len(nodes1), len(nodes2))
    print(two_sided_f(count1, count2, len(nodes1), len(nodes2)))
    return two_sided_f(count1, count2, len(nodes1), len(nodes2))
install.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
DB.py 文件源码 项目:mongodb_consistent_backup 作者: Percona-Lab 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def get_oplog_cursor_since(self, caller, ts=None):
        frame   = getframeinfo(currentframe().f_back)
        comment = "%s:%s;%s:%i" % (caller.__name__, frame.function, frame.filename, frame.lineno)
        if not ts:
            ts = self.get_oplog_tail_ts()
        query = {'ts': {'$gte': ts}}
        logging.debug("Querying oplog on %s with query: %s" % (self.uri, query))
        # http://api.mongodb.com/python/current/examples/tailable.html
        return self.get_oplog_rs().find(query, cursor_type=CursorType.TAILABLE_AWAIT, oplog_replay=True).comment(comment)
timing.py 文件源码 项目:python-application 作者: AGProjects 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __enter__(self):
        parent = inspect.currentframe().f_back
        try:
            if parent.f_code.co_flags & inspect.CO_NEWLOCALS:
                raise RuntimeError('timers only work when invoked at the module/script level')
            self._with_start = parent.f_lasti
        finally:
            del parent
        gc_enabled = gc.isenabled()
        gc.disable()
        self._gc_enabled = gc_enabled
        self._start_time = self.time_function()
        return self
install.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()
install.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run(self):
        # Explicit request for old-style install?  Just do it
        if self.old_and_unmanageable or self.single_version_externally_managed:
            return orig.install.run(self)

        if not self._called_from_setup(inspect.currentframe()):
            # Run in backward-compatibility mode to support bdist_* commands.
            orig.install.run(self)
        else:
            self.do_egg_install()


问题


面经


文章

微信
公众号

扫码关注公众号