Python operator 模块,isSequenceType() 实例源码

我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用operator.isSequenceType()

项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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)
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def __init__(self, stream, cols=None, number_fmt='%8.4f', col_width=8,
                 col_sep='  ', output_block=False, **pars):
        DataRecorder.__init__(self, **pars)
        self._stream = stream
        if not number_fmt.startswith('%'):
            number_fmt = '%%s' % number_fmt
        self._number_fmt = number_fmt
        self._col_sep = col_sep
        self._col_width = col_width
        if operator.isSequenceType(cols) and \
                not isinstance(cols, (str, unicode)):
            cols = CaselessList(cols)
        elif operator.isNumberType(cols):
            cols = cols
        else:
            cols = None
        self._columns = cols
        self._output_block = output_block
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def setEnvObj(self, obj):
        """Sets the environment for the given object. If object is a sequence
        then each pair of elements k, v is added as env[k] = v.
        If object is a map then the environmnent is updated.
        Other object types are not supported
        The elements which are strings are 'python evaluated'

        @throws TypeError is obj is not a sequence or a map

        @param[in] obj object to be added to the environment

        @return a dict representing the added environment"""

        if operator.isSequenceType(obj) and \
           not isinstance(obj, (str, unicode)):
            obj = self._dictFromSequence(obj)
        elif not operator.isMappingType(obj):
            raise TypeError("obj parameter must be a sequence or a map")

        obj = self._encode(obj)
        for k, v in obj.iteritems():
            self._setOneEnv(k, v)
        return obj
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def __init__(self, allowedMethods, *args):
        Exception.__init__(self, allowedMethods, *args)
        self.allowedMethods = allowedMethods

        if not operator.isSequenceType(allowedMethods):
            why = "but my first argument is not a sequence."
            s = ("First argument must be a sequence of"
                 " supported methods, %s" % (why,))
            raise TypeError, s
项目:rTensor    作者:erichson    | 项目源码 | 文件源码
def is_sequence(obj):
    """
    Helper function to determine sequences
    across Python 2.x and 3.x
    """
    try:
        from collections import Sequence
    except ImportError:
        from operator import isSequenceType
        return isSequenceType(obj)
    else:
        return isinstance(obj, Sequence)
项目:fandango    作者:tango-controls    | 项目源码 | 文件源码
def __init__(self,*args):
        assert args
        if len(args)==1:
            if isinstance(args[0],basestring):
                args = args[0].split('.')
            elif isSequenceType(args[0]):
                args = args[0]
            else:
                args = [args]
        self._tuple = tuple(args)
项目:fandango    作者:tango-controls    | 项目源码 | 文件源码
def __init__(self,arg=None):
        """ Initializes the list with a sequence or an initial value. """
        if arg is None:
            list.__init__(self)
        elif operator.isSequenceType(arg):
            list.__init__(self,arg)
        else:
            list.__init__(self)
            self.append(arg,1)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_isSequenceType(self):
        self.assertRaises(TypeError, operator.isSequenceType)
        self.assertTrue(operator.isSequenceType(dir()))
        self.assertTrue(operator.isSequenceType(()))
        self.assertTrue(operator.isSequenceType(xrange(10)))
        self.assertTrue(operator.isSequenceType('yeahbuddy'))
        self.assertFalse(operator.isSequenceType(3))
        class Dict(dict): pass
        self.assertFalse(operator.isSequenceType(Dict()))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_isSequenceType(self):
        self.assertRaises(TypeError, operator.isSequenceType)
        self.assertTrue(operator.isSequenceType(dir()))
        self.assertTrue(operator.isSequenceType(()))
        self.assertTrue(operator.isSequenceType(xrange(10)))
        self.assertTrue(operator.isSequenceType('yeahbuddy'))
        self.assertFalse(operator.isSequenceType(3))
        class Dict(dict): pass
        self.assertFalse(operator.isSequenceType(Dict()))
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def __init__(self, allowedMethods, *args):
        Exception.__init__(self, allowedMethods, *args)
        self.allowedMethods = allowedMethods

        if not operator.isSequenceType(allowedMethods):
            why = "but my first argument is not a sequence."
            s = ("First argument must be a sequence of"
                 " supported methods, %s" % (why,))
            raise TypeError, s
