• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python context.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_reader

    def get_reader(self, file_name):
        """See `IBackend.get_reader()`.

        If `file_name` matches `re_config_file` then the response is obtained
        from a server. Otherwise the filesystem is used to service the
        response.
        """
        config_file_match = self.re_config_file.match(file_name)
        if config_file_match is None:
            return super(TFTPBackend, self).get_reader(file_name)
        else:
            # Do not include any element that has not matched (ie. is None)
            params = {
                key: value
                for key, value in config_file_match.groupdict().items()
                if value is not None
                }
            # Send the local and remote endpoint addresses.
            local_host, local_port = get("local", (None, None))
            params["local"] = local_host
            remote_host, remote_port = get("remote", (None, None))
            params["remote"] = remote_host
            params["cluster_uuid"] = get_cluster_uuid()
            d = self.get_config_reader(params)
            d.addErrback(self.get_page_errback, file_name)
            return d
开发者ID:deepakhajare,项目名称:maas,代码行数:26,代码来源:tftp.py


示例2: test_unsetAfterCall

 def test_unsetAfterCall(self):
     """
     After a L{twisted.python.context.call} completes, keys specified in the
     call are no longer associated with the values from that call.
     """
     context.call({"x": "y"}, lambda: None)
     self.assertIsNone(context.get("x"))
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:7,代码来源:test_context.py


示例3: logPrefix

    def logPrefix():
        "logPrefix that adjust to current context"

        logCtx = context.get('system',"-")
        if logCtx is not "-":
            return "%s,%s"%(logCtx,prefix)
        return prefix
开发者ID:amvtek,项目名称:EventSource,代码行数:7,代码来源:log.py


示例4: msg

    def msg(self, *message, **kw):
        """
        Log a new message.

        For example::

        >>> log.msg('Hello, world.')

        In particular, you MUST avoid the forms::

        >>> log.msg(u'Hello, world.')
        >>> log.msg('Hello ', 'world.')

        These forms work (sometimes) by accident and will be disabled
        entirely in the future.
        """
        actualEventDict = (context.get(ILogContext) or {}).copy()
        actualEventDict.update(kw)
        actualEventDict['message'] = message
        actualEventDict['time'] = time.time()
        for i in xrange(len(self.observers) - 1, -1, -1):
            try:
                self.observers[i](actualEventDict)
            except KeyboardInterrupt:
                # Don't swallow keyboard interrupt!
                raise
            except UnicodeEncodeError:
                raise
            except:
                o = self.observers.pop(i)
                err(failure.Failure(),
                    "Log observer %s failed, removing from observer list." % (o,))
开发者ID:axray,项目名称:dataware.dreamplug,代码行数:32,代码来源:log.py


示例5: dataReceived

 def dataReceived(self, bytes):
     self.system = context.get(ILogContext)["system"]
     self.transport.write("b")
     # Only close connection if both sides have received data, so
     # that both sides have system set.
     if "b" in bytes:
         self.transport.loseConnection()
开发者ID:BillAndersan,项目名称:twisted,代码行数:7,代码来源:connectionmixins.py


示例6: _contextualize

def _contextualize(contextFactory, contextReceiver):
    """
    Invoke a callable with an argument derived from the current execution
    context (L{twisted.python.context}), or automatically created if none is
    yet present in the current context.

    This function, with a better name and documentation, should probably be
    somewhere in L{twisted.python.context}.  Calling context.get() and
    context.call() individually is perilous because you always have to handle
    the case where the value you're looking for isn't present; this idiom
    forces you to supply some behavior for that case.

    @param contextFactory: An object which is both a 0-arg callable and
    hashable; used to look up the value in the context, set the value in the
    context, and create the value (by being called).

    @param contextReceiver: A function that receives the value created or
    identified by contextFactory.  It is a 1-arg callable object, called with
    the result of calling the contextFactory, or retrieving the contextFactory
    from the context.
    """
    value = context.get(contextFactory, _NOT_SPECIFIED)
    if value is not _NOT_SPECIFIED:
        return contextReceiver(value)
    else:
        return context.call({contextFactory: contextFactory()},
                            _contextualize, contextFactory, contextReceiver)
开发者ID:bne,项目名称:squeal,代码行数:27,代码来源:structlike.py


示例7: test_setDefault

 def test_setDefault(self):
     """
     A default value may be set for a key in the context using
     L{twisted.python.context.setDefault}.
     """
     key = object()
     self.addCleanup(context.defaultContextDict.pop, key, None)
     context.setDefault(key, "y")
     self.assertEqual("y", context.get(key))
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:9,代码来源:test_context.py


