Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit 413bdbf

Browse files
committed
fixed bug where app crashed because of non-supported python syntax
1 parent 241a115 commit 413bdbf

File tree

5 files changed

+245
-1936
lines changed

5 files changed

+245
-1936
lines changed

Python2FlowChart/PyPreprocessor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ def _find_all_veribles(self, code=None) -> list:
9494
# find ver statements
9595
for string in code:
9696
if type(string) == str:
97-
m += re.findall(r'(\w+)\.? ?= ?', string)
98-
m += re.findall(r'for (\w+)\.?', string)
99-
m += re.findall(r'while (\w+)\.?', string)
100-
m += re.findall(r'for (\w+)', string)
101-
m += re.findall(r'in +(\w+)\.?', string)
102-
if '(' in string:
103-
m += re.findall(r'[a-zA-Z_0-9]+', string[string.index('(')+1:string[::-1].index(')')])
97+
try:
98+
m += re.findall(r'(\w+)\.? ?= ?', string)
99+
m += re.findall(r'for (\w+)\.?', string)
100+
m += re.findall(r'while (\w+)\.?', string)
101+
m += re.findall(r'for (\w+)', string)
102+
m += re.findall(r'in +(\w+)\.?', string)
103+
if '(' in string:
104+
m += re.findall(r'[a-zA-Z_0-9]+', string[string.index('(') + 1:string[::-1].index(')')])
105+
except ValueError:
106+
print('wrong syntax on line:', f'"{string}"')
104107
else:
105108
value = list(string.values())[0]
106109
m += self._find_all_veribles(value)
Binary file not shown.
Binary file not shown.

Python2FlowChart/debug/example.py

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,10 @@
1-
from random import shuffle
2-
from uuid import uuid1
3-
from os import listdir
1+
def pointless_fun(dictionary, num):
2+
for key in dictionary:
3+
if len(key) == num:
4+
dictionary[key] += '+'
5+
return dictionary
46

5-
no_test_error_msg = 'Теста не существует или введен неправильный номер'
67

7-
8-
def get_parsed_test(f):
9-
test = {}
10-
11-
cur_task = []
12-
for line in f:
13-
line = line.strip()
14-
15-
if not line.isdigit():
16-
cur_task.append(line)
17-
else:
18-
test[line + '_' + uuid1().hex] = cur_task
19-
cur_task = []
20-
21-
return test
22-
23-
24-
def game(test_name):
25-
try:
26-
f = open(f'tests/{test_name}.txt')
27-
except FileNotFoundError:
28-
exit(no_test_error_msg)
29-
tasks = get_parsed_test(f)
30-
test_ids = list(tasks.keys())
31-
shuffle(test_ids)
32-
33-
score = 0
34-
for test_id in test_ids:
35-
task = tasks[test_id]
36-
question = task.copy()[0]
37-
task = task[1::]
38-
right_answer = task.copy()[int(test_id.split('_')[0])-1]
39-
shuffle(task)
40-
41-
print(f'Вопрос: {question}')
42-
for answer_index in range(0, len(task)):
43-
print(f'{answer_index+1} -> {task[answer_index]}')
44-
45-
if right_answer == task[int(input('Введите номер ответа: \n').strip())-1]:
46-
score += 1
47-
48-
f.close()
49-
return f'{score}/{str(len(tasks))}'
50-
51-
52-
def update_leader_board(user_name, score, test_name):
53-
f = open('leader_board.txt', 'r')
54-
f_string = f.read()
55-
f.close()
56-
f_string += f'{user_name} -> {score} -> {test_name}\n'
57-
f = open('leader_board.txt', 'w+')
58-
f.write(f_string)
59-
f.close()
60-
return f_string
61-
62-
63-
def main():
64-
user_name = input('Введите имя: ')
65-
tests = listdir('tests/')
66-
for i in range(len(tests)):
67-
tests[i] = tests[i].replace('.txt', '')
68-
for i in range(0, len(tests)):
69-
print(f'{i+1} -> {tests[i]}')
70-
71-
try:
72-
test_index = int(input('Введите номер теста:\n')) - 1
73-
if test_index < 0:
74-
raise IndexError
75-
test_name = tests[test_index]
76-
except IndexError:
77-
exit(no_test_error_msg)
78-
79-
score = game(test_name)
80-
print(update_leader_board(user_name, score, test_name))
81-
82-
83-
if __name__ == '__main__':
84-
main()
8+
print(
9+
pointless_fun({'a': 'fas', 'b': '2ads'}, 1)
10+
)

0 commit comments

Comments
 (0)