项目:protoc-gen-lua-bin    作者:u0u0    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:protoc-gen-lua-bin    作者:u0u0    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:protoc-gen-lua-bin    作者:u0u0    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:protoc-gen-lua-bin    作者:u0u0    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:bigmuddy-network-telemetry-collector    作者:cisco    | 项目源码 | 文件源码
def is_sequence(other):
        return operator.isSequenceType(other)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_isSequenceType(self):
        self.assertRaises(TypeError, operator.isSequenceType)
        self.assertTrue(operator.isSequenceType(dir()))
        self.assertTrue(operator.isSequenceType(()))
        self.assertTrue(operator.isSequenceType(xrange(10)))
        self.assertTrue(operator.isSequenceType('yeahbuddy'))
        self.assertFalse(operator.isSequenceType(3))
        class Dict(dict): pass
        self.assertFalse(operator.isSequenceType(Dict()))
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_isSequenceType(self):
        self.assertRaises(TypeError, operator.isSequenceType)
        self.assertTrue(operator.isSequenceType(dir()))
        self.assertTrue(operator.isSequenceType(()))
        self.assertTrue(operator.isSequenceType(xrange(10)))
        self.assertTrue(operator.isSequenceType('yeahbuddy'))
        self.assertFalse(operator.isSequenceType(3))
        class Dict(dict): pass
        self.assertFalse(operator.isSequenceType(Dict()))
项目:Chromium_DepotTools    作者:p07r0457    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def get_plot(self):
        self.plot = ''
        if hasattr(self.page, 'EditorialReviews'):
            if hasattr(self.page.EditorialReviews, 'EditorialReview'):
                if isSequenceType(self.page.EditorialReviews.EditorialReview):
                    for review in self.page.EditorialReviews.EditorialReview:
                        if hasattr(review, 'Source') and \
                            hasattr(review, 'Content') and \
                            string.find(review.Source, 'Amazon') > -1:
                            self.plot = review.Content
                else:
                    if hasattr(self.page.EditorialReviews.EditorialReview, 'Source') and \
                        hasattr(self.page.EditorialReviews.EditorialReview, 'Content') and \
                        string.find(self.page.EditorialReviews.EditorialReview.Source, 'Amazon') > -1:
                        self.plot = self.page.EditorialReviews.EditorialReview.Content
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def get_genre(self):
        # BrowseNodeId 547664 (Genres)
        self.genre = ''
        delimiter = ''
        if hasattr(self.page, 'BrowseNodes') and hasattr(self.page.BrowseNodes, 'BrowseNode'):
            if isSequenceType(self.page.BrowseNodes.BrowseNode):
                for node in self.page.BrowseNodes.BrowseNode:
                    parentnode = node
                    while hasattr(parentnode, 'Ancestors') and parentnode.BrowseNodeId <> '547664' \
                            and parentnode.BrowseNodeId <> '13628901': # no production countries; they are also arranged under genres
                        parentnode = parentnode.Ancestors.BrowseNode
                    if parentnode.BrowseNodeId == '547664':
                        self.genre = self.genre + delimiter + node.Name
                        delimiter = ', '
项目:griffith    作者:Strit    | 项目源码 | 文件源码
def get_country(self):
        # BrowseNodeId 13628901 (production countries)
        self.country = ''
        delimiter = ''
        if hasattr(self.page, 'BrowseNodes') and hasattr(self.page.BrowseNodes, 'BrowseNode'):
            if isSequenceType(self.page.BrowseNodes.BrowseNode):
                for node in self.page.BrowseNodes.BrowseNode:
                    parentnode = node
                    while hasattr(parentnode, 'Ancestors') and parentnode.BrowseNodeId <> '13628901':
                        parentnode = parentnode.Ancestors.BrowseNode
                    if parentnode.BrowseNodeId == '13628901':
                        self.country = self.country + delimiter + node.Name
                        delimiter = ', '
项目:node-gn    作者:Shouqun    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:PCInotes    作者:ahangchen    | 项目源码 | 文件源码
def _convert_to_svm_node_array(x):
    """ convert a sequence or mapping to an svm_node array """
    import operator

    # Find non zero elements
    iter_range = []
    if type(x) == dict:
        for k, v in x.iteritems():
            # all zeros kept due to the precomputed kernel; no good solution yet
            #           if v != 0:
            iter_range.append(k)
    elif operator.isSequenceType(x):
        for j in range(len(x)):
            #           if x[j] != 0:
            iter_range.append(j)
    else:
        raise TypeError, "data must be a mapping or a sequence"

    iter_range.sort()
    data = svmc.svm_node_array(len(iter_range) + 1)
    svmc.svm_node_array_set(data, len(iter_range), -1, 0)

    j = 0
    for k in iter_range:
        svmc.svm_node_array_set(data, j, k, x[k])
        j = j + 1
    return data
