本文整理汇总了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))