本文整理汇总了Python中twisted.python.util.mergeFunctionMetadata函数的典型用法代码示例。如果您正苦于以下问题:Python mergeFunctionMetadata函数的具体用法?Python mergeFunctionMetadata怎么用?Python mergeFunctionMetadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mergeFunctionMetadata函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: patch_noargs_decorator
def patch_noargs_decorator(decorator):
def new_decorator(func):
wrapper = decorator(func)
wrapper.__wrapped__ = func
return wrapper
util.mergeFunctionMetadata(decorator, new_decorator)
return new_decorator
开发者ID:buildbot,项目名称:buildbot,代码行数:7,代码来源:decorators.py
示例2: onlyOnce
def onlyOnce(fn):
'Set up FN to only run once within an interpreter instance'
def wrap(*args, **kwargs):
if hasattr(fn, 'called'):
return
fn.called = 1
return fn(*args, **kwargs)
util.mergeFunctionMetadata(fn, wrap)
return wrap
开发者ID:595796726,项目名称:buildbot,代码行数:9,代码来源:__init__.py
示例3: _maybeUnhandled
def _maybeUnhandled(fn):
def wrap(self, *args, **kwargs):
d = fn(self, *args, **kwargs)
if self._start_unhandled_deferreds is not None:
self._start_unhandled_deferreds.append(d)
return d
wrap.__wrapped__ = fn
twutil.mergeFunctionMetadata(fn, wrap)
return wrap
开发者ID:daymanc,项目名称:buildbot,代码行数:9,代码来源:buildstep.py
示例4: _f
def _f(f):
def g(*args, **kw):
_close_db()
try:
ret = f(*args, **kw)
finally:
_close_db()
return ret
mergeFunctionMetadata(f, g)
return g
开发者ID:nakedible,项目名称:vpnease-l2tp,代码行数:10,代码来源:init.py
示例5: _f
def _f(f):
def g(self, *args, **kw):
if not hasattr(self, 'identify_successful'):
raise managementprotocol.InternalServerError('no identify_successful attribute found')
elif not isinstance(self.identify_successful, bool):
raise managementprotocol.InternalServerError('identify_successful attribute not boolean')
elif not self.identify_successful:
raise managementprotocol.ProtocolStateError('request requires successful Identify')
else:
return f(self, *args, **kw)
mergeFunctionMetadata(f, g)
return g
开发者ID:nakedible,项目名称:vpnease-l2tp,代码行数:13,代码来源:managementserver.py
示例6: _f
def _f(f):
def g(*args, **kw):
starttime = datetime.datetime.utcnow()
dbase = database
if dbase is None:
raise Exception('dbase is None')
_transact_begin_log_helper('@untransact', f, dbase)
if (dbase is not None) and hasattr(dbase, 'store') and (dbase.store is not None):
# hasattr + store check is to fix #621, this is also an API issue with rdf.py
t = dbase.begin_untransaction()
else:
t = None
global toplevel_transaction
# Log transact locktime here if active
if t is not None:
# XXX: There is no sensible date value to show here,
# because we are not actually logging anything for
# current untransaction: we log the locktime of the
# toplevel transaction which is committed here. Using
# current time as both timestamps for now.
_transact_end_log_helper('@transact (in untransact)', toplevel_transaction, dbase, True, datetime.datetime.utcnow(), datetime.datetime.utcnow(), t.get_txn_locked_time(), TRANSACT_LOCK_TIME_WARNING_LIMIT, untransact_point=f)
try:
ret = f(*args, **kw)
except:
t_locked_time = None
if t is not None:
t_locked_time = t.get_locked_time()
t.commit()
endtime = datetime.datetime.utcnow()
_transact_end_log_helper('@untransact', f, dbase, False, starttime, endtime, t_locked_time, UNTRANSACT_LOCK_TIME_WARNING_LIMIT)
raise
t_locked_time = None
if t is not None:
t_locked_time = t.get_locked_time()
t.commit()
endtime = datetime.datetime.utcnow()
_transact_end_log_helper('@untransact', f, dbase, True, starttime, endtime, t_locked_time, UNTRANSACT_LOCK_TIME_WARNING_LIMIT)
return ret
mergeFunctionMetadata(f, g)
return g
开发者ID:nakedible,项目名称:vpnease-l2tp,代码行数:48,代码来源:rdftransact.py
示例7: deferredGenerator
def deferredGenerator(f):
"""
deferredGenerator and waitForDeferred help you write L{Deferred}-using code
that looks like a regular sequential function. If your code has a minimum
requirement of Python 2.5, consider the use of L{inlineCallbacks} instead,
which can accomplish the same thing in a more concise manner.
There are two important functions involved: L{waitForDeferred}, and
L{deferredGenerator}. They are used together, like this::
def thingummy():
thing = waitForDeferred(makeSomeRequestResultingInDeferred())
yield thing
thing = thing.getResult()
print thing #the result! hoorj!
thingummy = deferredGenerator(thingummy)
L{waitForDeferred} returns something that you should immediately yield; when
your generator is resumed, calling C{thing.getResult()} will either give you
the result of the L{Deferred} if it was a success, or raise an exception if it
was a failure. Calling C{getResult} is B{absolutely mandatory}. If you do
not call it, I{your program will not work}.
L{deferredGenerator} takes one of these waitForDeferred-using generator
functions and converts it into a function that returns a L{Deferred}. The
result of the L{Deferred} will be the last value that your generator yielded
unless the last value is a L{waitForDeferred} instance, in which case the
result will be C{None}. If the function raises an unhandled exception, the
L{Deferred} will errback instead. Remember that C{return result} won't work;
use C{yield result; return} in place of that.
Note that not yielding anything from your generator will make the L{Deferred}
result in C{None}. Yielding a L{Deferred} from your generator is also an error
condition; always yield C{waitForDeferred(d)} instead.
The L{Deferred} returned from your deferred generator may also errback if your
generator raised an exception. For example::
def thingummy():
thing = waitForDeferred(makeSomeRequestResultingInDeferred())
yield thing
thing = thing.getResult()
if thing == 'I love Twisted':
# will become the result of the Deferred
yield 'TWISTED IS GREAT!'
return
else:
# will trigger an errback
raise Exception('DESTROY ALL LIFE')
thingummy = deferredGenerator(thingummy)
Put succinctly, these functions connect deferred-using code with this 'fake
blocking' style in both directions: L{waitForDeferred} converts from a
L{Deferred} to the 'blocking' style, and L{deferredGenerator} converts from the
'blocking' style to a L{Deferred}.
"""
def unwindGenerator(*args, **kwargs):
return _deferGenerator(f(*args, **kwargs), Deferred())
return mergeFunctionMetadata(f, unwindGenerator)
开发者ID:fluidinfo,项目名称:chainDeferredExamples,代码行数:60,代码来源:tdefer.py
示例8: fastInline
def fastInline(f):
"""This decorator is mostly equivalent to defer.inlineCallbacks except
that speed is the primary priority. while inlineCallbacks checks a few
different things to make sure you're doing it properly, this method simply
assumes you are.
changes:
* this decorator no longer checks that you're wrapping a generator
* this decorator no longer checks that _DefGen_Return is thrown from the
decoratored generator only
* the generator loop no longer double checks that you're yielding
deferreds and simply assumes it, catching the exception if you aren't
* the generator stops calling isinstance for logic - profiling reveals
that isinstance consumes a nontrivial amount of computing power during
heavy use
You can force this method to behave exactly like defer.inlineCallbacks by
providing the FORCE_STANDARD_INLINE_CALLBACKS environment variable
"""
def unwind(*args, **kwargs):
try:
gen = f(*args, **kwargs)
except defer._DefGen_Return: # pylint: disable=W0212
raise TypeError("defer.returnValue used from non-generator")
return _inlineCallbacks(None, None, gen, defer.Deferred())
return mergeFunctionMetadata(f, unwind)
开发者ID:spacemonkeyinc,项目名称:twisted-utils,代码行数:26,代码来源:deferred.py
示例9: goodDecorator
def goodDecorator(fn):
"""
Decorate a function and preserve the original name.
"""
def nameCollision(*args, **kwargs):
return fn(*args, **kwargs)
return mergeFunctionMetadata(fn, nameCollision)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:7,代码来源:sample.py
示例10: decorator
def decorator(function):
def decorated(*a, **kw):
with context_factory(*args, **kwargs):
return function(*a, **kw)
return mergeFunctionMetadata(function, decorated)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:7,代码来源:utils.py
示例11: fireWhenDoneFunc
def fireWhenDoneFunc(d, f):
"""Returns closure that when called calls f and then callbacks d.
"""
def newf(*args, **kw):
rtn = f(*args, **kw)
d.callback('')
return rtn
return util.mergeFunctionMetadata(f, newf)
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:8,代码来源:util.py
示例12: make_it_green
def make_it_green(f):
def unwindGenerator(*args, **kwargs):
g = greenlet(f)
# Похоже, что такой тупой ход парента не меняет.
# Также похоже, что и без него работает, оставляя выполнение в текущем гринлете.
#g.parent = main
return _inline_greens(None, g, (args, kwargs), defer.Deferred())
return mergeFunctionMetadata(f, unwindGenerator)
开发者ID:Deepwalker,项目名称:deepwalker_sandbox,代码行数:8,代码来源:tx_green.py
示例13: __getattr__
def __getattr__(self, name):
maybe_method = getattr(self._transport, name)
if not callable(maybe_method):
return maybe_method
def defer_it(*args, **kwargs):
return defer.maybeDeferred(maybe_method, *args, **kwargs)
return mergeFunctionMetadata(maybe_method, defer_it)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:9,代码来源:test_sftp.py
示例14: _deco
def _deco(meth):
methodName = meth.__name__
def _soapMethod(self, *args, **kwargs):
def _parse(body):
return body[0]
request = getattr(NS, methodName)
request, parser = meth(self, request, *args, **kwargs)
return self.call(_uj(_nsuri(NS), methodName), request).addCallback(_parse).addCallback(parser)
return util.mergeFunctionMetadata(meth, _soapMethod)
开发者ID:mithrandi,项目名称:eridanus,代码行数:9,代码来源:soap.py
示例15: atSpecifiedTime
def atSpecifiedTime(when, func):
def inner(*a, **kw):
orig = time.time
time.time = lambda: when
try:
return func(*a, **kw)
finally:
time.time = orig
return util.mergeFunctionMetadata(func, inner)
开发者ID:nunb,项目名称:calendarserver,代码行数:9,代码来源:test_http_headers.py
示例16: _fireWhenDoneFunc
def _fireWhenDoneFunc(self, d, f):
"""Returns closure that when called calls f and then callbacks d.
"""
from twisted.python import util as tputil
def newf(*args, **kw):
rtn = f(*args, **kw)
d.callback('')
return rtn
return tputil.mergeFunctionMetadata(f, newf)
开发者ID:galaxysd,项目名称:BitTorrent,代码行数:9,代码来源:test_tcp.py
示例17: suppressWarnings
def suppressWarnings(f, *suppressedWarnings):
"""
Wrap C{f} in a callable which suppresses the indicated warnings before
invoking C{f} and unsuppresses them afterwards. If f returns a Deferred,
warnings will remain suppressed until the Deferred fires.
"""
def warningSuppressingWrapper(*a, **kw):
return runWithWarningsSuppressed(suppressedWarnings, f, *a, **kw)
return tputil.mergeFunctionMetadata(f, warningSuppressingWrapper)
开发者ID:grze,项目名称:castle-bravo,代码行数:9,代码来源:myutils.py
示例18: reset_store
def reset_store(func):
"""Function decorator that resets the main store."""
def reset_store_decorator(*args, **kwargs):
try:
return func(*args, **kwargs)
finally:
_get_sqlobject_store().reset()
return mergeFunctionMetadata(func, reset_store_decorator)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:9,代码来源:sqlbase.py
示例19: alias
def alias(f, name=None):
"""
Create an alias of another command.
"""
newCmd = mergeFunctionMetadata(f, lambda *a, **kw: f(*a, **kw))
newCmd.alias = True
if name is not None:
newCmd.func_name = name
newCmd.arglimits = getCommandArgLimits(f)
return newCmd
开发者ID:mithrandi,项目名称:eridanus,代码行数:10,代码来源:plugin.py
示例20: return_fault
def return_fault(function):
"""Catch any Faults raised by 'function' and return them instead."""
def decorated(*args, **kwargs):
try:
return function(*args, **kwargs)
except Fault as fault:
return fault
return mergeFunctionMetadata(function, decorated)
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:10,代码来源:helpers.py
注:本文中的twisted.python.util.mergeFunctionMetadata函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论