Пример #1
0
def setup(userclass):
    global connections

    if not hasattr(userclass, "dict"):
        raise errors.Context("FlaskSetupError", "Must use class")
    if len(connections) == 0:
        raise errors.Context("FlaskSetupError", "No connections setup")
    if app is None:
        raise errors.Context("FlaskSetupError", "Please setup app first")

    global classitems
    classitems = userclass.dict

    if classitems.keys() != connections.keys():
        raise errors.Context("FlaskSetupError",
                             "Class Defentions dont match route connections")
    for key in classitems:
        route = connections[key]
        exec(f"""
@currentapp.route("{route}")
def {key}():
  global classitems
  return classitems["{key}"].runfunc(transformer.DefInterpreter, [])  
    """)

    global weberrors
    for status in weberrors:
        exec(f"""
@currentapp.errorhandler("{status}")
def {weberrors[status].name}(e):
  global weberrors
  return weberrors["{status}"].runfunc(transformer.DefInterpreter, [e])  
    """)
Пример #2
0
 def index(self, item):
   currentobj = item
   for index in self.indexes:
     try:
       currentobj = currentobj[index]
     except IndexError:
       raise errors.Context("IndexError", "List index out of range")
     except TypeError:
       raise errors.Context("TypeError", "Type not supported")
   return currentobj
Пример #3
0
 def key(self, item):
   currentobj = item
   for index in self.indexes:
     try:
       currentobj = currentobj[index]
     except KeyError:
       raise errors.Context("KeyError", "Invalid Key")
   return currentobj
Пример #4
0
 def dictionary(self, args):
   keys = args[::2]
   values = args[1::2]
   if len(keys) != len(values):
     raise errors.Context("ValueError", "Dict does not match up with key")
   
   userdict = dict(zip(keys, values))
   return userdict
Пример #5
0
def import_online(name):
  pkgobj = requests.get(f"https://pakrat.teamzala.repl.co/scrp/{name}")
  if pkgobj.status_code == 404:
    raise errors.Context("PakratPackagerError", "The requested package was not found.")

  pkg = pkgobj.content.decode('utf-8').replace("<br>", "\n")
  pkg = parser.parser.parse(pkg)

  pkgParsedTokens = transformer.TransformTokens().transform(pkg)
  assigner.ClassBuilder.build(transformer.ClassInterpreter, name, pkgParsedTokens)
Пример #6
0
    def value(self, args):
      item = assigner.Variable.basic_get(args[0])
      if isinstance(args[-1], Indexer):
        if isinstance(item, list):
          indexer = args.pop(-1)
          indexedlist = indexer.index(item)
          return assigner.Variable.basic_get(indexedlist)
        if isinstance(item, dict):
          indexer = args.pop(-1)
          dictvalue = indexer.key(item)  
          return assigner.Variable.basic_get(dictvalue)
        if isinstance(item, str):
          indexer = args.pop(-1)
          indexes = indexer.indexes
          
          if len(indexes) > 1:
            raise errors.Context("IndexError","String Supports Single Index Only")

          strvalue = item[indexes[0]]
          return strvalue
        else:
          raise errors.Context("TypeError", "Type does not support index.")
      return item
Пример #7
0
 def div(self, args):
     left, right = assigner.Variable.binop_get(args[0], args[1])
     if right == 0:
         raise errors.Context('ZeroDivision', 'Cannot Divide by Zero')
     return left / right