python类isSequenceType()的实例源码

test_bool.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)
test_bool.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)
test_bool.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)
test_bool.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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)
output.py 文件源码 项目:sardana 作者: sardana-org 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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
msenvmanager.py 文件源码 项目:sardana 作者: sardana-org 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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
server.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
pyutils.py 文件源码 项目:rTensor 作者: erichson 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
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)
objects.py 文件源码 项目:fandango 作者: tango-controls 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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)
arrays.py 文件源码 项目:fandango 作者: tango-controls 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)
test_operator.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
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()))
test_operator.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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()))
server.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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
cpp_message.py 文件源码 项目:protoc-gen-lua-bin 作者: u0u0 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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)]
cpp_message.py 文件源码 项目:protoc-gen-lua-bin 作者: u0u0 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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)]
cpp_message.py 文件源码 项目:protoc-gen-lua-bin 作者: u0u0 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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)]
cpp_message.py 文件源码 项目:protoc-gen-lua-bin 作者: u0u0 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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)]
cpp_message.py 文件源码 项目:bigmuddy-network-telemetry-collector 作者: cisco 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def is_sequence(other):
        return operator.isSequenceType(other)
test_operator.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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()))
test_operator.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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()))
cpp_message.py 文件源码 项目:Chromium_DepotTools 作者: p07r0457 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
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)]
PluginMovieAmazon.py 文件源码 项目:griffith 作者: Strit 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
PluginMovieAmazon.py 文件源码 项目:griffith 作者: Strit 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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 = ', '
PluginMovieAmazon.py 文件源码 项目:griffith 作者: Strit 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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 = ', '
cpp_message.py 文件源码 项目:node-gn 作者: Shouqun 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
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)]
svm.py 文件源码 项目:PCInotes 作者: ahangchen 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
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
Image.py 文件源码 项目:CNCGToolKit 作者: cineuse 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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.
cpp_message.py 文件源码 项目:depot_tools 作者: webrtc-uwp 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:image-occlusion-enhanced 作者: glutanimate 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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.
Image.py 文件源码 项目:InstagramPosting 作者: LeviParadis 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
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.


问题


面经


文章

微信
公众号

扫码关注公众号