本文整理匯總了Python中twisted.python.versions.Version.__cmp__方法的典型用法代碼示例。如果您正苦於以下問題:Python Version.__cmp__方法的具體用法?Python Version.__cmp__怎麽用?Python Version.__cmp__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.python.versions.Version
的用法示例。
在下文中一共展示了Version.__cmp__方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_notImplementedComparisons
# 需要導入模塊: from twisted.python.versions import Version [as 別名]
# 或者: from twisted.python.versions.Version import __cmp__ [as 別名]
def test_notImplementedComparisons(self):
"""
Comparing a L{Version} to some other object type results in
C{NotImplemented}.
"""
va = Version("dummy", 1, 0, 0)
vb = ("dummy", 1, 0, 0) # a tuple is not a Version object
self.assertEqual(va.__cmp__(vb), NotImplemented)
示例2: AppVersion
# 需要導入模塊: from twisted.python.versions import Version [as 別名]
# 或者: from twisted.python.versions.Version import __cmp__ [as 別名]
class AppVersion(Entity):
"""Track application versions"""
implements(IDroneModelAppVersion)
description = property( lambda self: "%s %s" % \
(self.app.name, self.version_string) )
serializable = True
def __getattribute__(self, name):
"""Overrode to fulfill Interface Obligations"""
if name in ('package','major','minor','micro','prerelease','base',\
'short'):
return self.version.__getattribute__(name)
return object.__getattribute__(self, name)
def __init__(self, *args, **kwargs):
self.version = Version(*args, **kwargs)
self.app = IDroneModelApp(self.version)
@property
def version_string(self):
"""makes a nice version string that we can use for reconstruction"""
result = '.'.join([
str(self.major),
str(self.minor),
str(self.micro),
])
if self.prerelease:
result += '.%s' % str(self.prerelease)
return result
def __getstate__(self):
return {
'app' : self.package,
'version' : self.version_string, #for proper serialization
}
def __cmp__(self, other):
"""overrode for easy comparison of AppVersion to AppVersion and Version
to AppVersion.
@raise IncomparableVersions: when the package names of the versions
differ.
@param other L{twisted.python.versions.Version},
L{IDroneModelAppVersion}, or object
@return C{int} of value -1, 0, or 1
"""
try:
if IDroneModelAppVersion.providedBy(other):
return self.version.__cmp__(other.version)
except IncomparableVersions: raise
except: pass
if isinstance(other, Version):
return self.version.__cmp__(other)
return object.__cmp__(self, other)
@staticmethod
def makeAppVersion(name, version):
"""Similar to ``makeArgs``
@return L{IDroneModelAppVersion} provider
"""
args, kwargs = AppVersion.makeArgs(name, version)
return AppVersion(*args, **kwargs)
@staticmethod
def makeVersion(name, version):
"""Similar to ``makeArgs``
@return L{twisted.python.versions.Version}
"""
args, kwargs = AppVersion.makeArgs(name, version)
return Version(*args, **kwargs)
@staticmethod
def versionExists(name, version):
"""check if this L{IDroneModelAppVersion} provider exists"""
args, kwargs = AppVersion.makeArgs(name, version)
return AppVersion.exists(*args, **kwargs)
@staticmethod
def makeArgs(name, version):
"""goes through great lengths to make args for use
by a constructor for class types -
L{IDroneModelAppVersion} providers or
L{twisted.python.versions.Version}.
@raises TypeError - if version is not convertable
@param name C{str}
@param version C{str}, C{list}, C{tuple}, or
L{twisted.python.versions.Version}
@return ((name, major, minor, micro), {'prerelease': prerelease})
"""
default = [0,0,0,0] #last number denotes pre-release
if isinstance(version, Version):
if version.package == name:
return (
(name, version.major, version.minor, version.micro),
{'prerelease': version.prerelease}
#.........這裏部分代碼省略.........