Public Member Functions |
| def | __init__ |
|
def | namespace |
| def | is_balanced |
|
def | complete |
|
def | eval |
|
def | execute |
Data Fields |
|
| completer |
|
| command |
|
| globals |
|
| locals |
|
| complete_sep |
|
| prompt |
Detailed Description
Definition at line 40 of file shell.py.
Constructor & Destructor Documentation
| def pycons::shell::Shell::__init__ |
( |
|
self, |
|
|
|
ns_globals = {}, |
|
|
|
ns_locals = {} |
|
) |
| |
Definition at line 43 of file shell.py.
00043 {}, ns_locals={}):
00044 """ """
00045
00046 self.completer = rlcompleter.Completer (ns_globals)
00047 self.command = ''
00048 self.globals = ns_globals
00049 self.locals = ns_locals
00050 self.complete_sep = re.compile('[\s\{\}\[\]\(\)]')
00051 self.prompt = sys.ps1
00052
00053
Member Function Documentation
| def pycons::shell::Shell::is_balanced |
( |
|
self, |
|
|
|
line |
|
) |
| |
Checks line balance for brace, bracket, parenthese and string quote
This helper function checks for the balance of brace, bracket,
parenthese and string quote. Any unbalanced line means to wait until
some other lines are fed to the console.
Definition at line 57 of file shell.py.
00058 :
00059 """ Checks line balance for brace, bracket, parenthese and string quote
00060
00061 This helper function checks for the balance of brace, bracket,
00062 parenthese and string quote. Any unbalanced line means to wait until
00063 some other lines are fed to the console.
00064 """
00065
00066 s = line
00067 s = filter(lambda x: x in '()[]{}"\'', s)
00068 s = s.replace ("'''", "'")
00069 s = s.replace ('"""', '"')
00070 instring = False
00071 brackets = {'(':')', '[':']', '{':'}', '"':'"', '\'':'\''}
00072 stack = []
00073 while len(s):
00074 if not instring:
00075 if s[0] in ')]}':
00076 if stack and brackets[stack[-1]] == s[0]:
00077 del stack[-1]
00078 else:
00079 return False
00080 elif s[0] in '"\'':
00081 if stack and brackets[stack[-1]] == s[0]:
00082 del stack[-1]
00083 instring = False
00084 else:
00085 stack.append(s[0])
00086 instring = True
00087 else:
00088 stack.append(s[0])
00089 else:
00090 if s[0] in '"\'' and stack and brackets[stack[-1]] == s[0]:
00091 del stack[-1]
00092 instring = False
00093 s = s[1:]
00094 return len(stack) == 0
00095
The documentation for this class was generated from the following file: