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


Python context.Context类代码示例

本文整理汇总了Python中context.Context的典型用法代码示例。如果您正苦于以下问题:Python Context类的具体用法?Python Context怎么用?Python Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: add_node

    def add_node(self, prev, worker, gstate, do_hash=True):
        if do_hash:
            hash = gstate.compute_hash()
            if hash is not None:
                node = self.statespace.get_node_by_hash(hash)
                if node is not None:
                    return (node, False)
        else:
            hash = None
        uid = str(self.statespace.nodes_count)
        node = Node(uid, hash)
        logging.debug("New node %s", node.uid)

        if prev:
            node.prev = prev
        self.statespace.add_node(node)

        if self.debug_compare_states is not None \
                and node.uid in self.debug_compare_states:
            if self.debug_captured_states is None:
                self.debug_captured_states = []
            logging.debug("Capturing %s", node)
            self.debug_captured_states.append((gstate.copy(), worker))

        if self.statespace.nodes_count > self.max_states:
            logging.info("Maximal number of states reached")
            if self.debug_compare_states is not None:
                self.debug_compare()
            raise ErrorFound()

        if self.debug_state == uid:
            context = Context(self, node, None)
            context.add_error_and_throw(
                errormsg.StateCaptured(context, uid=uid))
        return (node, True)
开发者ID:spirali,项目名称:aislinn,代码行数:35,代码来源:generator.py

示例2: test

    def test(self):
        c = Context('Root')
        c.start()

        o0 = self.SampleObj()
        Dispatcher.add(obj=o0, parent_obj=None, context=c)

        o1 = self.SampleObj()
        Dispatcher.add(obj=o1, parent_obj=None, context=c)
        Dispatcher.add_listener(src_obj=o1, dst_obj=o0)

        Dispatcher.send(event=Event('1'), src_obj=o0, dst_obj=o1)
        assert str(o1.lastHandler) == 'on1'

        Dispatcher.queue(event=Event('2'), src_obj=o0, dst_obj=o1)
        #assert str(o1.lastHandler) == 'on2'

        Dispatcher.send(event=Event('3'), src_obj=o0, dst_obj=o1)
        #assert str(o1.lastHandler) == 'on3'

        Dispatcher.notify(event=Event('4'), src_obj=o1)
        #assert str(o1.lastHandler) == 'on4'
        Dispatcher.notify(event=Event('4'), src_obj=o1)
        #assert str(o1.lastHandler) == 'on4'

        c.stop()
开发者ID:CaveMike,项目名称:iron,代码行数:26,代码来源:test_dispatcher.py

示例3: run_keyword

    def run_keyword(self, name, args, kwargs):
        """
        RF Dynamic API hook implementation that maps method names to their actual functions.

        :param name: The keyword name from robot
        :type name: str
        :param args: the args from robot
        :type args: list
        :param kwargs: a dict of additional args
        :type kwargs: dict
        :return: callable function
        :rtype: callable
        """
        # Translate back from Robot Framework name to actual method
        ret = None

        func_mapping = KeywordManager().get_meth_mapping_from_robot_alias(self, name)
        meth = func_mapping.func
        try:
            if "${" in func_mapping.func_alias:
                args = self._parse_embedded_args(name, func_mapping.func_alias)
            ret = meth(self, *args, **kwargs)
        except Exception, e:
            Context.set_current_page("automationpages.Page")
            # Pass up the stack, so we see complete stack trace in Robot trace logs
            BuiltIn().fail(str(e))
开发者ID:charleshamel73,项目名称:robot-pageobjects,代码行数:26,代码来源:page.py

示例4: __init__

 def __init__(self, argnames, expr=None):
     self.argnames = argnames
     self.expr = expr
     self.funcontext = None
     self.strict = True
     Context.__init__(self)
     self['$'] = self
开发者ID:gurgeh,项目名称:Pur-e,代码行数:7,代码来源:shadow_core.py

