本文整理汇总了Python中twisted.python.deprecate.deprecated函数的典型用法代码示例。如果您正苦于以下问题:Python deprecated函数的具体用法?Python deprecated怎么用?Python deprecated使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deprecated函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deprecatedPreservesName
def test_deprecatedPreservesName(self):
"""
The decorated function has the same name as the original.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
self.assertEqual(dummyCallable.__name__, dummy.__name__)
self.assertEqual(qual(dummyCallable), qual(dummy))
示例2: test_versionMetadata
def test_versionMetadata(self):
"""
Deprecating a function adds version information to the decorated
version of that function.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
self.assertEqual(version, dummy.deprecatedVersion)
示例3: deprecated
def deprecated(a):
# the stacklevel is important here, because as the function is
# recursive, the warnings produced have a different stack, but we
# want to be sure that only the first warning is tested against
warnings.warn("Woo deprecated",
category=PendingDeprecationWarning,
stacklevel=2)
i[0] += 1
if i[0] < 3:
return deprecated(a)
else:
return a
示例4: test_deprecateEmitsWarning
def test_deprecateEmitsWarning(self):
"""
Decorating a callable with L{deprecated} emits a warning.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
def addStackLevel():
dummy()
self.assertWarns(
DeprecationWarning,
getDeprecationWarningString(dummyCallable, version),
__file__,
addStackLevel)
示例5: test_deprecatedUpdatesDocstring
def test_deprecatedUpdatesDocstring(self):
"""
The docstring of the deprecated function is appended with information
about the deprecation.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
_appendToDocstring(
dummyCallable,
_getDeprecationDocstring(version))
self.assertEqual(dummyCallable.__doc__, dummy.__doc__)
示例6: test_deprecateEmitsWarning
def test_deprecateEmitsWarning(self):
"""
Decorating a callable with L{deprecated} emits a warning.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(dummyCallable)
def addStackLevel():
dummy()
with catch_warnings(record=True) as caught:
simplefilter("always")
addStackLevel()
self.assertEqual(caught[0].category, DeprecationWarning)
self.assertEqual(str(caught[0].message), getDeprecationWarningString(dummyCallable, version))
# rstrip in case .pyc/.pyo
self.assertEqual(caught[0].filename.rstrip('co'), __file__.rstrip('co'))
示例7: test_nestedDeprecation
def test_nestedDeprecation(self):
"""
L{callDeprecated} ignores all deprecations apart from the first.
Multiple warnings are generated when a deprecated function calls
another deprecated function. The first warning is the one generated by
the explicitly called function. That's the warning that we care about.
"""
differentVersion = Version('Foo', 1, 2, 3)
def nestedDeprecation(*args):
return self.oldMethod(*args)
nestedDeprecation = deprecated(differentVersion)(nestedDeprecation)
self.callDeprecated(differentVersion, nestedDeprecation, 24)
示例8: test_deprecatedReplacementWithCallable
def test_deprecatedReplacementWithCallable(self):
"""
L{deprecated} takes an additional replacement parameter that can be used
to indicate the new, non-deprecated method developers should use. If
the replacement parameter is a callable, its fully qualified name will
be interpolated into the warning message.
"""
version = Version('Twisted', 8, 0, 0)
decorator = deprecated(version, replacement=dummyReplacementMethod)
dummy = decorator(dummyCallable)
self.assertEqual(dummy.__doc__,
"\n"
" Do nothing.\n\n"
" This is used to test the deprecation decorators.\n\n"
" Deprecated in Twisted 8.0.0; please use "
"%s.dummyReplacementMethod instead.\n"
" " % (__name__,))
示例9: test_deprecatedReplacement
def test_deprecatedReplacement(self):
"""
L{deprecated} takes an additional replacement parameter that can be used
to indicate the new, non-deprecated method developers should use. If
the replacement parameter is a string, it will be interpolated directly
into the warning message.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version, "something.foobar")(dummyCallable)
self.assertEqual(dummy.__doc__,
"\n"
" Do nothing.\n\n"
" This is used to test the deprecation decorators.\n\n"
" Deprecated in Twisted 8.0.0; please use "
"something.foobar"
" instead.\n"
" ")
示例10: test_deprecatedUpdatesDocstring
def test_deprecatedUpdatesDocstring(self):
"""
The docstring of the deprecated function is appended with information
about the deprecation.
"""
def localDummyCallable():
"""
Do nothing.
This is used to test the deprecation decorators.
"""
version = Version('Twisted', 8, 0, 0)
dummy = deprecated(version)(localDummyCallable)
_appendToDocstring(
localDummyCallable,
_getDeprecationDocstring(version, ''))
self.assertEqual(localDummyCallable.__doc__, dummy.__doc__)
示例11: test_nestedDeprecation
def test_nestedDeprecation(self):
"""
L{callDeprecated} ignores all deprecations apart from the first.
Multiple warnings are generated when a deprecated function calls
another deprecated function. The first warning is the one generated by
the explicitly called function. That's the warning that we care about.
"""
differentVersion = Version('Foo', 1, 2, 3)
def nestedDeprecation(*args):
return oldMethod(*args)
nestedDeprecation = deprecated(differentVersion)(nestedDeprecation)
self.callDeprecated(differentVersion, nestedDeprecation, 24)
# The oldMethod deprecation should have been emitted too, not captured
# by callDeprecated. Flush it now to make sure it did happen and to
# prevent it from showing up on stdout.
warningsShown = self.flushWarnings()
self.assertEqual(len(warningsShown), 1)
示例12: __call__
def __call__(self, *args, **kw):
"""Asynchronously invoke a remote method.
"""
return self.obj.broker._sendMessage('',self.obj.perspective, self.obj.luid, self.name, args, kw)
def noOperation(*args, **kw):
"""
Do nothing.
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet,
consectetur, adipisci velit...
"""
noOperation = deprecated(Version("twisted", 8, 2, 0))(noOperation)
class PBConnectionLost(Exception):
pass
def printTraceback(tb):
"""
Print a traceback (string) to the standard log.
"""
log.msg('Perspective Broker Traceback:' )
log.msg(tb)
printTraceback = deprecated(Version("twisted", 8, 2, 0))(printTraceback)
示例13: compareMarkPos
notes = domhelpers.findElementsWithAttribute(document, "class", "note")
notePrefix = dom.parseString('<strong>Note: </strong>').documentElement
for note in notes:
note.childNodes.insert(0, notePrefix)
def compareMarkPos(a, b):
"""
Perform in every way identically to L{cmp} for valid inputs.
"""
linecmp = cmp(a[0], b[0])
if linecmp:
return linecmp
return cmp(a[1], b[1])
compareMarkPos = deprecated(Version('Twisted', 9, 0, 0))(compareMarkPos)
def comparePosition(firstElement, secondElement):
"""
Compare the two elements given by their position in the document or
documents they were parsed from.
@type firstElement: C{dom.Element}
@type secondElement: C{dom.Element}
@return: C{-1}, C{0}, or C{1}, with the same meanings as the return value
of L{cmp}.
"""
return cmp(firstElement._markpos, secondElement._markpos)
示例14: str
self.callDeprecated,
differentVersion, self.oldMethod, 'foo')
self.assertIn(getVersionString(self.version), str(exception))
self.assertIn(getVersionString(differentVersion), str(exception))
def test_nestedDeprecation(self):
"""
L{callDeprecated} ignores all deprecations apart from the first.
Multiple warnings are generated when a deprecated function calls
another deprecated function. The first warning is the one generated by
the explicitly called function. That's the warning that we care about.
"""
differentVersion = Version('Foo', 1, 2, 3)
def nestedDeprecation(*args):
return self.oldMethod(*args)
nestedDeprecation = deprecated(differentVersion)(nestedDeprecation)
self.callDeprecated(differentVersion, nestedDeprecation, 24)
# The oldMethod deprecation should have been emitted too, not captured
# by callDeprecated. Flush it now to make sure it did happen and to
# prevent it from showing up on stdout.
warningsShown = self.flushWarnings()
self.assertEqual(len(warningsShown), 1)
TestCallDeprecated.oldMethod = deprecated(TestCallDeprecated.version)(
TestCallDeprecated.oldMethod)
示例15: _makeOptions
def _makeOptions(self, pattern, enums):
options = super(RadioGroupInput, self)._makeOptions(pattern, enums)
for o in options:
o.fillSlots('name', self.name)
yield o
class ObjectRadioGroupInput(ObjectChoiceMixin, RadioGroupInput):
"""
Variant of L{RadioGroupInput} for arbitrary Python objects.
Deprecated. Use L{RadioGroupInput} with L{methanal.enums.ObjectEnum}.
"""
ObjectRadioGroupInput.__init__ = deprecated(Version('methanal', 0, 2, 1))(
ObjectRadioGroupInput.__init__)
class MultiCheckboxInput(MultiChoiceInputMixin, ChoiceInput):
"""
Multiple-checkboxes input.
"""
fragmentName = 'methanal-multicheck-input'
jsClass = u'Methanal.View.MultiCheckboxInput'
class ObjectMultiCheckboxInput(ObjectMultiChoiceMixin, MultiCheckboxInput):
"""
Variant of L{MultiCheckboxInput} for arbitrary Python objects.