项目:CNCGToolKit    作者:cineuse    | 项目源码 | 文件源码
def point(self, lut, mode=None):
        "Map image through lookup table"

        self.load()

        if isinstance(lut, ImagePointHandler):
            return lut.point(self)

        if not isSequenceType(lut):
            # if it isn't a list, it should be a function
            if self.mode in ("I", "I;16", "F"):
                # check if the function can be used with point_transform
                scale, offset = _getscaleoffset(lut)
                return self._new(self.im.point_transform(scale, offset))
            # for other modes, convert the function to a table
            lut = map(lut, range(256)) * self.im.bands

        if self.mode == "F":
            # FIXME: _imaging returns a confusing error message for this case
            raise ValueError("point operation not supported for this mode")

        return self._new(self.im.point(lut, mode))

    ##
    # Adds or replaces the alpha layer in this image.  If the image
    # does not have an alpha layer, it's converted to "LA" or "RGBA".
    # The new layer must be either "L" or "1".
    #
    # @param im The new alpha layer.  This can either be an "L" or "1"
    #    image having the same size as this image, or an integer or
    #    other color value.
项目:depot_tools    作者:webrtc-uwp    | 项目源码 | 文件源码
def __eq__(self, other):
    if self is other:
      return True
    if not operator.isSequenceType(other):
      raise TypeError(
          'Can only compare repeated scalar fields against sequences.')
    # We are presumably comparing against some other sequence type.
    return other == self[slice(None, None, None)]
项目:image-occlusion-enhanced    作者:glutanimate    | 项目源码 | 文件源码
def point(self, lut, mode=None):
        "Map image through lookup table"

        self.load()

        if isinstance(lut, ImagePointHandler):
            return lut.point(self)

        if not isSequenceType(lut):
            # if it isn't a list, it should be a function
            if self.mode in ("I", "I;16", "F"):
                # check if the function can be used with point_transform
                scale, offset = _getscaleoffset(lut)
                return self._new(self.im.point_transform(scale, offset))
            # for other modes, convert the function to a table
            lut = map(lut, range(256)) * self.im.bands

        if self.mode == "F":
            # FIXME: _imaging returns a confusing error message for this case
            raise ValueError("point operation not supported for this mode")

        return self._new(self.im.point(lut, mode))

    ##
    # Adds or replaces the alpha layer in this image.  If the image
    # does not have an alpha layer, it's converted to "LA" or "RGBA".
    # The new layer must be either "L" or "1".
    #
    # @param im The new alpha layer.  This can either be an "L" or "1"
    #    image having the same size as this image, or an integer or
    #    other color value.
