我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用future.utils.istext()。
def join(self, iterable_of_bytes): errmsg = 'sequence item {0}: expected bytes, {1} found' if isbytes(iterable_of_bytes) or istext(iterable_of_bytes): raise TypeError(errmsg.format(0, type(iterable_of_bytes))) for i, item in enumerate(iterable_of_bytes): if istext(item): raise TypeError(errmsg.format(i, type(item))) return newbytes(super(newbytes, self).join(iterable_of_bytes))
def __lt__(self, other): if not istext(other): raise TypeError(self.unorderable_err.format(type(other))) return super(newstr, self).__lt__(other)
def __le__(self, other): if not istext(other): raise TypeError(self.unorderable_err.format(type(other))) return super(newstr, self).__le__(other)
def __gt__(self, other): if not istext(other): raise TypeError(self.unorderable_err.format(type(other))) return super(newstr, self).__gt__(other)
def __new__(cls, x=0, base=10): """ From the Py3 int docstring: | int(x=0) -> integer | int(x, base=10) -> integer | | Convert a number or string to an integer, or return 0 if no | arguments are given. If x is a number, return x.__int__(). For | floating point numbers, this truncates towards zero. | | If x is not a number or if base is given, then x must be a string, | bytes, or bytearray instance representing an integer literal in the | given base. The literal can be preceded by '+' or '-' and be | surrounded by whitespace. The base defaults to 10. Valid bases are | 0 and 2-36. Base 0 means to interpret the base from the string as an | integer literal. | >>> int('0b100', base=0) | 4 """ try: val = x.__int__() except AttributeError: val = x else: if not isint(val): raise TypeError('__int__ returned non-int ({0})'.format( type(val))) if base != 10: # Explicit base if not (istext(val) or isbytes(val) or isinstance(val, bytearray)): raise TypeError( "int() can't convert non-string with explicit base") try: return super(newint, cls).__new__(cls, val, base) except TypeError: return super(newint, cls).__new__(cls, newbytes(val), base) # After here, base is 10 try: return super(newint, cls).__new__(cls, val) except TypeError: # Py2 long doesn't handle bytearray input with an explicit base, so # handle this here. # Py3: int(bytearray(b'10'), 2) == 2 # Py2: int(bytearray(b'10'), 2) == 2 raises TypeError # Py2: long(bytearray(b'10'), 2) == 2 raises TypeError try: return super(newint, cls).__new__(cls, newbytes(val)) except: raise TypeError("newint argument must be a string or a number," "not '{0}'".format(type(val)))