#!/usr/bin/python
import cgi, sys
import aword_ as aword # python2.5 would fix this
form = cgi.FieldStorage()
print 'Content-Type: text/html'
print
k = form.keys()
mode = None
def r(x):
    return x.replace('\r', '')
if 'wrap' in k:
    text1 = r(form['text'].value)
    text2 = aword.awrap(text1)
elif 'unwrap' in k:
    text2 = r(form['text'].value)
    text1 = aword.aunwrap(text2)
else:
    text1 = text2 = ''
print '''
<html>
<head>
<title>wrap</title>
</head>
<body>
<a href="../aword.py">aword.py</a>
<table style="width: 100%">
<tr>
<td>
    <form action="?" method="POST">
    <h4>Unwrapped:</h4>
    <textarea style="width:100%" rows="20" name="text">text1</textarea><br>
    <input type="submit" style="width:100%; height: 50px" name="wrap" value="--&gt;">
    </form>
</td>
'''.replace('text1', text1) + '''
<td>
    <form action="?" method="POST">
    <h4>Wrapped:</h4>
    <textarea style="width:100%" rows="20" name="text">text2</textarea><br>
    <input type="submit" style="width:100%; height: 50px" name="unwrap" value="&lt;--">
    </form>
</td>
</tr>
</table>
</body>
</html>

'''.replace('text2', text2)