项目:InstagramPosting    作者:LeviParadis    | 项目源码 | 文件源码
def point(self, lut, mode=None):
        "Map image through lookup table"

        self.load()

        if isinstance(lut, ImagePointHandler):
            return lut.point(self)

        if not isSequenceType(lut):
            # if it isn't a list, it should be a function
            if self.mode in ("I", "I;16", "F"):
                # check if the function can be used with point_transform
                scale, offset = _getscaleoffset(lut)
                return self._new(self.im.point_transform(scale, offset))
            # for other modes, convert the function to a table
            lut = map(lut, range(256)) * self.im.bands

        if self.mode == "F":
            # FIXME: _imaging returns a confusing error message for this case
            raise ValueError("point operation not supported for this mode")

        return self._new(self.im.point(lut, mode))

    ##
    # Adds or replaces the alpha layer in this image.  If the image
    # does not have an alpha layer, it's converted to "LA" or "RGBA".
    # The new layer must be either "L" or "1".
    #
    # @param im The new alpha layer.  This can either be an "L" or "1"
    #    image having the same size as this image, or an integer or
    #    other color value.
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def _start(self, *args, **kwargs):
        new_pos = args[0]
        if operator.isSequenceType(new_pos):
            new_pos = new_pos[0]
        try:
            self.write_attribute('position', new_pos)
        except DevFailed as df:
            for err in df:
                if err.reason == 'API_AttrNotAllowed':
                    raise RuntimeError('%s is already moving' % self)
                else:
                    raise
        self.final_pos = new_pos
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def iterMove(self, new_pos, timeout=None):
        if operator.isSequenceType(new_pos):
            new_pos = new_pos[0]
        state, pos = self.getAttribute("state"), self.getAttribute("position")

        evt_wait = self._getEventWait()
        evt_wait.connect(state)
        evt_wait.lock()
        try:
            # evt_wait.waitEvent(DevState.MOVING, equal=False)
            time_stamp = time.time()
            try:
                self.getPositionObj().write(new_pos)
            except DevFailed as err_traceback:
                for err in err_traceback:
                    if err.reason == 'API_AttrNotAllowed':
                        raise RuntimeError('%s is already moving' % self)
                    else:
                        raise
            self.final_pos = new_pos
            # putting timeout=0.1 and retries=1 is a patch for the case when
            # the initial moving event doesn't arrive do to an unknown
            # tango/pytango error at the time
            evt_wait.waitEvent(DevState.MOVING, time_stamp,
                               timeout=0.1, retries=1)
        finally:
            evt_wait.unlock()
            evt_wait.disconnect()

        evt_iter_wait = AttributeEventIterator(state, pos)
        evt_iter_wait.lock()
        try:
            for evt_data in evt_iter_wait.events():
                src, value = evt_data
                if src == state and value != DevState.MOVING:
                    raise StopIteration
                yield value
        finally:
            evt_iter_wait.unlock()
            evt_iter_wait.disconnect()
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def _start(self, *args, **kwargs):
        new_pos = args[0]
        if operator.isSequenceType(new_pos):
            new_pos = new_pos[0]
        try:
            self.write_attribute('position', new_pos)
        except DevFailed, df:
            for err in df:
                if err.reason == 'API_AttrNotAllowed':
                    raise RuntimeError('%s is already moving' % self)
                else:
                    raise
        self.final_pos = new_pos
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def appendBuffer(self, d):
        if operator.isSequenceType(d):
            if isinstance(d, (str, unicode)):
                self._buff.append(d)
            else:
                self._buff.extend(d)
        else:
            self._buff.append(str(d))
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def to_dtype_dformat(data):
    """Transforms the given data parameter (string/ or sequence of string or
    sequence of sequence of string/:obj:`DataType`) into a tuple of two
    elements (:obj:`DataType`, :obj:`DataFormat`).

    :param data: the data information to be transformed
    :type data: str or seq<str> or seq<seq<str>>
    :return: a tuple <:obj:`DataType`, :obj:`DataFormat`> for the given data
    :rtype: tuple<:obj:`DataType`, :obj:`DataFormat`>
    """
    import operator
    dtype, dformat = data, DataFormat.Scalar
    if isinstance(data, (str, unicode)):
        dtype, dformat = from_dtype_str(data)
    elif operator.isSequenceType(data):
        dformat = DataFormat.OneD
        dtype = data[0]
        if isinstance(dtype, str):
            dtype, dformat2 = from_dtype_str(dtype)
            if dformat2 == DataFormat.OneD:
                dformat = DataFormat.TwoD
        elif operator.isSequenceType(dtype):
            dformat = DataFormat.TwoD
            dtype = dtype[0]
            if isinstance(dtype, str):
                dtype, _ = from_dtype_str(dtype)
    dtype = DTYPE_MAP.get(dtype, DataType.Invalid)
    return dtype, dformat
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def _outputBlock(self, line):
        """**Unofficial Macro API**.
        Sends a line tagged as a block to the output

        :param str line: line to be sent"""
        if isinstance(line, (str, unicode)):
            o = line
        elif operator.isSequenceType(line):
            o = "\n".join(line)
        else:
            o = str(line)
        self._output("%s\n%s\n%s" % (Macro.BlockStart, o, Macro.BlockFinish))
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def _reserveObjs(self, args):
        """**Internal method**. Used to reserve a set of objects for this
        macro"""
        for obj in args:
            # isiterable
            if not type(obj) in map(type, ([], ())):
                # if not operator.isSequenceType(obj) or type(obj) in
                # types.StringTypes:
                obj = (obj,)
            for sub_obj in obj:
                if isinstance(sub_obj, PoolElement):
                    self.addObj(sub_obj)
项目:sardana    作者:sardana-org    | 项目源码 | 文件源码
def __prepareResult(self, out):
        """**Internal method**. Decodes the given output in order to be able to
        send to the result channel

        :param out: output value

        :return: the output as a sequence of strings
        """
        if out is None:
            out = ()
        if operator.isSequenceType(out) and not type(out) in types.StringTypes:
            out = map(str, out)
        else:
            out = (str(out),)
        return out
项目:ngx_status    作者:YoYoAdorkable    | 项目源码 | 文件源码
def point(self, lut, mode=None):
        "Map image through lookup table"

        self.load()

        if not isSequenceType(lut):
            # if it isn't a list, it should be a function
            if self.mode in ("I", "I;16", "F"):
                # check if the function can be used with point_transform
                scale, offset = _getscaleoffset(lut)
                return self._new(self.im.point_transform(scale, offset))
            # for other modes, convert the function to a table
            lut = map(lut, range(256)) * self.im.bands

        if self.mode == "F":
            # FIXME: _imaging returns a confusing error message for this case
            raise ValueError("point operation not supported for this mode")

        return self._new(self.im.point(lut, mode))

    ##
    # Adds or replaces the alpha layer in this image.  If the image
    # does not have an alpha layer, it's converted to "LA" or "RGBA".
    # The new layer must be either "L" or "1".
    #
    # @param im The new alpha layer.  This can either be an "L" or "1"
    #    image having the same size as this image, or an integer or
    #    other color value.