Guest User

Untitled

a guest
Nov 4th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.44 KB | None | 0 0
  1. from flask import Flask, request, render_template
  2. app = Flask(__name__, template_folder=' templates')
  3.  
  4. class check:
  5.     def check(code):
  6.         #some inits
  7.         #================================
  8.  
  9.         result = ""
  10.  
  11.  
  12.         lines = code.split('\n')
  13.         # \r is in end of each line. broken af.
  14.         for i in range(len(lines)):
  15.             lines[i] = lines[i][:len(lines[i])-1] #takes out last 2
  16.  
  17.  
  18.         comma = ',r ,s ,t ,u ,v ,w ,x ,y ,z ,@ ,0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9'
  19.         comma += ',a ,b ,c ,d ,e ,f ,g ,h ,i ,j ,k ,l ,m ,n ,o ,p ,q'
  20.         comma = comma.split(' ')
  21.         codeseg = {
  22.             "parts":["; --------------------------", "; Your code here"],
  23.             "location":0
  24.         }
  25.         dataseg = ["; --------------------------", "; Your variables here"]
  26.         notTabbed = [
  27.             "IDEAL","MODEL small","DATASEG","CODESEG","start:","exit:","END start","STACK 100h",
  28.             "; --------------------------","; Your code here","; Your variables here","END start","END star"
  29.  
  30.             #end star is there to fix errs. apparently last line is vut by one char.
  31.         ]
  32.                
  33.            
  34.  
  35.         #================================
  36.  
  37.        
  38.         print(lines[0])
  39.         for i in range(len(lines)):
  40.             #to check if tabbed
  41.                
  42.             if (lines[i] in notTabbed) & (("\t" in lines[i]) or ("    " in lines[i])) & (";" not in lines[i]):
  43.                 result += f"line {i+1} should not be tabbed (Hazaha).<br />"
  44.             if (lines[i] not in notTabbed) & (("\t" not in lines[i]) and ("    " not in lines[i])) & (";" not in lines[i]):
  45.                 result += f"line {i+1} should be tabbed (Hazaha).<br />"
  46.  
  47.             if lines[i] == "":
  48.                 result += (f'line {i+1} is empty<br />')
  49.                
  50.             for form in comma:
  51.                 if form in lines[i]:
  52.                     result += (f'need space after comma in line {i+1}<br />')
  53.  
  54.             #Checks for CODESEG  so I could know where it is at
  55.  
  56.             if lines[i] == "CODESEG":
  57.                 codeseg["location"] = i
  58.  
  59.         if not (lines[0][0] == ';'):
  60.             result += ("Name not in first line.<br />")
  61.  
  62.         if not ((lines[codeseg["location"]+4] == lines[codeseg["location"]+6] == codeseg["parts"][0]) & (lines[codeseg["location"]+5] == codeseg["parts"][1])):
  63.             result += ("'your code here' comment missing / is not in the right place.<br />")
  64.  
  65.         if not "Name not in first line.<br />" in result:
  66.             if not ((lines[5] == lines[7] == dataseg[0]) & (lines[6] == dataseg[1])):
  67.                 result += ("'your variables here' comment missing / is not in the right place.<br />")
  68.         else:
  69.             if not ((lines[4] == lines[6] == dataseg[0]) & (lines[5] == dataseg[1])):
  70.                 result += ("'your variables here' comment missing / is not in the right place.<br />")
  71.  
  72.         if result != "":
  73.             result += 'see <a herf="http://bit.ly/baseASM"> the instructions of writing in base format</a>'
  74.         else:
  75.             result = "None! You're good to go!"
  76.  
  77.  
  78.         return(result)
  79.  
  80.    
  81.        
  82.  
  83.  
  84. @app.route("/send", methods=["GET", "POST"])
  85. def send():
  86.     if request.method == "POST":
  87.         code = request.form["code"]
  88.         return render_template("codetest-unst.html", ERRS=check.check(code), COD=code)
  89.  
  90.     return render_template("index-unst.html")
  91.  
  92. if __name__ == "__main__":
  93.     app.run()
Add Comment
Please, Sign In to add comment