"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "modules/pymol/parsing.py" between
pymol-v1.8.6.0.tar.bz2 and pymol-v2.1.0.tar.bz2

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

parsing.py  (pymol-v1.8.6.0.tar.bz2):parsing.py  (pymol-v2.1.0.tar.bz2)
skipping to change at line 74 skipping to change at line 74
# Don't import __future__.print_function # Don't import __future__.print_function
if __name__=='pymol.parsing': if __name__=='pymol.parsing':
import re import re
import sys import sys
import threading import threading
import types import types
import traceback import traceback
import inspect import inspect
from . import colorprinting
class QuietException(BaseException): class QuietException(BaseException):
pass pass
# constants for keyword modes # constants for keyword modes
SIMPLE = 0 # original pymol parsing (deprecated) SIMPLE = 0 # original pymol parsing (deprecated)
MOVIE = 1 # ignore ";", treat entire line as a single command MOVIE = 1 # ignore ";", treat entire line as a single command
RUN = 2 # run command RUN = 2 # run command
SPAWN = 3 # for spawn and fork commands SPAWN = 3 # for spawn and fork commands
skipping to change at line 148 skipping to change at line 149
if a[0] == None: if a[0] == None:
result.append(a[1]) result.append(a[1])
c = c + 1 c = c + 1
continue continue
if p in inp_dict: if p in inp_dict:
result.append(inp_dict[p]) result.append(inp_dict[p])
del inp_dict[p] del inp_dict[p]
elif p in def_dict: elif p in def_dict:
result.append(def_dict[p]) result.append(def_dict[p])
elif c<n_req: elif c<n_req:
print("Error: invalid argument(s).") raise QuietException("Error: invalid argument(s).")
raise QuietException
c = c + 1 c = c + 1
if len(inp_dict): if len(inp_dict):
print("Error: invalid argument(s).") raise QuietException("Error: invalid argument(s).")
raise QuietException
return result return result
def parse_arg(st,mode=STRICT,_self=None): def parse_arg(st,mode=STRICT,_self=None):
''' '''
parse_arg(st) parse_arg(st)
expects entire command to be passed in expects entire command to be passed in
returns list of tuples of strings: [(None,value),(name,value)...] returns list of tuples of strings: [(None,value),(name,value)...]
''' '''
skipping to change at line 220 skipping to change at line 219
if mo: if mo:
post_nester = mo.group(0) post_nester = mo.group(0)
cc=cc+mo.end(0) cc=cc+mo.end(0)
nest_str = nest_str + post_nester nest_str = nest_str + post_nester
nest_flag = 1 # one more cycle nest_flag = 1 # one more cycle
else: else:
mo = arg_hard_nester_re.match(st[cc:]) mo = arg_hard_nester_re.match(st[cc:])
if mo: if mo:
se = trim_nester(mo.group(0)) se = trim_nester(mo.group(0))
if se==None: if se==None:
print("Error: "+st) colorprinting.error("Error: "+st)
print("Error: "+" "*cc+"^ syntax error (type colorprinting.error("Error: "+" "*cc+"^ synt
1).") ax error (type 1).")
raise QuietException raise QuietException
else: else:
cc = cc + len(se) cc = cc + len(se)
nest_str = nest_str + se nest_str = nest_str + se
# text after nester? # text after nester?
mo = arg_post_nester_re.match(st[cc:]) mo = arg_post_nester_re.match(st[cc:])
if mo: if mo:
nest_str = nest_str + mo.group(0) nest_str = nest_str + mo.group(0)
cc=cc+mo.end(0) cc=cc+mo.end(0)
nest_flag = 1 # one more cycle nest_flag = 1 # one more cycle
if not len(nest_str): # we must have failed to parse... if not len(nest_str): # we must have failed to parse...
skip_flag = 0 skip_flag = 0
else: else:
result.append((nam, nest_str.strip())) result.append((nam, nest_str.strip()))
if not skip_flag: if not skip_flag:
# no nester, so just read normal argument value # no nester, so just read normal argument value
argval = None argval = None
mo = arg_value_re.match(st[cc:]) mo = arg_value_re.match(st[cc:])
if not mo: if not mo:
if(st[cc:cc+1]!=','): if(st[cc:cc+1]!=','):
print("Error: "+st) colorprinting.error("Error: "+st)
print("Error: "+" "*cc+"^ syntax error (type 2).") colorprinting.error("Error: "+" "*cc+"^ syntax error
(type 2).")
raise QuietException raise QuietException
else: else:
# allow blank arguments # allow blank arguments
result.append((nam,None)) result.append((nam,None))
else: else:
argval = mo.group(0) argval = mo.group(0)
cc=cc+mo.end(0) cc=cc+mo.end(0)
while 1: # pickup unqouted characters after quotes while 1: # pickup unqouted characters after quotes
mo = arg_value_re.match(st[cc:]) mo = arg_value_re.match(st[cc:])
if not mo: if not mo:
skipping to change at line 267 skipping to change at line 266
if argval!=None: if argval!=None:
result.append((nam, argval.strip())) result.append((nam, argval.strip()))
# clean whitespace # clean whitespace
st = st[cc:].lstrip() st = st[cc:].lstrip()
cc = 0 cc = 0
# skip over comma # skip over comma
if st != '': if st != '':
if st.startswith(','): if st.startswith(','):
st = st[1:].lstrip() st = st[1:].lstrip()
else: else:
print("Error: "+st) colorprinting.error("Error: "+st)
print("Error: "+" "*cc+"^ syntax error (type 3).") colorprinting.error("Error: "+" "*cc+"^ syntax error (ty
pe 3).")
raise QuietException raise QuietException
if __name__!='__main__': if __name__!='__main__':
if _self._feedback(_self.fb_module.parser, _self.fb_mask.debugging): if _self._feedback(_self.fb_module.parser, _self.fb_mask.debugging):
_self.fb_debug.write(" parsing-DEBUG: tup: "+str(result)+"\n") _self.fb_debug.write(" parsing-DEBUG: tup: "+str(result)+"\n")
return result return result
def dump_str_list(list): def dump_str_list(list):
lst = list_to_str_list(list) lst = list_to_str_list(list)
for a in lst: for a in lst:
print(a) print(a)
skipping to change at line 396 skipping to change at line 395
if a[0] not in arg_dct: if a[0] not in arg_dct:
tmp_lst.extend([(None,a[0]),(None,a[1])]) tmp_lst.extend([(None,a[0]),(None,a[1])])
else: else:
tmp_lst.append(a) tmp_lst.append(a)
else: else:
tmp_lst.append(a) tmp_lst.append(a)
lst = tmp_lst lst = tmp_lst
# make sure we don't have too many arguments # make sure we don't have too many arguments
if len(lst)>narg: if len(lst)>narg:
if not narg: if not narg:
print("Error: too many arguments for %s; None expected."%(na me)) colorprinting.error("Error: too many arguments for %s; None expected."%(name))
elif narg==nreq: elif narg==nreq:
print("Error: too many arguments for %s; %d expected, %d fou nd."%( colorprinting.error("Error: too many arguments for %s; %d ex pected, %d found."%(
name,nreq,len(lst))) name,nreq,len(lst)))
dump_arg(name,arg_nam,nreq) dump_arg(name,arg_nam,nreq)
else: else:
print("Error: too many arguments for %s; %d to %d expected, %d found."%( colorprinting.error("Error: too many arguments for %s; %d to %d expected, %d found."%(
name,nreq,narg,len(lst))) name,nreq,narg,len(lst)))
dump_arg(name,arg_nam,nreq) dump_arg(name,arg_nam,nreq)
raise QuietException raise QuietException
# match names to unnamed arguments to create argument dictionary # match names to unnamed arguments to create argument dictionary
ac = 0 ac = 0
val_dct = {} val_dct = {}
for a in lst: for a in lst:
if a[0]==None: if a[0]==None:
if ac>=narg: if ac>=narg:
print("Parsing-Error: ambiguous argument: '"+str(a[1])+" raise QuietException("Parsing-Error: ambiguous argument:
'") '"+str(a[1])+"'")
raise QuietException
else: else:
val_dct[arg_nam[ac]]=a[1] val_dct[arg_nam[ac]]=a[1]
else: else:
val_dct[a[0]]=a[1] val_dct[a[0]]=a[1]
ac = ac + 1 ac = ac + 1
# now check to make sure we don't have any missing arguments # now check to make sure we don't have any missing arguments
for a in arg_nam: for a in arg_nam:
if arg_dct[a]: if arg_dct[a]:
if a not in val_dct: if a not in val_dct:
print("Parsing-Error: missing required argument in funct raise QuietException("Parsing-Error: missing required ar
ion %s : %s" % (name, a)) gument in function %s : %s" % (name, a))
raise QuietException
# return all arguments as keyword arguments # return all arguments as keyword arguments
kw = val_dct kw = val_dct
# set feedback argument (quiet), if extant, results enabled, and not overridden # set feedback argument (quiet), if extant, results enabled, and not overridden
if "quiet" in arg_dct: if "quiet" in arg_dct:
if "quiet" not in kw: if "quiet" not in kw:
if _self._feedback(_self.fb_module.cmd, _self.fb_mask.result s): if _self._feedback(_self.fb_module.cmd, _self.fb_mask.result s):
kw["quiet"] = 0 kw["quiet"] = 0
# make sure command knows which PyMOL instance to message # make sure command knows which PyMOL instance to message
if "_self" in arg_nam: if "_self" in arg_nam:
if "_self" not in kw: if "_self" not in kw:
skipping to change at line 524 skipping to change at line 521
The best way to spawn processes at startup is to use the -l option The best way to spawn processes at startup is to use the -l option
(see "help launching"). (see "help launching").
SEE ALSO SEE ALSO
run run
''' '''
return run(filename, namespace, 1, _self) return run(filename, namespace, 1, _self)
def _print_exc():
colorprinting.print_exc([__file__])
def execfile(filename, global_ns, local_ns): def execfile(filename, global_ns, local_ns):
import pymol.internal as pi import pymol.internal as pi
co = compile(pi.file_read(filename), filename, 'exec') co = compile(pi.file_read(filename), filename, 'exec')
exec(co, global_ns, local_ns) exec(co, global_ns, local_ns)
def run_file(file,global_ns,local_ns): def run_file(file,global_ns,local_ns):
pymol.__script__ = file global_ns['__script__'] = file
try: try:
execfile(file,global_ns,local_ns) execfile(file,global_ns,local_ns)
except pymol.CmdException: except pymol.CmdException:
# so the idea here is to print the traceback here and then # so the idea here is to print the traceback here and then
# cascade all the way back up to the interactive level # cascade all the way back up to the interactive level
# without any further output # without any further output
traceback.print_exc() _print_exc()
raise QuietException raise QuietException
def run_file_as_module(file,spawn=0): def run_file_as_module(file,spawn=0):
name = re.sub('[^A-Za-z0-9]','_',file) name = re.sub('[^A-Za-z0-9]','_',file)
if not isinstance(name, str):
# Python 2 only
name = name.encode('ascii', errors='ignore')
mod = types.ModuleType(name) mod = types.ModuleType(name)
mod.__file__ = file mod.__file__ = file
mod.__script__ = file mod.__script__ = file
sys.modules[name]=mod sys.modules[name]=mod
if spawn: if spawn:
t = threading.Thread(target=execfile, t = threading.Thread(target=execfile,
args=(file,mod.__dict__,mod.__dict__)) args=(file,mod.__dict__,mod.__dict__))
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
else: else:
try: try:
execfile(file,mod.__dict__,mod.__dict__) execfile(file,mod.__dict__,mod.__dict__)
except pymol.CmdException: except pymol.CmdException:
traceback.print_exc() _print_exc()
raise QuietException raise QuietException
del sys.modules[name] del sys.modules[name]
del mod del mod
def spawn_file(args,global_ns,local_ns): def spawn_file(args,global_ns,local_ns):
local_ns['__script__'] = args local_ns['__script__'] = args
t = threading.Thread(target=execfile,args=(args,global_ns,local_ns)) t = threading.Thread(target=execfile,args=(args,global_ns,local_ns))
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
 End of changes. 16 change blocks. 
23 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)