main.py
def simple_transform():
    """
    handles the simple transcoding/transform page
    """
    input_string = ''
    dna_string = ''
    output_string = ''
    # program may or may not be using the above variables
    if request.method == 'POST':
        # if server receives a POST http request
        if 'encode' in request.form:
            # steps taken when the POST is received from element named encode
            input_text = request.form['input_text']
            range_value = int(request.form['base'])
            checked_value = ['', '', '']
            checked_value[range_value - 2] = 'checked'
            dna_string = convert_unicode_to_dna(input_text, range_value)
            input_string = input_text
            output_string = request.form['output_text']
            # returns template for simple transform page; variables relate to encode action
            return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                   checked=checked_value, dna_text=dna_string,
                                   output_text=output_string)
        elif 'decode' in request.form:
            # steps taken from when the POST is received from element named decode
            range_value = int(request.form['base'])
            checked_value = ['', '', '']
            checked_value[range_value - 2] = 'checked'
            input_string = request.form['input_text']
            dna_string = request.form['dna_text']
            output_string = request.form['output_text']
            try:
                # TODO: simplify error handling section, maybe should make render_template() more efficient
                output_string = convert_dna_to_unicode(request.form['dna_text'], range_value)
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=checked_value, dna_text=dna_string,
                                       output_text=output_string)
            except OverflowError:
                # for when the conversion results in a character value too large for Unicode to handle
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=['checked', '', ''], dna_text=dna_string,
                                       dna_right='One or more of the values that you tried to decode fell outside of'
                                                 ' the Unicode bounds. Try using a shorter DNA value or encoding a'
                                                 ' different set of data.', output_text=output_string)
            except ValueError:
                # error received when user decodes DNA not within the transcoding list
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=['checked', '', ''], dna_text=dna_string,
                                       dna_right='One or more of the values that you tried to decode were not '
                                                 'accounted for based on your selected encoding method. Please try '
                                                 'again with a different set of data.', output_text=output_string)
            except Exception as e:
                # TODO: all other errors, doesn't give any useful informtion as of now, more testing is needed
                print(e)
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=['checked', '', ''], dna_text=dna_string,
                                       dna_right='There was an unknown error while decoding your DNA data. Please '
                                                 'try again with a different input.', output_text=output_string)
        elif 'clear' in request.form:
            # when the POST is sent from the element named clear
            input_string = dna_string = output_string = ''
            return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                   checked=['checked', '', ''], dna_text=dna_string, input_right='', dna_right='',
                                   output_text=output_string, output_right='')
        else:
            # not entirely sure what to have here, not sure when this code would even run
            pass
    else:
        # this runs when we receive a GET http request from the program, returns an 'empty' simple transcoding page
        return render_template('simple_transform.html', action='/simple', input_text=input_string,
                               checked=['checked', '', ''], dna_text=dna_string, input_right='', dna_right='',
                               output_text=output_string, output_right='')

    handles the simple transcoding/transform page
    
handles the simple transcoding/transform page
handles the simple transcoding / transform page
def simple_transform():
    input_string = ''
    dna_string = ''
    output_string = ''
    if request.method == 'POST':
        if 'encode' in request.form:
            input_text = request.form['input_text']
            range_value = int(request.form['base'])
            checked_value = ['', '', '']
            checked_value[range_value - 2] = 'checked'
            dna_string = convert_unicode_to_dna(input_text, range_value)
            input_string = input_text
            output_string = request.form['output_text']
            return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                   checked=checked_value, dna_text=dna_string,
                                   output_text=output_string)
        elif 'decode' in request.form:
            range_value = int(request.form['base'])
            checked_value = ['', '', '']
            checked_value[range_value - 2] = 'checked'
            input_string = request.form['input_text']
            dna_string = request.form['dna_text']
            output_string = request.form['output_text']
            try:
                output_string = convert_dna_to_unicode(request.form['dna_text'], range_value)
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=checked_value, dna_text=dna_string,
                                       output_text=output_string)
            except OverflowError:
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=['checked', '', ''], dna_text=dna_string,
                                       dna_right='One or more of the values that you tried to decode fell outside of'
                                                 ' the Unicode bounds. Try using a shorter DNA value or encoding a'
                                                 ' different set of data.', output_text=output_string)
            except ValueError:
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=['checked', '', ''], dna_text=dna_string,
                                       dna_right='One or more of the values that you tried to decode were not '
                                                 'accounted for based on your selected encoding method. Please try '
                                                 'again with a different set of data.', output_text=output_string)
            except Exception as e:
                print(e)
                return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                       checked=['checked', '', ''], dna_text=dna_string,
                                       dna_right='There was an unknown error while decoding your DNA data. Please '
                                                 'try again with a different input.', output_text=output_string)
        elif 'clear' in request.form:
            input_string = dna_string = output_string = ''
            return render_template('simple_transform.html', action='/simple', input_text=input_string,
                                   checked=['checked', '', ''], dna_text=dna_string, input_right='', dna_right='',
                                   output_text=output_string, output_right='')
        else:
            pass
    else:
        return render_template('simple_transform.html', action='/simple', input_text=input_string,
                               checked=['checked', '', ''], dna_text=dna_string, input_right='', dna_right='',
                               output_text=output_string, output_right='')
