当前位置: 首页>>代码示例>>Python>>正文


Python State.clear方法代码示例

本文整理汇总了Python中state.State.clear方法的典型用法代码示例。如果您正苦于以下问题:Python State.clear方法的具体用法?Python State.clear怎么用?Python State.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在state.State的用法示例。


在下文中一共展示了State.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WPTUpdate

# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import clear [as 别名]
class WPTUpdate(object):
    def __init__(self, logger, runner_cls=UpdateRunner, **kwargs):
        """Object that controls the running of a whole wptupdate.

        :param runner_cls: Runner subclass holding the overall list of
                           steps to run.
        :param kwargs: Command line arguments
        """
        self.runner_cls = runner_cls
        self.serve_root = kwargs["test_paths"]["/"]["tests_path"]

        if not kwargs["sync"]:
            setup_paths(self.serve_root)
        else:
            if os.path.exists(kwargs["sync_path"]):
                # If the sync path doesn't exist we defer this until it does
                setup_paths(kwargs["sync_path"])

        self.state = State(logger)
        self.kwargs = kwargs
        self.logger = logger

    def run(self, **kwargs):
        if self.kwargs["abort"]:
            self.abort()
            return exit_clean

        if not self.kwargs["continue"] and not self.state.is_empty():
            self.logger.error("Found existing state. Run with --continue to resume or --abort to clear state")
            return exit_unclean

        if self.kwargs["continue"]:
            if self.state.is_empty():
                self.logger.error("No sync in progress?")
                return exit_clean

            self.kwargs = self.state.kwargs
        else:
            self.state.kwargs = self.kwargs

        self.state.serve_root = self.serve_root

        update_runner = self.runner_cls(self.logger, self.state)
        rv = update_runner.run()
        if rv in (exit_clean, None):
            self.state.clear()

        return rv

    def abort(self):
        self.state.clear()
开发者ID:Coder206,项目名称:servo,代码行数:53,代码来源:update.py

示例2: __init__

# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import clear [as 别名]

#.........这里部分代码省略.........
                title_common=zip(movie_list, commonalities)
                title_common=sorted(title_common, \
                                    lambda x,y:cmp(x[1],y[1]))[0:result_length]
                results = [item[0] for item in title_common]
            else:
                results = movie_list
            return {'print':'title','results':results}
        elif request_type == CHOICE:
            pass # do something here
        else:
            count = internal_dict.get('result_length')
            if count:
                internal_dict.pop('result_length')
                count = [0,count]
            elif request_type=="plot" or request_type=="year":
                count = [0, 1]
            results=self.dbi.query(request_type, internal_dict, count=count)
            state_dict = {'request':request_type}
            state_dict.update(internal_dict)
            self.state.add_request(state_dict)
            if isinstance(results, int) or isinstance(results, long):
                if len(internal_dict)<2:
                    self.pending_question=MORE_PREF
                    return {"question":MORE_PREF}
                else:
                    self.pending_question = "result_length"
                    return {'print':request_type,"list":results, "question":HOW_MANY}
            else:
                self.state.add_result({request_type:results})
                return {'print':request_type,'results':results}

    def command(self, dict):
        if dict["command"]==CLEAR:
            self.state.clear()

    def response(self, dict):
        internal_dict = dict.copy()
        response = internal_dict.pop("response")
        if response=="NO":
            if self.pending_question == MORE_PREF:
                self.pending_question = "result_length"
                return {"question":HOW_MANY}
            else:
                return {}
        elif response == "YES":
            if self.pending_question:
                internal_dict["request"]=self.state.last_request()
                internal_dict.update(self.state.get_all())
        elif self.pending_question:
            internal_dict[self.pending_question]=response
            request =self.state.last_request()
            if request == OPINION:
                request = 'title'
            internal_dict["request"] =request
            
            internal_dict.update(self.state.get_all())
        self.pending_question = None
        return self.request(internal_dict)
    
    def off_topic(self, dict):
        reply = chatbot.reply
        if reply is None:
            reply = chatbot.submit(dict['off_topic'])
        return {'off_topic':reply}
    
    def check_spelling(self, mylist):
开发者ID:B-Rich,项目名称:ai-movie,代码行数:70,代码来源:__init__.py


注:本文中的state.State.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。