本文整理汇总了Python中twisted.python.components.Componentized方法的典型用法代码示例。如果您正苦于以下问题:Python components.Componentized方法的具体用法?Python components.Componentized怎么用?Python components.Componentized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.components
的用法示例。
在下文中一共展示了components.Componentized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def Application(name, uid=None, gid=None):
"""
Return a compound class.
Return an object supporting the L{IService}, L{IServiceCollection},
L{IProcess} and L{sob.IPersistable} interfaces, with the given
parameters. Always access the return value by explicit casting to
one of the interfaces.
"""
ret = components.Componentized()
availableComponents = [MultiService(), Process(uid, gid),
sob.Persistent(ret, name)]
for comp in availableComponents:
ret.addComponent(comp, ignoreClass=1)
IService(ret).setName(name)
return ret
示例2: test_getComponentDefaults
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_getComponentDefaults(self):
"""
Test that a default value specified to Componentized.getComponent if
there is no component for the requested interface.
"""
componentized = components.Componentized()
default = object()
self.assertIs(
componentized.getComponent(ITest, default),
default)
self.assertIs(
componentized.getComponent(ITest, default=default),
default)
self.assertIs(
componentized.getComponent(ITest),
None)
示例3: _setupConfiguredLogger
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def _setupConfiguredLogger(self, application, extraLogArgs={},
appLogger=app.AppLogger):
"""
Set up an AppLogger which exercises the C{logger} configuration option.
@type application: L{Componentized}
@param application: The L{Application} object to pass to
L{app.AppLogger.start}.
@type extraLogArgs: C{dict}
@param extraLogArgs: extra values to pass to AppLogger.
@type appLogger: L{AppLogger} class, or a subclass
@param appLogger: factory for L{AppLogger} instances.
@rtype: C{list}
@return: The logs accumulated by the log observer.
"""
observer = self._makeObserver()
logArgs = {"logger": lambda: observer}
logArgs.update(extraLogArgs)
logger = appLogger(logArgs)
logger.start(application)
return observer
示例4: test_unmarkedObserversDeprecated
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_unmarkedObserversDeprecated(self):
"""
L{app.AppLogger} using a logger observer which does not implement
L{ILogObserver} or L{LegacyILogObserver} will be wrapped in a compat
shim and raise a L{DeprecationWarning}.
"""
logs = []
logger = app.AppLogger({})
logger._getLogObserver = lambda: logs.append
logger.start(Componentized())
self.assertIn("starting up", textFromEventDict(logs[0]))
warnings = self.flushWarnings(
[self.test_unmarkedObserversDeprecated])
self.assertEqual(len(warnings), 1)
self.assertEqual(warnings[0]["message"],
("Passing a logger factory which makes log observers "
"which do not implement twisted.logger.ILogObserver "
"or twisted.python.log.ILogObserver to "
"twisted.application.app.AppLogger was deprecated "
"in Twisted 16.2. Please use a factory that "
"produces twisted.logger.ILogObserver (or the "
"legacy twisted.python.log.ILogObserver) "
"implementing objects instead."))
示例5: __init__
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def __init__(self, *args, **kw):
http.Request.__init__(self, *args, **kw)
components.Componentized.__init__(self)
示例6: __init__
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def __init__(self):
components.Componentized.__init__(self)
self._pathCache = {}
示例7: test_addAdapter
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_addAdapter(self):
"""
C{Componentized.setAdapter} adapts the instance by wrapping it with
given adapter class, then stores it using C{addComponent}.
"""
componentized = components.Componentized()
componentized.addAdapter(Adept, ignoreClass=True)
component = componentized.getComponent(IAdept)
self.assertEqual(component.original, componentized)
self.assertIsInstance(component, Adept)
示例8: test_setComponent
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_setComponent(self):
"""
C{Componentized.setComponent} stores the given component using the
given interface as the key.
"""
componentized = components.Componentized()
obj = object()
componentized.setComponent(ITest, obj)
self.assertIs(componentized.getComponent(ITest), obj)
示例9: test_unsetComponent
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_unsetComponent(self):
"""
C{Componentized.setComponent} removes the cached component for the
given interface.
"""
componentized = components.Componentized()
obj = object()
componentized.setComponent(ITest, obj)
componentized.unsetComponent(ITest)
self.assertIsNone(componentized.getComponent(ITest))
示例10: __init__
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def __init__(self):
self.num = 0
components.Componentized.__init__(self)
示例11: _getAvatar
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def _getAvatar(self, avatarId):
comp = components.Componentized()
user = self.userFactory(comp, avatarId)
sess = self.sessionFactory(comp)
sess.transportFactory = self.transportFactory
sess.chainedProtocolFactory = self.chainedProtocolFactory
comp.setComponent(iconch.IConchUser, user)
comp.setComponent(iconch.ISession, sess)
return user
示例12: test_startUsesApplicationLogObserver
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_startUsesApplicationLogObserver(self):
"""
When the L{ILogObserver} component is available on the application,
that object will be used as the log observer instead of constructing a
new one.
"""
application = Componentized()
observer = self._makeObserver()
application.setComponent(ILogObserver, observer)
logger = app.AppLogger({})
logger.start(application)
self._checkObserver(observer)
示例13: test_startUsesConfiguredLogObserver
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_startUsesConfiguredLogObserver(self):
"""
When the C{logger} key is specified in the configuration dictionary
(i.e., when C{--logger} is passed to twistd), the initial log observer
will be the log observer returned from the callable which the value
refers to in FQPN form.
"""
application = Componentized()
self._checkObserver(self._setupConfiguredLogger(application))
示例14: test_configuredLogObserverBeatsComponent
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_configuredLogObserverBeatsComponent(self):
"""
C{--logger} takes precedence over a L{ILogObserver} component set on
Application.
"""
observer = self._makeObserver()
application = Componentized()
application.setComponent(ILogObserver, observer)
self._checkObserver(self._setupConfiguredLogger(application))
self.assertEqual(observer._logs, [])
示例15: test_configuredLogObserverBeatsLegacyComponent
# 需要导入模块: from twisted.python import components [as 别名]
# 或者: from twisted.python.components import Componentized [as 别名]
def test_configuredLogObserverBeatsLegacyComponent(self):
"""
C{--logger} takes precedence over a L{LegacyILogObserver} component
set on Application.
"""
nonlogs = []
application = Componentized()
application.setComponent(LegacyILogObserver, nonlogs.append)
self._checkObserver(self._setupConfiguredLogger(application))
self.assertEqual(nonlogs, [])