-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
68 lines (54 loc) · 2.01 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template('mainpage.html')
@app.route('/', methods=['POST'])
def my_form_post():
text = request.form['text']
# split text by line breaks
input_lines = text.splitlines()
if 'ignore-blank-lines' in request.form:
nonblank_lines = []
for line in input_lines:
if line.strip() != "":
nonblank_lines.append(line)
input_lines = nonblank_lines
if ('keep-trailing-spaces' not in request.form) and (
'keep-leading-spaces' not in request.form):
no_space_ends = []
for line in input_lines:
no_space_ends.append(line.strip())
input_lines = no_space_ends
elif 'keep-leading-spaces' not in request.form:
no_space_lead = []
for line in input_lines:
no_space_lead.append(line.lstrip())
input_lines = no_space_lead
elif 'keep-trailing-spaces' not in request.form:
no_space_trail = []
for line in input_lines:
no_space_trail.append(line.rstrip())
input_lines = no_space_trail
num_rm_start = int(request.form['rm-start'])
if num_rm_start > 0:
trimmed_lines = []
for line in input_lines:
trimmed_lines.append(line[num_rm_start:])
input_lines = trimmed_lines
num_rm_end = int(request.form['rm-end'])
if num_rm_end > 0:
trimmed_lines = []
for line in input_lines:
trimmed_lines.append(line[:-num_rm_end])
input_lines = trimmed_lines
if 'remove-all-spaces' in request.form:
no_space_any = []
for line in input_lines:
no_space_any.append( ''.join(line.split()) )
#no_space_any.append(re.sub(r"\s+", "", line))
input_lines = no_space_any
delim = request.form['delimiter']
# use <pre> tag to preserve whitespace (multiple space, tabs, etc.)
return "<pre>" + delim.join(input_lines) + "</pre>"