def _buildConfigPageBody(self, html, parm_map): configTable = None section = None for sect, opt in parm_map: if opt is None: if configTable is not None and section is not None: section.boxContent = configTable html.configFormContent += section section = self.html.headedBox.clone() configTable = self.html.configTable.clone() configTextRow1 = configTable.configTextRow1.clone() configTextRow2 = configTable.configTextRow2.clone() configCbRow1 = configTable.configCbRow1.clone() configRow2 = configTable.configRow2.clone() blankRow = configTable.blankRow.clone() del configTable.configTextRow1 del configTable.configTextRow2 del configTable.configCbRow1 del configTable.configRow2 del configTable.blankRow del configTable.folderRow section.heading = sect del section.iconCell continue html_key = sect + '_' + opt if sect == "Headers" and opt in ("notate_to", "notate_subject"): valid_input = (options["Headers", "header_ham_string"], options["Headers", "header_spam_string"], options["Headers", "header_unsure_string"]) else: valid_input = options.valid_input(sect, opt) if isinstance(valid_input, types.StringTypes): newConfigRow1 = configTextRow1.clone() newConfigRow1.label = options.display_name(sect, opt) newConfigRow1.input.name = html_key newConfigRow1.input.value = options.unconvert(sect, opt) else: newConfigRow1 = configCbRow1.clone() newConfigRow1.label = options.display_name(sect, opt) blankOption = newConfigRow1.input.clone() firstOpt = True i = 0 for val in valid_input: newOption = blankOption.clone() if options.multiple_values_allowed(sect, opt): if val in options[sect, opt]: newOption.input_box.checked = "checked" newOption.input_box.type = "checkbox" newOption.input_box.name = html_key + '-' + str(i) i += 1 else: if val == options[sect, opt]: newOption.input_box.checked = "checked" newOption.input_box.type = "radio" newOption.input_box.name = html_key if options.is_boolean(sect, opt): if val is True: val = "Yes" elif val is False: val = "No" newOption.val_label = str(val) newOption.input_box.value = str(val) if firstOpt: newConfigRow1.input = newOption firstOpt = False else: newConfigRow1.input += newOption newConfigRow1.helpCell = '<strong>' + \ options.display_name(sect, opt) + \ ':</strong> ' + \ cgi.escape(options.doc(sect, opt)) newConfigRow2 = configRow2.clone() currentValue = options[sect, opt] if type(currentValue) in types.StringTypes: currentValue = currentValue.replace(',', ', ') newConfigRow2 = configTextRow2.clone() else: currentValue = options.unconvert(sect, opt) newConfigRow2 = configRow2.clone() if options.is_boolean(sect, opt): if currentValue == "False": currentValue = _("No") elif currentValue == "True": currentValue = _("Yes") newConfigRow2.currentValue = currentValue configTable += newConfigRow1 + newConfigRow2 + blankRow if section is not None: section.boxContent = configTable html.configFormContent += section return html
def _buildConfigPage(self, parm_map): # Start with an empty config form then add the sections. html = self._getHTMLClone() # "Save and Shutdown" is confusing here - it means "Save database" # but that's not clear. html.shutdownTableCell = " " html.mainContent = self.html.configForm.clone() html.mainContent.configFormContent = "" html.mainContent.optionsPathname = optionsPathname configTable = None section = None # Loop though the sections. for sect, opt in parm_map: # We need a string to use as the html key that we can change to # and from the sect, opt pair. We like irony, so we use '_' as # the delimiter <wink>. if opt is None: if configTable is not None and section is not None: # Finish off the box for this section and add it # to the form. section.boxContent = configTable html.configFormContent += section # Start the yellow-headed box for this section. section = self.html.headedBox.clone() # Get a clone of the config table and a clone of each # example row, then blank out the example rows to make way # for the real ones. configTable = self.html.configTable.clone() configTextRow1 = configTable.configTextRow1.clone() configTextRow2 = configTable.configTextRow2.clone() configCbRow1 = configTable.configCbRow1.clone() configRow2 = configTable.configRow2.clone() blankRow = configTable.blankRow.clone() del configTable.configTextRow1 del configTable.configTextRow2 del configTable.configCbRow1 del configTable.configRow2 del configTable.blankRow del configTable.folderRow section.heading = sect del section.iconCell continue html_key = sect + '_' + opt # Populate the rows with the details and add them to the table. if type(options.valid_input(sect, opt)) in types.StringTypes: # we provide a text input newConfigRow1 = configTextRow1.clone() newConfigRow1.label = options.display_name(sect, opt) newConfigRow1.input.name = html_key newConfigRow1.input.value = options.unconvert(sect, opt) else: # we provide checkboxes/radio buttons newConfigRow1 = configCbRow1.clone() newConfigRow1.label = options.display_name(sect, opt) blankOption = newConfigRow1.input.clone() firstOpt = True i = 0 for val in options.valid_input(sect, opt): newOption = blankOption.clone() if options.multiple_values_allowed(sect, opt): if val in options[sect, opt]: newOption.input_box.checked = "checked" newOption.input_box.type = "checkbox" newOption.input_box.name = html_key + '-' + str(i) i += 1 else: if val == options[sect, opt]: newOption.input_box.checked = "checked" newOption.input_box.type = "radio" newOption.input_box.name = html_key # Tim thinks that Yes/No makes more sense than True/False if options.is_boolean(sect, opt): if val == False: val = "No" elif val == True: val = "Yes" newOption.val_label = str(val) newOption.input_box.value = str(val) if firstOpt: newConfigRow1.input = newOption firstOpt = False else: newConfigRow1.input += newOption # Insert the help text in a cell newConfigRow1.helpCell = '<strong>' + \ options.display_name(sect, opt) + \ ':</strong> ' + \ cgi.escape(options.doc(sect, opt)) newConfigRow2 = configRow2.clone() currentValue = options[sect, opt] if type(currentValue) in types.StringTypes: currentValue = currentValue.replace(',', ', ') newConfigRow2 = configTextRow2.clone() else: currentValue = options.unconvert(sect, opt) newConfigRow2 = configRow2.clone() # Tim thinks that Yes/No makes more sense than True/False if options.is_boolean(sect, opt): if currentValue == "False": currentValue = "No" elif currentValue == "True": currentValue = "Yes" # XXX Something needs to be done here, otherwise really # XXX long options squeeze the help text too far to the # XXX right. Browsers can't wrap the text (even if # XXX no-wrap is False) unless there is whitespace to # XXX wrap on - comma's don't count. This works, but # XXX it's a bit ugly. Ideas? # currentValue = str(currentValue).replace(',', '<br />') newConfigRow2.currentValue = currentValue configTable += newConfigRow1 + newConfigRow2 + blankRow # Finish off the box for this section and add it to the form. if section is not None: section.boxContent = configTable html.configFormContent += section return html
import Dibbler import tokenizer from spambayes import Stats from spambayes import Version from spambayes import storage from spambayes import FileCorpus from Options import options, optionsPathname, defaults, OptionsClass, _ IMAGES = ('helmet', 'status', 'config', 'help', 'message', 'train', 'classify', 'query') experimental_ini_map = ( ('Experimental Options', None), ) for opt in options.options(True): sect, opt = opt[1:].split(']', 1) if opt[:2].lower() == "x-" and \ not options.doc(sect, opt).lower().startswith(_("(deprecated)")): experimental_ini_map += ((sect, opt),) class UserInterfaceServer(Dibbler.HTTPServer): """Implements the web server component via a Dibbler plugin.""" def __init__(self, uiPort): Dibbler.HTTPServer.__init__(self, uiPort) print _('User interface url is http://localhost:%d/') % (uiPort) def requestAuthenticationMode(self): return options["html_ui", "http_authentication"] def getRealm(self): return _("SpamBayes Web Interface") def isValidUser(self, name, password): return (name == options["html_ui", "http_user_name"] and password == options["html_ui", "http_password"]) def getPasswordForUser(self, name): return options["html_ui", "http_password"]