示例5: test_expand

    def test_expand(self):
        """
        Test expand functionality
        :return:
        """

        data = [
            (
                {'range_value': {'__range__': [2]},},
                [{'range_value': 0}, {'range_value': 1}]
            ),
            (
                {'range_value': {'__range__': [1], '__format__': 'value_{value}'},},
                [{'range_value': 'value_0'}]
            ),
            (
                {'range_value': {'__range__': [2], '__format__': 'value_{value}', '__exclude__': [0]}},
                [{'range_value': 'value_1'}]
            ),
            (
                {'choice_value': {'__choices__': ['a', 'b'], '__format__': 'value_{value}'}},
                [{'choice_value': 'value_a'}, {'choice_value': 'value_b'}]
            ),
        ]

        for item in data:
            inp, expected = item
            context = Context(inp)
            self.assertEqual(list(context.expand()), expected)
开发者ID:phonkee,项目名称:vcontext,代码行数:29,代码来源:tests.py

示例6: runTest

	def runTest( self ):

		context = Context( 'context' )
		context.start()

		listener = TestListener()
		listener.context = context

		node = System( 'system0', listener )
		node.addListener( listener )

		assert( node.currentState == 'Stopped' )

		node.process( Event( 'Start' ) )
		assert( node.currentState == 'Started' )

		sleep( 2 )

		node.process( Event( 'Pause' ) )
		assert( node.currentState == 'Paused' )

		node.process( Event( 'Continue' ) )
		assert( node.currentState == 'Started' )

		node.process( Event( 'Stop' ) )
		assert( node.currentState == 'Stopped' )
开发者ID:CaveMike,项目名称:mercury,代码行数:26,代码来源:system_test.py

示例7: genBitfieldContexts

def genBitfieldContexts(enums, bitfGroups):
    bitfieldEnums = [enum for enum in enums if enum.type == "GLbitfield"]
    maxLength = max([len(enumBID(enum)) for enum in bitfieldEnums])

    noneIdentifier = "GL_NONE_BIT"
    noneValue = "0x0"
    noneGroups = Context.listContext([g.name for g in bitfGroups], sortKey = lambda g: g)

    bitfieldContexts = []
    bitfieldContexts.append({"identifier": noneIdentifier,
                             "name": noneIdentifier,
                             "value": noneValue,
                             "spaces": " " * (maxLength - len(noneIdentifier)),
                             "generic": True,
                             "groups": noneGroups,
                             "primaryGroup": noneGroups["items"][0]["item"] if not noneGroups["empty"] else None,
                             "supported": (lambda feature, core, ext: True) })
    for enum in bitfieldEnums:
        groups = Context.listContext([g.name for g in enum.groups], sortKey = lambda g: g)
        bitfieldContexts.append({"identifier": enumBID(enum),
                                 "name": enum.name,
                                 "value": enum.value,
                                 "spaces": " " * (maxLength - len(enumBID(enum))),
                                 "generic": False,
                                 "groups": groups,
                                 "primaryGroup": groups["items"][0]["item"] if not groups["empty"] else None,
                                 "supported": supportedLambda(enum) })
    return bitfieldContexts
开发者ID:achurch,项目名称:glbinding,代码行数:28,代码来源:gen_bitfields.py

示例8: __init__

 def __init__(self, parent, frame_num=0):
     Context.__init__(self)
     self._parent = parent
     self._arguments = collections.OrderedDict()
     self._parent_parser = parent._parent_parser
     self._context = parent._context
     self._frame_num = frame_num
开发者ID:ManOfTeflon,项目名称:config,代码行数:7,代码来源:actions.py

示例9: make_context

 def make_context(self):
     c = Context()
     for name, recordset in self._db.items():
         for r in recordset:
             if hasattr(r, 'fixity'):
                 c.bind_operator(name, r.graph, r.assoc, r.prec, r.fixity)
             else:
                 c.bind(name, r.graph)
     return c
开发者ID:carriercomm,项目名称:fundy,代码行数:9,代码来源:pyops.py

示例10: listen

 async def listen(self):
   # Start listening for incoming request on tcp socket
   self._open()
   while True:
     req = self._read()
     if not req:
       break
     ctx = Context(req)
     # This should run middleware in parallel?
     for fn in self.middleware:
       await fn(ctx)
     self._send(ctx.to_HTTP())
