Example #1
0
 def _input(self, args, lcls):
     """ nput:[question,[valid results (regex) [, error messg]]]"""
     from Objects import strobj #this could be moved to the top
     msg, valid, err = group(data = "'> '", control = args.control), None,\
                       group(data = "\"\0'{inv}' is an invalid input! Valid: '{val}'.\"", control = args.control)
     if len(args) > 0:
         args[0].evalgrp(lcls)
         msg = lcls.iv.last
         if len(args) > 1:
             args[1].evalgrp(lcls)
             valid = lcls.iv.last
             if len(args) > 2:
                 args[2].evalgrp(lcls)
                 err = lcls.iv.last
                 if __debug__:
                     assert len(args) <= 3, 'input:[question,[valid results (array) [, error messg]]]'
     lcls.iv.last = group(baseobj = strobj(), control = args.control)
     # if valid != None:
     #     assert 0, 'what is convstr??' + repr(valid)
     #     valid.data = str(valid.data.convstr())
     while True:
         lcls.iv.last = group(data = str(input(msg.scrubstr(args.control))), control = args.control)
         if valid == None:
             break
         if __debug__:
             assert isinstance(valid.baseobj, arrayobj),\
                 'Only accepts array of valid results!, not ' + str(type(valid.baseobj))
         if lcls.iv.last not in valid:
             print(err.scrubstr(args.control, inv = lcls.iv.last.data, val = str(valid)))
         else:
             break;
Example #2
0
 def _evalargs(self, args, lcls, ignore):
     if __debug__:
         assert len(args) > 0, "No known Obj function '' for Obj '{}'!".format(args)
     # objname = str(lcls.iv.last.data)
     fncname = str(args[0])
     if fncname == '$clone' or fncname == '$copy' and fncname not in ignore:
         lcls.iv.last = lcls.iv.last.deepcopy()
     elif fncname == '$updtype' and fncname not in ignore:
         if __debug__:
             from Objects import arrayobj
             assert isinstance(args[1].baseobj, arrayobj), str(args) + " should be obj:updtype:(type)"
             assert len(args[1]) == 1, str(args) + " should be obj:updtype:(type)"
         last = lcls.iv.last
         args[1][0].evalgrp(lcls)
         if __debug__:
             from Objects import typeobj
             assert isinstance(lcls.iv.last.baseobj, typeobj), "should be obj:updtype:(type)"
         last.baseobj = lcls.iv.last.baseobj.baseclass.baseobj
     elif fncname == '$type' and fncname not in ignore:
         from Group import group # not sure this is the best way
         from Objects import typeobj # to be doing this...
         lcls.iv.last = group(data = type(lcls.iv.last.baseobj).__qualname__, baseobj = typeobj(lcls.iv.last),
                              control = args.control)
     elif fncname == '$str' and fncname not in ignore:
         from Group import group # not sure this is the best way
         from Objects import strobj # to be doing this...
         lcls.iv.last = group(data = lcls.iv.last.data, baseobj = strobj(),
                              control = args.control)
     elif fncname in {'$attrs', '$a'} and fncname not in ignore:
         from Group import group # not sure this is the best way
         from Objects import dictobj # to be doing this...
         lcls.iv.last = group(data = '', baseobj = dictobj(), parens = ('{', '}'),
                              control = args.control,
                              args = lcls.iv.last.attrs)
     elif fncname in {'$setattr', '$sa'} and fncname not in ignore:
         if __debug__:
             assert len(args) == 2, "obj:$setattr:(name, value), not '{}'".format(str(args))
             assert len(args[1]) == 2, "obj:$setattr:(name, value), not '{}'".format(str(args[0]))
         last = lcls.iv.last
         args[1][0].evalgrp(lcls)
         name = lcls.iv.last
         args[1][1].evalgrp(lcls)
         print(name.datastr in last.attrs,name.datastr, last.attrs.keys(), sep = '\t|\t')
         last.attrs[name.datastr] = lcls.iv.last
     elif fncname in {'$getattr', '$ga'} and fncname not in ignore:
         if __debug__:
             assert len(args) == 2, "obj:$getattr:(name), not '{}'".format(str(args))
             assert len(args[1]) == 1, "obj:$getattr:(name), not '{}'".format(str(args[0]))
         last = lcls.iv.last
         # args[1][0].evalgrp(lcls)
         lcls.iv.last = last.attrs[args[1][0].datastr]
     elif fncname in {'$delattr', '$da'} and fncname not in ignore:
         if __debug__:
             assert len(args) == 2, "obj:$delattr:(name), not '{}'".format(str(args))
             assert len(args[1]) == 1, "obj:$delattr:(name), not '{}'".format(str(args[0]))
         last = lcls.iv.last
         # args[1][0].evalgrp(lcls)
         lcls.iv.last = last.attrs[args[1][0].datastr]
         del last.attrs[args[1][0].datastr]
     else:
         if type(self)._evalargs == obj._evalargs:
             raise SyntaxError("No known function '{}' for {} '{}'.".\
                               format(fncname, type(self).__qualname__, lcls.iv.last))
         return NotImplemented
     return lcls.iv.last