示例#1
0
    def flatmatches(self, t):
        """Flattens t and then sees if any part of it matches self.pattern.
        """
        try:
            # See if user gave entire type
            if self.matches(t):
                return True
        except TypeError:
            # This might fail, if it does just move on
            pass

        else:
            if isinstance(t, basestring):
                return self.matches(t)
            elif isinstance(t, (tuple, list)):
                return any([self.matches(i) for i in flatten(t)])
示例#2
0
    def flatmatches(self, t):
        """Flattens t and then sees if any part of it matches self.pattern.
        """
        try:
            # See if user gave entire type
            if self.matches(t):
                return True
        except TypeError:
            # This might fail, if it does just move on
            pass

        else:
            if isinstance(t, basestring):
                return self.matches(t)
            elif isinstance(t, (tuple, list)):
                return any([self.matches(i) for i in flatten(t)])
示例#3
0
def test_flatten():
    exp = ["hello", None, 1, 3, 2, 5, 6]
    obs = [x for x in flatten(["hello", None, (1, 3, (2, 5, 6))])]
    assert_equal(exp, obs)
示例#4
0
def test_flatten():
    exp = ["hello", None, 1, 3, 2, 5, 6]
    obs = [x for x in flatten(["hello", None, (1, 3, (2, 5, 6))])]
    assert_equal(exp, obs)