def simple_transform ( ) : input_string = '' dna_string = '' output_string = '' if request . method == 'POST' : if 'encode' in request . form : input_text = request . form [ 'input_text' ] range_value = int ( request . form [ 'base' ] ) checked_value = [ '' , '' , '' ] checked_value [ range_value - 2 ] = 'checked' dna_string = convert_unicode_to_dna ( input_text , range_value ) input_string = input_text output_string = request . form [ 'output_text' ] return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = checked_value , dna_text = dna_string , output_text = output_string ) elif 'decode' in request . form : range_value = int ( request . form [ 'base' ] ) checked_value = [ '' , '' , '' ] checked_value [ range_value - 2 ] = 'checked' input_string = request . form [ 'input_text' ] dna_string = request . form [ 'dna_text' ] output_string = request . form [ 'output_text' ] try : output_string = convert_dna_to_unicode ( request . form [ 'dna_text' ] , range_value ) return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = checked_value , dna_text = dna_string , output_text = output_string ) except OverflowError : return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = [ 'checked' , '' , '' ] , dna_text = dna_string , dna_right = 'One or more of the values that you tried to decode fell outside of' ' the Unicode bounds. Try using a shorter DNA value or encoding a' ' different set of data.' , output_text = output_string ) except ValueError : return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = [ 'checked' , '' , '' ] , dna_text = dna_string , dna_right = 'One or more of the values that you tried to decode were not ' 'accounted for based on your selected encoding method. Please try ' 'again with a different set of data.' , output_text = output_string ) except Exception as e : print ( e ) return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = [ 'checked' , '' , '' ] , dna_text = dna_string , dna_right = 'There was an unknown error while decoding your DNA data. Please ' 'try again with a different input.' , output_text = output_string ) elif 'clear' in request . form : input_string = dna_string = output_string = '' return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = [ 'checked' , '' , '' ] , dna_text = dna_string , input_right = '' , dna_right = '' , output_text = output_string , output_right = '' ) else : pass else : return render_template ( 'simple_transform.html' , action = '/simple' , input_text = input_string , checked = [ 'checked' , '' , '' ] , dna_text = dna_string , input_right = '' , dna_right = '' , output_text = output_string , output_right = '' )
handles the simple transcoding/transform page
handles the simple transcoding / transform page
"""
    handles the simple transcoding/transform page
    """ # program may or may not be using the above variables
 # if server receives a POST http request
 # steps taken when the POST is received from element named encode
 # returns template for simple transform page; variables relate to encode action
 # steps taken from when the POST is received from element named decode
 # TODO: simplify error handling section, maybe should make render_template() more efficient
 # for when the conversion results in a character value too large for Unicode to handle
 # error received when user decodes DNA not within the transcoding list
 # TODO: all other errors, doesn't give any useful informtion as of now, more testing is needed
 # when the POST is sent from the element named clear
 # not entirely sure what to have here, not sure when this code would even run
 # this runs when we receive a GET http request from the program, returns an 'empty' simple transcoding page
