droid
This commit is contained in:
@@ -13,6 +13,7 @@ from IPython.core.inputtransformer import *
|
||||
from IPython.core.interactiveshell import *
|
||||
from ipython_genutils.py3compat import builtin_mod
|
||||
|
||||
import copy
|
||||
import json
|
||||
|
||||
from yap_kernel.displayhook import ZMQShellDisplayHook
|
||||
@@ -535,13 +536,14 @@ class YAPRun(InteractiveShell):
|
||||
self.engine.mgoal(errors(self,text),"user",True)
|
||||
return self.errors
|
||||
|
||||
def prolog(self, program, squery, howmany, result):
|
||||
def prolog(self, ccell, result):
|
||||
|
||||
#
|
||||
# construct a self.query from a one-line string
|
||||
# self.q is opaque to Python
|
||||
try:
|
||||
# sys.settrace(tracefunc)
|
||||
(program, squery, _, howmany) = ccell
|
||||
if self.q and self.os == (program,squery):
|
||||
howmany += self.iterations
|
||||
else:
|
||||
@@ -551,7 +553,6 @@ class YAPRun(InteractiveShell):
|
||||
self.answers = []
|
||||
result.result = []
|
||||
self.os = (program,squery)
|
||||
self.iterations = 0
|
||||
pg = jupyter_query(self,program,squery)
|
||||
self.q = Query(self.engine, pg)
|
||||
for v in self.q:
|
||||
@@ -614,13 +615,6 @@ class YAPRun(InteractiveShell):
|
||||
`result : :class:`ExecutionResult`
|
||||
"""
|
||||
|
||||
if store_history:
|
||||
# Write output to the database. Does nothing unless
|
||||
# history output logging is enabled.
|
||||
self.shell.history_manager.store_output(self.shell.execution_count)
|
||||
# Each cell is a *single* input, regardless of how many lines it has
|
||||
self.shell.execution_count += 1
|
||||
|
||||
# construct a query from a one-line string
|
||||
# q is opaque to Python
|
||||
# vs is the list of variables
|
||||
@@ -656,6 +650,8 @@ class YAPRun(InteractiveShell):
|
||||
# # Display the exception if input processing failed.
|
||||
if preprocessing_exc_tuple is not None:
|
||||
self.showtraceback(preprocessing_exc_tuple)
|
||||
if store_history:
|
||||
self.shell.execution_count += 1
|
||||
return self.error_before_exec(preprocessing_exc_tuple[2])
|
||||
|
||||
# Our own compiler remembers the __future__ environment. If we want to
|
||||
@@ -665,7 +661,7 @@ class YAPRun(InteractiveShell):
|
||||
self.cell_name = str( self.shell.execution_count)
|
||||
self.shell.displayhook.exec_result= result
|
||||
cell = raw_cell.strip()
|
||||
while cell and cell[0] == '%':
|
||||
while cell[0] == '%':
|
||||
if cell[1] == '%':
|
||||
## cell magic
|
||||
txt0 = cell[2:].split(maxsplit = 1, sep = '\n')
|
||||
@@ -675,6 +671,7 @@ class YAPRun(InteractiveShell):
|
||||
except:
|
||||
magic = cell[2:].strip()
|
||||
body = ""
|
||||
linec = False
|
||||
try:
|
||||
[magic,line] = magic.split(maxsplit=1)
|
||||
except:
|
||||
@@ -683,6 +680,7 @@ class YAPRun(InteractiveShell):
|
||||
result.result = self.shell.run_cell_magic(magic, line, body)
|
||||
return
|
||||
else:
|
||||
linec = True
|
||||
rcell = cell[1:].strip()
|
||||
try:
|
||||
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
||||
@@ -699,8 +697,9 @@ class YAPRun(InteractiveShell):
|
||||
# Give the displayhook a reference to our ExecutionResult so it
|
||||
# can fill in the output value.
|
||||
self.shell.displayhook.exec_result = result
|
||||
(program,squery,_ ,howmany) = self.prolog_cell(cell)
|
||||
if howmany <= 0 and not program:
|
||||
ccell = self.prolog_cell(cell)
|
||||
(program,squery,_ ,howmany) = ccell
|
||||
if howmany == 0 and not program:
|
||||
return result
|
||||
if self.syntaxErrors(program+squery+".\n") :
|
||||
result.result = []
|
||||
@@ -724,7 +723,7 @@ class YAPRun(InteractiveShell):
|
||||
# run the new command using the given tracer
|
||||
#
|
||||
# tracer.runfunc(f,self,cell,state)
|
||||
answers = self.prolog( program, squery, howmany, result )
|
||||
answers = self.prolog( ccell, result )
|
||||
# state = tracer.runfunc(hist
|
||||
# er_query( self, cell ) )
|
||||
except Exception as e:
|
||||
@@ -732,7 +731,6 @@ class YAPRun(InteractiveShell):
|
||||
try:
|
||||
(etype, value, tb) = e
|
||||
traceback.print_exception(etype, value, tb)
|
||||
self.engine.mgoal(streams(False),"user", True)
|
||||
except:
|
||||
print(e)
|
||||
|
||||
@@ -745,26 +743,32 @@ class YAPRun(InteractiveShell):
|
||||
if not silent:
|
||||
self.shell.events.trigger('post_run_cell')
|
||||
|
||||
if store_history:
|
||||
# Write output to the database. Does nothing unless
|
||||
# history output logging is enabled.
|
||||
self.shell.history_manager.store_output(self.shell.execution_count)
|
||||
# Each cell is a *single* input, regardless of how many lines it has
|
||||
self.shell.execution_count += 1
|
||||
|
||||
self.engine.mgoal(streams(False),"user", True)
|
||||
return
|
||||
|
||||
|
||||
|
||||
def prolog_cell(self, s):
|
||||
return pcell(s)
|
||||
return cell_structure(s)
|
||||
|
||||
|
||||
def pcell(s):
|
||||
def cell_structure(s):
|
||||
"""
|
||||
Trasform a text into program+query. A query is the
|
||||
last line if the last line is non-empty and does not terminate
|
||||
on a dot. You can also finish with
|
||||
Trasform a text into program+query. A query is the
|
||||
last line if the last line is non-empty and does not terminate
|
||||
on a dot. You can also finish with
|
||||
|
||||
- `*`: you request all solutions
|
||||
- ';'[N]: you want an answer; optionally you want N answers
|
||||
- `*`: you request all solutions
|
||||
- ';'[N]: you want an answer; optionally you want N answers
|
||||
|
||||
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||
is a comment.
|
||||
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||
is a comment.
|
||||
"""
|
||||
try:
|
||||
sl = s.splitlines()
|
||||
@@ -780,32 +784,35 @@ def pcell(s):
|
||||
if line[-1] == '.':
|
||||
return (s,'','.',0)
|
||||
query = ''
|
||||
loop = ''
|
||||
while i<l:
|
||||
line = sl[-i-1]
|
||||
if line.strip() == '':
|
||||
break
|
||||
query = line+'\n'+query
|
||||
query = line+'\n\n'+query
|
||||
i+=1
|
||||
reps = 1
|
||||
reps = 1
|
||||
if query:
|
||||
q = query.strip()
|
||||
c= q.rpartition('?')
|
||||
if not c[1]:
|
||||
c= q.rpartition(';')
|
||||
c= q.rpartition('*')
|
||||
c2 = c[2].strip()
|
||||
if c[1] != '*' or (c2!='' and not c2.isdecimal()):
|
||||
c = q.rpartition('?')
|
||||
c2 = c[2].strip()
|
||||
if len(c[1]) == 1 and c[0].strip():
|
||||
c2 = c[2].strip()
|
||||
query = c[0]
|
||||
if c2.isdecimal():
|
||||
reps = int(c2)
|
||||
elif c2:
|
||||
return ('',c[1]+c[2],c[1],-1)
|
||||
elif c[1] == '?':
|
||||
reps = 1
|
||||
if c[1] == '?' and(c2=='' or c2.isdecimal()):
|
||||
c = q.rpartition(';')
|
||||
c2 = c[2].strip()
|
||||
else:
|
||||
reps = 10000000000
|
||||
loop = c[1]
|
||||
c=('','',query)
|
||||
[q,loop,repeats] = c
|
||||
if q:
|
||||
query=q
|
||||
if repeats.strip().isdecimal():
|
||||
reps = int(repeats)
|
||||
sep = sepator
|
||||
elif loop == '*':
|
||||
reps = -1
|
||||
elif loop == '?':
|
||||
reps = 10
|
||||
while i<l:
|
||||
line = sl[-i-1]
|
||||
if line.strip() != '':
|
||||
@@ -821,10 +828,6 @@ def pcell(s):
|
||||
try:
|
||||
(etype, value, tb) = e
|
||||
traceback.print_exception(etype, value, tb)
|
||||
return ('','','',-1)
|
||||
except:
|
||||
print(e)
|
||||
return ('','','',-1)
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user