def POST(self):
        """ webserver.py POST method """
        post_form = MYFORM()
        global RO
        #  remove any previous results from previous searches
        RO.zero_results_list()
        # remove any previous modifier flags.  Maybe we're no longer evil.
        RO.zero_modifier_flags()
        myextras = ""
        if not post_form.validates():
            return render.formresult(post_form, RO)
        else:
            xml_element_results = []
            xml_id_results = []
            weed_out_duplicates = []
            text = ""
            searchterm = post_form.d.searchfield
            ### first, for debugging, capture original form input.
            ### comment out the next two lines for production use
            text = "You submitted: [%s]\n" % searchterm
            RO.set_results_text(text)
            ### sanity check the data sent from the customer
            searchterm = handle_form_input.check_input_length(searchterm)
            searchterm = handle_form_input.scrub_form_input(searchterm)
            searchterm = searchterm.lower()  # lower case text for searching
            ### check if this is a True Cry For Help
            if handle_form_input.check_is_input_cry_for_help(searchterm):
                help_text = RO.get_results_text()
                help_text = help_text +  smfoo.display_help_text("html")
                RO.set_results_text(help_text)
                return render.formresult(post_form, RO)
            smx = smxml.Smxml()
            input_values = handle_form_input.split_input_keep_quotes(searchterm)
            #### look up synonyms before weeding out duplicates.
            #### put something in here to weed out duplicates
            #
            #### set standard list of keys for monster attributes
#            makeys = ['alignment', 'name', 'prd', 'size']
            for myinput in input_values:
                result = input_is_integer(myinput)
                if type(result) == tuple:
                    if result[0] == "yes":# we have a modifier, like +good
                        modifier_text = handle_modifier(str(result[1]))
                        myextras = RO.get_results_text() + modifier_text
                        RO.set_results_text(myextras)
                    else:
                        # we have other text input, like "dog, riding" or "all"
                        # check it for synonyms and normalize it
                        norm_st = check_for_synonyms(str(result[1]))
                        try:
                            norm_st = int(norm_st)
                            xml_id_results = smx.search_for_id_attributes(
                                             norm_st)
                        except ValueError:
                            xml_id_results = smx.search_for_monster_name(
                                             norm_st)
                        # If this list is empty,
                        #  no monster names like 'wolf' have been provided.
                        # Assume it is a special quality search
                        #  on a term like "blindsense'
                        if not xml_id_results:
                            xml_id_results = smx.search_for_monster_sq(norm_st)
                else:  # we have an integer
                    xml_id_results = smx.search_for_id_attributes(result)
                mon_att_keys = ['name', 'prd', 'hit_dice', 'hit_points',
                                'special_qualities', 'size', 'alignment']
                for monster_id in xml_id_results:
                    # create new monster object
                    monster_obj = smfoo.MonsterObject()
                    mon_dict = {}
                    mon_dict = smx.id_into_dict(monster_id, mon_att_keys)
                    # set the monster id from xml file into MonsterObject
                    monster_obj.set_id(monster_id)
                    # set a boolean flag if the monster takes a c_or_i template
                    monster_obj.set_takes_c_or_i_template(
                        smx.monster_takes_c_or_i_template([monster_id]))
                    for attribute in mon_att_keys:
                        try:
                            throwaway = getattr(monster_obj,
                                                "set_%s" %
                                                attribute)(mon_dict[attribute])
                        except KeyError:
                            throwaway = getattr(monster_obj,
                                                "set_%s" % attribute)("")
                        throwaway = monster_obj.set_name_w_link()
                    # Sometimes the input could be "eagle eagle eagle"
                    # Weed out duplicates
                    if monster_obj.get_name() not in weed_out_duplicates:
                        xml_element_results.append(monster_obj)
                        weed_out_duplicates.append(monster_obj.get_name())
                for returned_result in xml_element_results:
                    if returned_result not in RO.get_results_list():
                        RO.set_results_list(returned_result)
            ### set HTML list or HTML table.  Default is list
            if RO.get_display_output() == "extended":
                ### see if apply celestial or infernal template
                if  "Celestial" in RO.get_results_text():
                    newlist = []
                    for monster_obj in RO.get_results_list():
                        newlist.append(monster_obj)
                    RO.zero_results_list()
                    for mon_obj in newlist:
                        mon_obj.apply_template("celestial")
                        RO.set_results_list(mon_obj)
                elif "Infernal" in RO.get_results_text():
                    newlist = []
                    for monster_obj in RO.get_results_list():
                        newlist.append(monster_obj)
                    RO.zero_results_list()
                    for mon_obj in newlist:
                        mon_obj.apply_template("infernal")
                        RO.set_results_list(mon_obj)
                ### hack to get Augmented Summoning
                ###     to show up in extended display
                if "The Augment Summoning feat" in RO.get_results_text():
                    newlist = []
                    for monster_obj in RO.get_results_list():
                        newlist.append(monster_obj)
                    RO.zero_results_list()
                    for mon_obj in newlist:
                        mon_obj.apply_augs_feat()
                        RO.set_results_list(mon_obj)
                return render.formresultextended(post_form, RO)
            else:
                return render.formresult(post_form, RO)
 def test_scrub_percentage_sign(self):
     """percentage_sign within input is removed """
     expect = 'bear'
     form_input = 'be%ar'
     result = handle_form_input.scrub_form_input(form_input)
     self.assertEqual(expect, result)
 def test_scrub_semicolon(self):
     """semicolon within input is removed """
     expect = 'demon'
     form_input = 'de;mon'
     result = handle_form_input.scrub_form_input(form_input)
     self.assertEqual(expect, result)
 def test_scrub_backslash(self):
     """backslash within input is removed """
     expect = 'demon'
     form_input = 'de\mon'
     result = handle_form_input.scrub_form_input(form_input)
     self.assertEqual(expect, result)
 def test_scrub_dollar_sign(self):
     """dollar sign within input is removed """
     expect = 'dolphin'
     form_input = 'dolphin$'
     result = handle_form_input.scrub_form_input(form_input)
     self.assertEqual(expect, result)