开发者ID:ccutch,项目名称:python-webserver,代码行数:12,代码来源:server.py

示例11: test

    def test(self):
        events = [Event('event0'), Event('event1'), Event('event2')]

        o = SampleObj(events)

        c = Context('context0')

        for event in events:
            future = c.queue(event, o, o)
        time.sleep(0.1)

        c.poll()
开发者ID:CaveMike,项目名称:iron,代码行数:12,代码来源:test_context.py

示例12: run

def run(fname):
    with open(fname, "r") as f:
        source_code = f.read()

    # Remove shebang line if it exists.
    if source_code[0:2] == "#!":
        source_code = "\n".join(source_code.split("\n")[1:])

    ctx = Context()
    parser.parse(lexer.lex(source_code)).compile(ctx)

    bytecode = ctx.create_bytecode()
    frame = Frame(bytecode)
    interpreter = Interpreter()

    interpreter.interpret(bytecode, frame)
开发者ID:pombredanne,项目名称:rila,代码行数:16,代码来源:main.py

示例13: get

def get(domain, function=False, **kwargs):
    """
    Get a single piece of data. function needs to be true if you want
    a callable.
    """

    return Context.get_skin(function=function).get(domain, **kwargs)
开发者ID:fakedrake,项目名称:WikipediaBase-skinz,代码行数:7,代码来源:api.py

示例14: on_clipboard_owner_change

    def on_clipboard_owner_change(self, clipboard, event):
        text = clipboard.wait_for_text() or ""

        if etc.DEBUG: print "Clipboard change", "###" + etc.reduce_text(text,40) + "###"

        # Ignore clipboard selections made by keyboard
        if text and self.keydetector.check_event() != KeyDetector.KEYBOARD:
            mouse_x, mouse_y = self.mouse_xy()

            # reads again the configuration file so it can be changed without restarting the program!
            self.check_config()

            self.ctx = Context(text, mouse_x, mouse_y)

            # I could call the ctx.complete method and create the menu when
            # the floating windows is clicked. But to make the application
            # more responsive, i make it now.
            # This is more important when the application is inactive for a long time.
            self.ctx.complete()

            # I have to define as a object variable, or it will loose scope and the menus will close after this method returns!
            self.menu = self.actions.actions_menu(self.ctx)

            if not self.timer:
                # start the timer that will be use to show and hide the floating
                self.timer = GObject.timeout_add(self.TIMER_INTERVAL, self.timer_func)

            # There are some applications that produce several clipboard events while
            # the user is grabbing the mouse to make the selection.
            # So we wait some time before showing the floating icon.
            # The show_me method will be called from the timer...
            self.delayed_to_show = True

        else:
            if etc.DEBUG: print "Ignored"
开发者ID:idnael,项目名称:ctxsearch,代码行数:35,代码来源:old_main.py

示例15: __init__

    def __init__(self):
        self.in_robot = Context.in_robot()
        self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
        self.threshold_level_as_str = self.get_threshold_level_as_str()
        self.threshold_level_as_int = self.get_log_level_from_str(self.threshold_level_as_str)

        if self.in_robot:
            self.logger = robot.api.logger
        else:

            # Stream handler is attached from log() since
            # that must be decided at run-time, but here we might as well
            # do the setup to keep log() clean.
            self.stream_handler = logging.StreamHandler(sys.stdout)
            self.stream_handler.setFormatter(self.formatter)

            # We have to instantiate a logger to something and this is a global
            # logger so we name it by this class. Later in this class'
            # log method, we manipulate the msg string to include the calling
            # page class name.
            logger = logging.getLogger(self.__class__.__name__)
            logger.setLevel(self.threshold_level_as_int)
            fh = logging.FileHandler("po_log.txt", "w")
            fh.setLevel(self.threshold_level_as_int)
            fh.setFormatter(self.formatter)
            logger.addHandler(fh)
            self.logger = logger
开发者ID:guykisel,项目名称:robotframework-pageobjects,代码行数:27,代码来源:abstractedlogger.py


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