示例8: broadcast

 def broadcast(self):
     """
     Don't really broadcast.  Add this event to the events which will be
     sent when the action (or whatever) execution transaction is committed
     successfully.
     """
     broadcaster = context.get(iimaginary.ITransactionalEventBroadcaster)
     if broadcaster is not None:
         broadcaster.addEvent(self.reify())
     else:
         self.reify()()
开发者ID:rcarmo,项目名称:divmod.org,代码行数:11,代码来源:events.py


示例9: msg

    def msg(self, *message, **kw):
        """
        Log a new message.

        The message should be a native string, i.e. bytes on Python 2 and
        Unicode on Python 3. For compatibility with both use the native string
        syntax, for example::

        >>> from twisted.python import log
        >>> log.msg('Hello, world.')

        You MUST avoid passing in Unicode on Python 2, and the form::

        >>> log.msg('Hello ', 'world.')

        This form only works (sometimes) by accident.

        Keyword arguments will be converted into items in the event
        dict that is passed to L{ILogObserver} implementations.
        Each implementation, in turn, can define keys that are used
        by it specifically, in addition to common keys listed at
        L{ILogObserver.__call__}.

        For example, to set the C{system} parameter while logging
        a message::

        >>> log.msg('Started', system='Foo')

        """
        actualEventDict = (context.get(ILogContext) or {}).copy()
        actualEventDict.update(kw)
        actualEventDict['message'] = message
        actualEventDict['time'] = time.time()
        for i in range(len(self.observers) - 1, -1, -1):
            try:
                self.observers[i](actualEventDict)
            except KeyboardInterrupt:
                # Don't swallow keyboard interrupt!
                raise
            except UnicodeEncodeError:
                raise
            except:
                observer = self.observers[i]
                self.observers[i] = lambda event: None
                try:
                    self._err(failure.Failure(),
                        "Log observer %s failed." % (observer,))
                except:
                    # Sometimes err() will throw an exception,
                    # e.g. RuntimeError due to blowing the stack; if that
                    # happens, there's not much we can do...
                    pass
                self.observers[i] = observer
开发者ID:hanwei2008,项目名称:ENV,代码行数:53,代码来源:log.py


示例10: log

def log(level, message, system=None):
    """
    Write a message to the Twisted log with an appropriate prefix, assuming it
    meets our verbosity criteria.
    """
    if not system:
        system = context.get(twisted_log.ILogContext)['system']
    if level >= LEVEL:
        if level >= Levels.WARNING:
            twisted_log.msg(message, system="WARNING %s" % (system,))
        elif level >= Levels.INFO:
            twisted_log.msg(message, system="INFO %s" % (system,))
        else:
            twisted_log.msg(message, system="DEBUG %s" % (system,))
开发者ID:jdswinbank,项目名称:Comet,代码行数:14,代码来源:__init__.py


示例11: legacyEvent

    def legacyEvent(self, *message, **values):
        """
        Return a basic old-style event as would be created by L{legacyLog.msg}.

        @param message: a message event value in the legacy event format
        @type message: L{tuple} of L{bytes}

        @param values: additional event values in the legacy event format
        @type event: L{dict}

        @return: a legacy event
        """
        event = (context.get(legacyLog.ILogContext) or {}).copy()
        event.update(values)
        event["message"] = message
        event["time"] = time()
        if "isError" not in event:
            event["isError"] = 0
        return event
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:19,代码来源:test_legacy.py


示例12: msg

    def msg(self, *message, **kw):
        """
        Log a new message.

        For example::

        >>> log.msg('Hello, world.')

        In particular, you MUST avoid the forms::

        >>> log.msg(u'Hello, world.')
        >>> log.msg('Hello ', 'world.')

        These forms work (sometimes) by accident and will be disabled
        entirely in the future.
        """
        actualEventDict = (context.get(ILogContext) or {}).copy()
        actualEventDict.update(kw)
        actualEventDict['message'] = message
        actualEventDict['time'] = time.time()
        for i in xrange(len(self.observers) - 1, -1, -1):
            try:
                self.observers[i](actualEventDict)
            except KeyboardInterrupt:
                # Don't swallow keyboard interrupt!
                raise
            except UnicodeEncodeError:
                raise
            except:
                observer = self.observers[i]
                self.observers[i] = lambda event: None
                try:
                    self._err(failure.Failure(),
                        "Log observer %s failed." % (observer,))
                except:
                    # Sometimes err() will throw an exception,
                    # e.g. RuntimeError due to blowing the stack; if that
                    # happens, there's not much we can do...
                    pass
                self.observers[i] = observer
开发者ID:BillAndersan,项目名称:twisted,代码行数:40,代码来源:log.py


