GnuCash  5.6-150-g038405b370+
Public Member Functions | Data Fields
pycons.shell.Shell Class Reference

Public Member Functions

def __init__ (self, ns_globals={}, ns_locals={})
 
def namespace (self)
 
def is_balanced (self, line)
 
def complete (self, line)
 
def eval (self, console)
 
def execute (self, console)
 

Data Fields

 completer
 
 command
 
 globals
 
 locals
 
 complete_sep
 
 prompt
 

Detailed Description

 

Definition at line 40 of file shell.py.

Constructor & Destructor Documentation

◆ __init__()

def pycons.shell.Shell.__init__ (   self,
  ns_globals = {},
  ns_locals = {} 
)
 

Definition at line 43 of file shell.py.

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

Member Function Documentation

◆ is_balanced()

def pycons.shell.Shell.is_balanced (   self,
  line 
)
Checks line balance for brace, bracket, parentheses and string quote

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

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