From e738379dbec31c7dc1f0c00e68c86ba51d5bc128 Mon Sep 17 00:00:00 2001 From: BuffTechTalk Date: Thu, 12 Sep 2024 07:31:31 -0500 Subject: [PATCH] check import action in code editor --- requirements.txt | Bin 2220 -> 2224 bytes .../__pycache__/code_editor.cpython-312.pyc | Bin 1861 -> 2363 bytes webpages/code_editor.py | 9 ++++++++ webpages/input_code.py | 20 ++++++++---------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7633c8ad1b5e9417577acd16779e29b8b25a33b6..cce10ea1e107e9398fab8702e2991146fda15510 100644 GIT binary patch delta 12 TcmZ1@xIu8k8V;5shExUs9a;mv delta 7 OcmdlWxJGcp8V&#qO#6rY*f-MjU^q-UDcrCUdJYvhS#LWEL!)I}YUMI~3V+^lkT-W{_WWu52` zK}dxiLu3U(5cI|VgMKm6pZX;zC^n0zp9%uaK=7A(b9xrNVc&e_GjHB|^WN-C;CV3c z%I~j0An!hX>2oTIfjYdqxNUPBQJj%`Wa_$tdK4;C=?d;~4`E&TCX5q0b`;C*HBx2@ z3t~lNm|gHK90he7d<^5_X#Ge57m&STg3y4p3Rl6TI0e#;bdtE#d^Tw{M*3K8FllX1 zc5er*cccgNIc5Wl0Ha3$7}oN(-l4l3!c52Am(EfnlX27|Ck`KvAC4ztI&q|6Do0^6 zZ`iiUvKE0j9Lt@j))-kMGjz%9U3P6TFYI{Wv+6;OqW6J)qX%Za{_#Cydv5km*bk3A zNM2`dq#{}x zlOkIXjE2Aydu)pwOF~szQQmDu!*W3$5GgE6@plBT;RU?0l~A>xPz8qfnQw9>;bEnq z3ozIKbYRhd%XZy9hkveDe zn-;(0x)%;Q#IhYVmCM>jI%_f}s$A-o{t2u?Dv;Ir7ft=KMtm zF=!I{wicA`aa7A@rZJdFdu+A|D7KaVQ0k6}U$IoA(v_be<`aY{$dYI8V2+;8nC)yY kEX9+wHh`LQVT`|`+7GDeBho$~^`}Dc&R-Q#TvIyy2h?8lK>z>% delta 620 zcmX|7&ubGw6rS1HpV=fdKQ;uD25qg)HlfzkQt(Gm6Y!?=Bzg%kyGmlxgxM`9q_hPu z;-S=sm)<-GYWxSpQ%J>wC&AO&;=xmIEv*PW`Ie;4FyDOd`{q5~ywA}u;qbRmC_r%i zY5#h(scnUmG`lrDQ4lTmoIa4AQB&IY?K>v*WXG*kYj#cah0zM(&F~y`V3*#X=!*QE ztDKsaYH2-T7%h-hsVg-!=n0o}{q#j62pcSx5-jzxV9B@xANAg-{;J%S8)4tqf=?C+ z;gc?fJz<=NAi@%0vlLumM!ZLd#VBz{j1X92aS^kV&}Y*$gBW`yDDYK?f+3F60K8#o zxGP3z8p~&3O`M`*@K*c)>(aI{<_V7LX|?vUTdgnKocsTS>vD-EU_&mP(=haOr`qZ? z?Mkg}*Ta7?n$?GPlSkl(JP9RwGpqYMm)q4= zv+nXFDjY}jT}|HbyMIrP5DCvAoT%4YZEK}z7x`rj{mDBqgabw?{Y?@-No0?lJ(ly- I;Pa^e1HoXCf&c&j diff --git a/webpages/code_editor.py b/webpages/code_editor.py index f8ec6663e..c8a1d440f 100644 --- a/webpages/code_editor.py +++ b/webpages/code_editor.py @@ -2,6 +2,12 @@ import streamlit as st import subprocess from streamlit_ace import st_ace +import re + +# check if user import python module +def analyze_imports(code): + pattern = r'^\s*(from\s+\S+\s+)?import\s+(\S+)(\s+as\s+\S+)?' + return re.findall(pattern, code, re.MULTILINE) def code_editor(height="300px", sample_code = "", editor_label = "",min_lines = 20): @@ -26,6 +32,9 @@ def code_editor(height="300px", sample_code = "", editor_label = "",min_lines = ) + if analyze_imports(content): + st.warning("Code Editor does not support importing packages") + return if content: with open("./webpages/input_code.py", "w") as f: diff --git a/webpages/input_code.py b/webpages/input_code.py index 1d23f8784..5328929cc 100644 --- a/webpages/input_code.py +++ b/webpages/input_code.py @@ -1,12 +1,10 @@ -# Example 3: Demonstrating basic arithmetic operations -a = 10 # Assigns integer 10 to variable 'a' -b = 3 # Assigns integer 3 to variable 'b' -c = 2.5 # Assigns floating-point number 2.5 to variable 'c' +# Example 1 +Age = 24; +if Age >=18: + print('You are an adult') -print('Addition: ', a + b) # Prints the sum of 'a' and 'b' -print('Subtraction: ', a - b) # Prints the result of subtracting 'b' from 'a' -print('Multiplication: ', a * b) # Prints the product of 'a' and 'b' -print('Multiplication: ', a * c) # Prints the product of 'a' and 'c', demonstrating integer-float multiplication -print('Division: ', a / b) # Prints the division of 'a' by 'b', result is a float -print('Floor Division: ', a // b) # Prints the floor division of 'a' by 'b', removing digits after the decimal point -print('Modulus: ', a % b) # Prints the remainder of 'a' divided by 'b' \ No newline at end of file +# Example 2 +has_license = False +if has_license == True: # False == True-> Flase + print('You can drive') +print('False condition, skip the if statement') \ No newline at end of file