示例13: _newOperation

    def _newOperation(self, label, deferred):
        """
        Helper to emit a log event when a new operation is started and
        another one when it completes.
        """
        # If this is a scheduled request, record the lag in the
        # scheduling now so it can be reported when the response is
        # received.
        lag = context.get('lag', None)

        before = self._reactor.seconds()
        msg(
            type="operation",
            phase="start",
            user=self._client.record.uid,
            client_type=self._client.title,
            client_id=self._client._client_id,
            label=label,
            lag=lag,
        )

        def finished(passthrough):
            success = not isinstance(passthrough, Failure)
            if not success:
                passthrough.trap(IncorrectResponseCode)
                passthrough = passthrough.value.response
            after = self._reactor.seconds()
            msg(
                type="operation",
                phase="end",
                duration=after - before,
                user=self._client.record.uid,
                client_type=self._client.title,
                client_id=self._client._client_id,
                label=label,
                success=success,
            )
            return passthrough
        deferred.addBoth(finished)
        return deferred
开发者ID:eventable,项目名称:CalendarServer,代码行数:40,代码来源:profiles.py


示例14: msg

    def msg(self, *message, **kw):
        """
        Log a new message.

        The message should be a native string, i.e. bytes on Python 2 and
        Unicode on Python 3. For compatibility with both use the native string
        syntax, for example::

        >>> log.msg('Hello, world.')

        You MUST avoid passing in Unicode on Python 2, and the form::

        >>> log.msg('Hello ', 'world.')

        This form only works (sometimes) by accident.
        """
        actualEventDict = (context.get(ILogContext) or {}).copy()
        actualEventDict.update(kw)
        actualEventDict['message'] = message
        actualEventDict['time'] = time.time()
        for i in range(len(self.observers) - 1, -1, -1):
            try:
                self.observers[i](actualEventDict)
            except KeyboardInterrupt:
                # Don't swallow keyboard interrupt!
                raise
            except UnicodeEncodeError:
                raise
            except:
                observer = self.observers[i]
                self.observers[i] = lambda event: None
                try:
                    self._err(failure.Failure(),
                        "Log observer %s failed." % (observer,))
                except:
                    # Sometimes err() will throw an exception,
                    # e.g. RuntimeError due to blowing the stack; if that
                    # happens, there's not much we can do...
                    pass
                self.observers[i] = observer
开发者ID:geodrinx,项目名称:gearthview,代码行数:40,代码来源:log.py


示例15: msg

    def msg(self, *message, **kw):
        """
        Log a new message.

        The message should be a native string, i.e. bytes on Python 2 and
        Unicode on Python 3. For compatibility with both use the native string
        syntax, for example::

            >>> log.msg('Hello, world.')

        You MUST avoid passing in Unicode on Python 2, and the form::

            >>> log.msg('Hello ', 'world.')

        This form only works (sometimes) by accident.

        Keyword arguments will be converted into items in the event
        dict that is passed to L{ILogObserver} implementations.
        Each implementation, in turn, can define keys that are used
        by it specifically, in addition to common keys listed at
        L{ILogObserver.__call__}.

        For example, to set the C{system} parameter while logging
        a message::

        >>> log.msg('Started', system='Foo')

        """
        actualEventDict = (context.get(ILogContext) or {}).copy()
        actualEventDict.update(kw)
        actualEventDict['message'] = message
        actualEventDict['time'] = time.time()
        if "isError" not in actualEventDict:
            actualEventDict["isError"] = 0

        _publishNew(self._publishPublisher, actualEventDict, textFromEventDict)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:36,代码来源:log.py


示例16: __init__

 def __init__(self, args, names):
     super(CapturedContext, self).__init__(*args)
     self.context = {name: context.get(name) for name in names}
开发者ID:deepakhajare,项目名称:maas,代码行数:3,代码来源:test_protocol.py


示例17: _cssRewriter

def _cssRewriter(topLevelBF, path, registry):
	"""
	C{path} is a C{str} representing the absolute path of the .css file.
	"""
	request = context.get('_BetterFile_last_request')
	return CSSResource(topLevelBF, request, path)
开发者ID:ludios,项目名称:Webmagic,代码行数:6,代码来源:untwist.py


示例18: gettext

def gettext(string):
    return context.get(
        'translations', default=support.NullTranslations()).gettext(string)
开发者ID:Nobatek,项目名称:umongo,代码行数:3,代码来源:klein_babel.py


示例19: testBasicContext

 def testBasicContext(self):
     self.assertEquals(context.get("x"), None)
     self.assertEquals(context.call({"x": "y"}, context.get, "x"), "y")
     self.assertEquals(context.get("x"), None)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:4,代码来源:test_context.py


示例20: dataReceived

 def dataReceived(self, bytes):
     self.system.callback(context.get(ILogContext)["system"])
开发者ID:GunioRobot,项目名称:twisted,代码行数:2,代码来源:connectionmixins.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python deprecate.deprecated函数代码示例发布时间:2022-05-27
下一篇:
Python components.registerAdapter函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap