Create a new completer for the command line. Completer(namespace=ns, global_namespace=ns2) -> completer instance. If unspecified, the default namespace where completions are performed is __main__ (technically, __main__.__dict__). Namespaces should be given as dictio
(self, namespace=None, global_namespace=None, **kwargs)
| 598 | |
| 599 | |
| 600 | def __init__(self, namespace=None, global_namespace=None, **kwargs): |
| 601 | """Create a new completer for the command line. |
| 602 | |
| 603 | Completer(namespace=ns, global_namespace=ns2) -> completer instance. |
| 604 | |
| 605 | If unspecified, the default namespace where completions are performed |
| 606 | is __main__ (technically, __main__.__dict__). Namespaces should be |
| 607 | given as dictionaries. |
| 608 | |
| 609 | An optional second namespace can be given. This allows the completer |
| 610 | to handle cases where both the local and global scopes need to be |
| 611 | distinguished. |
| 612 | """ |
| 613 | |
| 614 | # Don't bind to namespace quite yet, but flag whether the user wants a |
| 615 | # specific namespace or to use __main__.__dict__. This will allow us |
| 616 | # to bind to __main__.__dict__ at completion time, not now. |
| 617 | if namespace is None: |
| 618 | self.use_main_ns = True |
| 619 | else: |
| 620 | self.use_main_ns = False |
| 621 | self.namespace = namespace |
| 622 | |
| 623 | # The global namespace, if given, can be bound directly |
| 624 | if global_namespace is None: |
| 625 | self.global_namespace = {} |
| 626 | else: |
| 627 | self.global_namespace = global_namespace |
| 628 | |
| 629 | self.custom_matchers = [] |
| 630 | |
| 631 | super(Completer, self).__init__(**kwargs) |
| 632 | |
| 633 | def complete(self, text, state): |
| 634 | """Return the next possible completion for 'text'. |