本文整理匯總了Python中operator.truth方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.truth方法的具體用法?Python operator.truth怎麽用?Python operator.truth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類operator
的用法示例。
在下文中一共展示了operator.truth方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_operator
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
self.assertIs(operator.truth(1), True)
with test_support.check_py3k_warnings():
self.assertIs(operator.isCallable(0), False)
self.assertIs(operator.isCallable(len), True)
self.assertIs(operator.isNumberType(None), False)
self.assertIs(operator.isNumberType(0), True)
self.assertIs(operator.not_(1), False)
self.assertIs(operator.not_(0), True)
self.assertIs(operator.isSequenceType(0), False)
self.assertIs(operator.isSequenceType([]), True)
self.assertIs(operator.contains([], 1), False)
self.assertIs(operator.contains([1], 1), True)
self.assertIs(operator.isMappingType(1), False)
self.assertIs(operator.isMappingType({}), True)
self.assertIs(operator.lt(0, 0), False)
self.assertIs(operator.lt(0, 1), True)
self.assertIs(operator.is_(True, True), True)
self.assertIs(operator.is_(True, False), False)
self.assertIs(operator.is_not(True, True), False)
self.assertIs(operator.is_not(True, False), True)
示例2: boolean
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def boolean(value, _truefalse=(False, True)):
"""Convert any Python value to XML-RPC 'boolean'."""
return _truefalse[operator.truth(value)]
##
# Wrapper for XML-RPC DateTime values. This converts a time value to
# the format used by XML-RPC.
# <p>
# The value can be given as a string in the format
# "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
# time.localtime()), or an integer value (as returned by time.time()).
# The wrapper uses time.localtime() to convert an integer to a time
# tuple.
#
# @param value The time, given as an ISO 8601 string, a time
# tuple, or a integer time value.
示例3: test_operator
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
self.assertIs(operator.truth(1), True)
self.assertIs(operator.isCallable(0), False)
self.assertIs(operator.isCallable(len), True)
self.assertIs(operator.isNumberType(None), False)
self.assertIs(operator.isNumberType(0), True)
self.assertIs(operator.not_(1), False)
self.assertIs(operator.not_(0), True)
self.assertIs(operator.isSequenceType(0), False)
self.assertIs(operator.isSequenceType([]), True)
self.assertIs(operator.contains([], 1), False)
self.assertIs(operator.contains([1], 1), True)
self.assertIs(operator.isMappingType(1), False)
self.assertIs(operator.isMappingType({}), True)
self.assertIs(operator.lt(0, 0), False)
self.assertIs(operator.lt(0, 1), True)
self.assertIs(operator.is_(True, True), True)
self.assertIs(operator.is_(True, False), False)
self.assertIs(operator.is_not(True, True), False)
self.assertIs(operator.is_not(True, False), True)
示例4: __init__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def __init__(self, value = 0):
self.value = operator.truth(value)
示例5: boolean
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def boolean(value, _truefalse=(False, True)):
"""Convert any Python value to XML-RPC 'boolean'."""
return _truefalse[operator.truth(value)]
示例6: test_bool_values
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_bool_values(self):
from operator import truth
for t, v in zip(bool_types, bool_values):
self.assertEqual(t(v).value, truth(v))
示例7: test_truth
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_truth(self):
class C(object):
def __nonzero__(self):
raise SyntaxError
self.assertRaises(TypeError, operator.truth)
self.assertRaises(SyntaxError, operator.truth, C())
self.assertTrue(operator.truth(5))
self.assertTrue(operator.truth([0]))
self.assertFalse(operator.truth(0))
self.assertFalse(operator.truth([]))
示例8: parse_stdout_filelist
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def parse_stdout_filelist(hg_out_filelist):
files = hg_out_filelist.split()
files = [f.strip(string.whitespace + "'") for f in files]
files = list(filter(operator.truth, files)) # get rid of empty entries
return files
示例9: __init__
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def __init__(self, value=0):
self.value = operator.truth(value)
示例10: getBroadcastAllowed
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getBroadcastAllowed(self):
"""
Checks if broadcast is currently allowed on this port.
@return: Whether this port may broadcast.
@rtype: L{bool}
"""
return operator.truth(
self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST))
示例11: setLoopbackMode
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def setLoopbackMode(self, mode):
mode = struct.pack("b", operator.truth(mode))
self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP,
mode)
示例12: getTcpNoDelay
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getTcpNoDelay(self):
return operator.truth(self.socket.getsockopt(socket.IPPROTO_TCP,
socket.TCP_NODELAY))
示例13: getTcpKeepAlive
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getTcpKeepAlive(self):
return operator.truth(self.socket.getsockopt(socket.SOL_SOCKET,
socket.SO_KEEPALIVE))
示例14: getTcpNoDelay
# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getTcpNoDelay(self):
return operator.truth(self.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY))