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)
| 1073 | ).tag(config=True) |
| 1074 | |
| 1075 | def __init__(self, namespace=None, global_namespace=None, **kwargs): |
| 1076 | """Create a new completer for the command line. |
| 1077 | |
| 1078 | Completer(namespace=ns, global_namespace=ns2) -> completer instance. |
| 1079 | |
| 1080 | If unspecified, the default namespace where completions are performed |
| 1081 | is __main__ (technically, __main__.__dict__). Namespaces should be |
| 1082 | given as dictionaries. |
| 1083 | |
| 1084 | An optional second namespace can be given. This allows the completer |
| 1085 | to handle cases where both the local and global scopes need to be |
| 1086 | distinguished. |
| 1087 | """ |
| 1088 | |
| 1089 | # Don't bind to namespace quite yet, but flag whether the user wants a |
| 1090 | # specific namespace or to use __main__.__dict__. This will allow us |
| 1091 | # to bind to __main__.__dict__ at completion time, not now. |
| 1092 | if namespace is None: |
| 1093 | self.use_main_ns = True |
| 1094 | else: |
| 1095 | self.use_main_ns = False |
| 1096 | self.namespace = namespace |
| 1097 | |
| 1098 | # The global namespace, if given, can be bound directly |
| 1099 | if global_namespace is None: |
| 1100 | self.global_namespace = {} |
| 1101 | else: |
| 1102 | self.global_namespace = global_namespace |
| 1103 | |
| 1104 | self.custom_matchers = [] |
| 1105 | |
| 1106 | super(Completer, self).__init__(**kwargs) |
| 1107 | |
| 1108 | def complete(self, text, state): |
| 1109 | """Return the next possible completion for 'text'. |