GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Data Fields
pycons.shell.Shell Class Reference

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.

43 
44  def __init__(self, ns_globals={}, ns_locals={}):
45  """ """
46 
47  self.completer = rlcompleter.Completer (ns_globals)
48  self.command = ''
49  self.globals = ns_globals
50  self.locals = ns_locals
51  self.complete_sep = re.compile('[\s\{\}\[\]\(\)]')
52  self.prompt = sys.ps1
53 

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.

57 
58  def is_balanced (self, line):
59  """ Checks line balance for brace, bracket, parenthese and string quote
60 
61  This helper function checks for the balance of brace, bracket,
62  parenthese and string quote. Any unbalanced line means to wait until
63  some other lines are fed to the console.
64  """
65 
66  s = line
67  s = filter(lambda x: x in '()[]{}"\'', s)
68  s = s.replace ("'''", "'")
69  s = s.replace ('"""', '"')
70  instring = False
71  brackets = {'(':')', '[':']', '{':'}', '"':'"', '\'':'\''}
72  stack = []
73  while len(s):
74  if not instring:
75  if s[0] in ')]}':
76  if stack and brackets[stack[-1]] == s[0]:
77  del stack[-1]
78  else:
79  return False
80  elif s[0] in '"\'':
81  if stack and brackets[stack[-1]] == s[0]:
82  del stack[-1]
83  instring = False
84  else:
85  stack.append(s[0])
86  instring = True
87  else:
88  stack.append(s[0])
89  else:
90  if s[0] in '"\'' and stack and brackets[stack[-1]] == s[0]:
91  del stack[-1]
92  instring = False
93  s = s[1:]
94  return len(stack) == 0
95 

The documentation for this class was generated from the following file: