def param_noColor(self, tag): """The <noColor> parameter disables colors. This is equivalent to a <format> parameter with CommitFormatter's default component tree. """ self.componentTree = XML.parseString(CommitFormatter.defaultComponentTree ).documentElement
def syncFromServer(self): """Update this Bot from the RPC server, if necessary. Right now the only task this performs is to store the server's ruleset if filterMode is 'unknown'. """ if self.filter_mode != FILTER.UNKNOWN: return ruleset = self._loadRuleset() if not ruleset: # If there's no ruleset, mark the bot as inactive. self.filter_mode = FILTER.INACTIVE self.save() return # Parse the ruleset using LibCIA's XML library from cia.LibCIA import XML dom = XML.parseString(ruleset) # XXX: We should try to reduce the ruleset to one of # the other FILTER.* modes if possible. For now, # we'll always import existing rulesets as # FILTER.CUSTOM. # Flatten the contents of the <ruleset> element, clean up # the resulting text, and save that as a custom filter. text = ''.join([n.toxml() for n in dom.documentElement.childNodes]) self.filter_mode = FILTER.CUSTOM self.custom_ruleset = clean_up_text(text) self.save()
def caps_store(self, path, xml): """Generate a list of acceptable capabilities to grant access to 'store'. In addition to the usual ones, allow ('ruleset.uri', x) where x is the ruleset's URI. """ if (xml.startswith('[')): uri = xml.split('\n')[0][2:] else: uri = XML.parseString(xml).documentElement.getAttributeNS(None, 'uri') return self.makeDefaultCaps(path) + [('ruleset.uri', uri)]
def format(self, args): """The formatter entry point. This just finds the current component tree and invokes walkComponents and joinComponents on it. """ # Parse the default component tree, caching it per-class if self.__class__._defaultTreeOwner is not self.__class__.defaultComponentTree: self.__class__._defaultTreeOwner = self.__class__.defaultComponentTree self.__class__._cachedDefaultTree = XML.parseString(self.__class__.defaultComponentTree).documentElement # This will use the default component tree if it hasn't been overridden in this instance tree = self.componentTree or self.__class__._cachedDefaultTree return self.joinComponents(self.walkComponents(tree.childNodes, args))
def getSvnRevision(self): """Return the current Subversion repository revision, or None if we're not in an svn working copy or it can't be parsed. """ try: entries = XML.parseString(open(".svn/entries").read()).documentElement highestRev = 0 for tag in XML.getChildElements(entries): if tag.nodeName == 'entry': rev = tag.getAttributeNS(None, 'committed-rev') if rev and rev > highestRev: highestRev = rev return highestRev except: return None
def dbStore(self, ruleset=None): """Write all rulesets to disk in one big XML file""" doc = XML.parseString("<rulesets>\n" "<!--\n" "This is a ruleset storage for CIA. It tells the CIA server\n" "how to deliver messages. Don't edit it by hand while the server\n" "is running, use tools/ruleset_editor.py\n" "-->\n" "\n" "</rulesets>") root = doc.documentElement for ruleset in self.flatten(): root.appendChild(XML.Domlette.ConvertDocument(ruleset.xml).documentElement) root.appendChild(doc.createTextNode("\n\n")) f = open(self.path, "w") XML.Domlette.Print(doc, f) f.write("\n")
def command_DeliverXML(self): """Deliver a message already formatted in XML""" # Note that parseString will convert UTF8 to Unicode for us. return XML.parseString(self.message.get_payload())