Skip to content

Commit

Permalink
Refactored and commented code.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxw59 committed Jun 21, 2015
1 parent b4a52f3 commit c4ffb0c
Show file tree
Hide file tree
Showing 42 changed files with 552 additions and 682 deletions.
Binary file removed __pycache__/asc.cpython-34.pyc
Binary file not shown.
Binary file removed __pycache__/core.cpython-34.pyc
Binary file not shown.
94 changes: 0 additions & 94 deletions app.py

This file was deleted.

45 changes: 0 additions & 45 deletions asc.py

This file was deleted.

88 changes: 88 additions & 0 deletions cgiApp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!./.interpreter.sh

import argparse
import cgi
import cgitb
import os
import sys
from conlang import soundChangeApp, workers


word = None
stdin = False
html = False
debug = 0
FILE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))

if 'REQUEST_METHOD' in os.environ:
# It's being run as a cgi script
# Encode all non-ascii characters with xml escapes
sys.stdout = workers.Reencoder(sys.stdout)
print('Content-Type: text/html')
print('')
form = cgi.FieldStorage(encoding='utf-8')
word = form['word'].value
startd = {}
endd = {}
for f in form:
try:
# just get the number from the form key
n = int(f.split('-')[1])
v = form[f].value
if f[0] == 's':
startd[n] = v if v != ' ' else ''
elif f[0] == 'e':
endd[n] = v if v != ' ' else ''
except IndexError:
# there wasn't a '-' in f, so it wasn't a start or end key
continue
start = [v for k, v in sorted(startd.items())]
end = [v for k, v in sorted(endd.items())]
if 'debug' in form:
debug = int(form['debug'].value)
html = True
else:
# It's being run from the command line
parser = argparse.ArgumentParser()
parser.add_argument('--word', '-w')
parser.add_argument('--start', '-s', action='append', default=[], nargs='?')
parser.add_argument('--end', '-e', action='append', default=[], nargs='?')
parser.add_argument('--debug', '-d', type=int, default=0)
parser.add_argument('--html', '-t', action='store_true')
args = parser.parse_args()
word = args.word
if word is None:
# take input from stdin
stdin = True
debug = args.debug
if args.html:
# encode all non-ascii characters with xml escapes
sys.stdout = Reencoder(sys.stdout)
html = True
start = [x if x else '' for x in args.start]
end = [x if x else '' for x in args.end]

if html:
# html formatted error messages
cgitb.enable()
else:
# plain error messages
cgitb.enable(format='plain')

pairs = list(zip(start, end))

while True:
if stdin:
try:
word = input()
except (KeyboardInterrupt, EOFError):
break
word, db = soundChangeApp.applyRuleFiles(word, pairs, debug)
if html:
print('<pre>')
print(word)
print(db, end='')
if html:
print('</pre>')
if not stdin:
break
133 changes: 0 additions & 133 deletions conlang/X_soundChanger.py

This file was deleted.

1 change: 0 additions & 1 deletion conlang/__init__.py

This file was deleted.

Binary file removed conlang/__init__.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/__init__.cpython-32.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/__init__.cpython-33.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/__init__.cpython-34.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/conlangApp.cpython-32.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/conlangApp.cpython-33.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/conlangApp.cpython-34.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/dictionary.cpython-33.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/dictionary.cpython-34.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/inflections.cpython-33.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/inflections.cpython-34.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/soundChanger.cpython-32.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/soundChanger.cpython-33.pyc
Binary file not shown.
Binary file not shown.
Binary file removed conlang/__pycache__/soundChanger.cpython-34.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/soundChanger2.cpython-33.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/workers.cpython-32.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/workers.cpython-33.pyc
Binary file not shown.
Binary file removed conlang/__pycache__/workers.cpython-34.pyc
Binary file not shown.
Loading

0 comments on commit c4ffb0c

Please sign in to comment.