Exemplo n.º 1
0
 def __iter__(self):
     from types import GeneratorType
     try:
         result = super(new_meta, self).__iter__()
     except AttributeError:
         result = Unset
     if isinstance(result, GeneratorType):
         for item in result:
             yield item
     elif result is Unset:
         from xotl.ql.expressions import is_instance
         query_part = next(iter(this(name)))
         is_instance(query_part, self)
         yield query_part
     else:
         raise TypeError('Class {target} has a metaclass with an '
                         '__iter__ that does not support thesefy'
                         .format(target=target))
Exemplo n.º 2
0
    def _test_class(self, Person):
        from xotl.ql.expressions import is_instance

        q = these((who for who in Person if who.age > 30), limit=100)
        # We assume that Person has been thesefied with thesefy('Person')
        who = domain = this('Person')
        q1 = these(w for w in domain if is_instance(w, Person) if w.age > 30)

        is_filter = is_instance(who, Person)
        age_filter = who.age > 30
        with context(UNPROXIFING_CONTEXT):
            self.assertEqual(2, len(q.filters))
            self.assertEqual(2, len(q1.filters))
            self.assertIn(is_filter, q.filters)
            self.assertIn(is_filter, q1.filters)
            self.assertIn(age_filter, q.filters)
            self.assertIn(age_filter, q1.filters)

            self.assertEqual(q.selection, q1.selection)
            self.assertEqual(q.tokens, q1.tokens)
Exemplo n.º 3
0
 def __iter__(self):
     from types import GeneratorType
     try:
         result = super(new_meta, self).__iter__()
     except AttributeError:
         result = Unset
     if isinstance(result, GeneratorType):
         for item in result:
             yield item
     elif result is not Unset and IQueryPart.providedBy(result):
         yield result
     elif result is Unset:
         from xotl.ql.expressions import is_instance
         query_part = next(iter(this(name)))
         is_instance(query_part, self)
         yield query_part
     else:
         raise TypeError(
             'Class {target} has a metaclass with an '
             '__iter__ that does not support thesefy'.format(
                 target=target))
Exemplo n.º 4
0
    def _test_class(self, Person):
        from xotl.ql.expressions import is_instance

        q = these((who for who in Person if who.age > 30),
                  limit=100)
        # We assume that Person has been thesefied with thesefy('Person')
        who = domain = this('Person')
        q1 = these(w for w in domain if is_instance(w, Person)
                        if w.age > 30)

        is_filter = is_instance(who, Person)
        age_filter = who.age > 30
        with context(UNPROXIFING_CONTEXT):
            self.assertEqual(2, len(q.filters))
            self.assertEqual(2, len(q1.filters))
            self.assertIn(is_filter, q.filters)
            self.assertIn(is_filter, q1.filters)
            self.assertIn(age_filter, q.filters)
            self.assertIn(age_filter, q1.filters)

            self.assertEqual(q.selection, q1.selection)
            self.assertEqual(q.tokens, q1.tokens)