test
Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
PhysicsTools
PythonAnalysis
python
cmscompleter.py
Go to the documentation of this file.
1
"""Word completion for CMS Software.
2
Based on rlcompleter from Python 2.4.1. Included additional namespace for not loaded modules
3
Please read license in your lcg external python version
4
5
benedikt.hegner@cern.ch
6
7
"""
8
from
__future__
import
absolute_import
9
# TODO: sometimes results are doubled. clean global_matches list!
10
11
import
readline
12
import
rlcompleter
13
import
__builtin__
14
import
__main__
15
16
__all__ = [
"CMSCompleter"
]
17
18
class
CMSCompleter
(rlcompleter.Completer):
19
def
__init__
(self, namespace = None):
20
21
if
namespace
and
not
isinstance(namespace, dict):
22
raise
TypeError(
'namespace must be a dictionary'
)
23
24
# Don't bind to namespace quite yet, but flag whether the user wants a
25
# specific namespace or to use __main__.__dict__. This will allow us
26
# to bind to __main__.__dict__ at completion time, not now.
27
if
namespace
is
None
:
28
self.
use_main_ns
= 1
29
else
:
30
self.
use_main_ns
= 0
31
self.
namespace
= namespace
32
try
:
33
# loading cms namespace
34
from
.
import
namespaceDict
35
self.
cmsnamespace
= namespaceDict.getNamespaceDict()
36
except
:
37
print
'Could not load CMS namespace'
38
39
40
def
global_matches
(self, text):
41
"""Compute matches when text is a simple name.
42
43
Return a list of all keywords, built-in functions and names currently
44
defined in self.namespace and self.cmsnamespace that match.
45
46
"""
47
import
keyword
48
matches = []
49
n = len(text)
50
for
list
in
[keyword.kwlist,
51
__builtin__.__dict__,
52
self.
cmsnamespace
]:
53
for
word
in
list:
54
if
word[:n] == text
and
word !=
"__builtins__"
:
55
matches.append(word)
56
return
matches
57
58
# connect CMSCompleter with readline
59
readline.set_completer(
CMSCompleter
().complete)
60
readline.parse_and_bind(
'tab: complete'
)
61
62
python.cmscompleter.CMSCompleter.use_main_ns
use_main_ns
Definition:
cmscompleter.py:28
python.cmscompleter.CMSCompleter.global_matches
def global_matches
Definition:
cmscompleter.py:40
python.cmscompleter.CMSCompleter.namespace
namespace
Definition:
cmscompleter.py:31
python.cmscompleter.CMSCompleter.__init__
def __init__
Definition:
cmscompleter.py:19
python.cmscompleter.CMSCompleter.cmsnamespace
cmsnamespace
Definition:
cmscompleter.py:35
python.cmscompleter.CMSCompleter
Definition:
cmscompleter.py:18
Generated for CMSSW Reference Manual by
1.8.5