Example #1
0
 def do(self, rhs, made_rhs_call, call_pos, quick_classes, quick_defs, result_should_be, rhs_ref_to_class_should_be, imports):
     for mode in self.modes:
         v = self.get_visitor(rhs, mode)
         v.made_rhs_call = made_rhs_call
         v.quick_parse.quick_found_classes = quick_classes
         v.quick_parse.quick_found_module_defs = quick_defs
         v.pos_rhs_call_pre_first_bracket = call_pos
         v.imports_encountered = imports
         
         ra = RhsAnalyser(v)
         self.assertEqual(ra.is_rhs_reference_to_a_class(), result_should_be)
         self.assertEqual(ra.rhs_ref_to_class,              rhs_ref_to_class_should_be)
Example #2
0
        def flush(self):
            self.flush_state(whosgranddaddy())

            # At this point we have both lhs and rhs plus three flags and can
            # make a decision about what to create.

            def create_attr_static(t):
                self.current_class().AddAttribute(attrname=t,
                                                  attrtype=['static'])
                return t

            def create_attr(t):
                if (t == '__class__') and len(self.lhs) >= 3:
                    t = self.lhs[2]
                    self.current_class().AddAttribute(attrname=t,
                                                      attrtype=['static'])
                else:
                    self.current_class().AddAttribute(attrname=t,
                                                      attrtype=['normal'])
                return t

            def create_attr_many(t):
                self.current_class().AddAttribute(attrname=t,
                                                  attrtype=['normal', 'many'])
                return t

            def create_attr_please(t):
                if self.made_append_call:
                    t = create_attr_many(t)
                else:
                    t = create_attr(t)
                return t

            if self.made_assignment or self.made_append_call:

                if self.in_class_static_area():
                    t = create_attr_static(self.lhs[0])
                elif self.in_method_in_class_area(
                ) and self.lhs[0] == 'self' and len(self.lhs) > 1:
                    t = create_attr_please(self.lhs[1])
                else:
                    pass  # in module area

                if self.lhs[0] == 'self' and len(self.rhs) > 0:
                    ra = RhsAnalyser(visitor=self)
                    if ra.is_rhs_reference_to_a_class():
                        self.add_composite_dependency((t, ra.rhs_ref_to_class))

            self.init_lhs_rhs()
            #self.flush_state()
            self.write("<hr>", mynote=2)
Example #3
0
    def flush(self):
        """
            Flush is called after:
                * newlines,
                * ends of classes
                * end of functions
                * should be more?

            It is only interested in whether an assignment has been made or an append call has been made
            in order to create the relevant attribute and type (one or many).
            """

        if DEBUGINFO():
            # this is cripplingly slow when bundled in pyinstaller
            self.flush_state(whosgranddaddy())
        else:
            self.flush_state("")

        # At this point we have both lhs and rhs plus three flags and can
        # make a decision about what to create.

        def create_attr_static(t):
            self.current_class().AddAttribute(attrname=t, attrtype=["static"])
            return t

        def create_attr(t):
            if (t == "__class__") and len(self.lhs) >= 3:
                t = self.lhs[2]
                self.current_class().AddAttribute(attrname=t,
                                                  attrtype=["static"])
            else:
                self.current_class().AddAttribute(attrname=t,
                                                  attrtype=["normal"])
            return t

        def create_attr_many(t):
            self.current_class().AddAttribute(attrname=t,
                                              attrtype=["normal", "many"])
            return t

        def create_attr_please(t):
            if self.made_append_call:
                t = create_attr_many(t)
            else:
                t = create_attr(t)
            return t

        if self.made_assignment or self.made_append_call:

            if self.in_class_static_area():
                t = create_attr_static(self.lhs[0])
            elif self.in_method_in_class_area(
            ) and self.lhs[0] == "self" and len(self.lhs) > 1:
                t = create_attr_please(self.lhs[1])
            else:
                pass  # in module area

            if self.lhs[0] == "self" and len(self.rhs) > 0:
                ra = RhsAnalyser(visitor=self)
                if ra.is_rhs_reference_to_a_class():
                    self.add_composite_dependency((t, ra.rhs_ref_to_class))

        self.init_lhs_rhs()
        # self.flush_state()
        self.write("<hr>", mynote=2)