Compute matches when text contains a dot. Assuming the text is of the form NAME.NAME....[NAME], and is evaluatable in self.namespace or self.global_namespace, it will be evaluated and its attributes (as revealed by dir()) are used as possible completions. (For class
(self, text)
| 679 | return matches |
| 680 | |
| 681 | def attr_matches(self, text): |
| 682 | """Compute matches when text contains a dot. |
| 683 | |
| 684 | Assuming the text is of the form NAME.NAME....[NAME], and is |
| 685 | evaluatable in self.namespace or self.global_namespace, it will be |
| 686 | evaluated and its attributes (as revealed by dir()) are used as |
| 687 | possible completions. (For class instances, class members are |
| 688 | also considered.) |
| 689 | |
| 690 | WARNING: this can still invoke arbitrary C code, if an object |
| 691 | with a __getattr__ hook is evaluated. |
| 692 | |
| 693 | """ |
| 694 | |
| 695 | # Another option, seems to work great. Catches things like ''.<tab> |
| 696 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
| 697 | |
| 698 | if m: |
| 699 | expr, attr = m.group(1, 3) |
| 700 | elif self.greedy: |
| 701 | m2 = re.match(r"(.+)\.(\w*)$", self.line_buffer) |
| 702 | if not m2: |
| 703 | return [] |
| 704 | expr, attr = m2.group(1,2) |
| 705 | else: |
| 706 | return [] |
| 707 | |
| 708 | try: |
| 709 | obj = eval(expr, self.namespace) |
| 710 | except: |
| 711 | try: |
| 712 | obj = eval(expr, self.global_namespace) |
| 713 | except: |
| 714 | return [] |
| 715 | |
| 716 | if self.limit_to__all__ and hasattr(obj, '__all__'): |
| 717 | words = get__all__entries(obj) |
| 718 | else: |
| 719 | words = dir2(obj) |
| 720 | |
| 721 | try: |
| 722 | words = generics.complete_object(obj, words) |
| 723 | except TryNext: |
| 724 | pass |
| 725 | except AssertionError: |
| 726 | raise |
| 727 | except Exception: |
| 728 | # Silence errors from completion function |
| 729 | #raise # dbg |
| 730 | pass |
| 731 | # Build match list to return |
| 732 | n = len(attr) |
| 733 | return [u"%s.%s" % (expr, w) for w in words if w[:n] == attr ] |
| 734 | |
| 735 | |
| 736 | def get__all__entries(obj): |
no test coverage detected