def parse_tags(self, tag_str): """ Return a list of tag tuples (name, value) pairs derived from a string. >>> th = TagHandler("bridge_of_death") >>> assert th.parse_tags("#ARTHUR") == [('name', 'ARTHUR')] >>> tags = th.parse_tags("name:Lancelot of Camelot;#Holy Grail;blue") >>> assert tags == [('name', 'LancelotofCamelot'), ('name', 'HolyGrail'), ('blue', None)] """ # Gracefully handle None. if not tag_str: return dict() # Strip unicode control characters tag_str = strip_control_characters(tag_str) # Split tags based on separators. reg_exp = re.compile('[' + self.tag_separators + ']') raw_tags = reg_exp.split(tag_str) return self.parse_tags_list(raw_tags)
def parse_tags(self, tag_str): """ Returns a list of raw (tag-name, value) pairs derived from a string; method scrubs tag names and values as well. Return value is a list of (tag_name, tag_value) tuples. """ # Gracefully handle None. if not tag_str: return dict() # Strip unicode control characters tag_str = strip_control_characters(tag_str) # Split tags based on separators. reg_exp = re.compile('[' + self.tag_separators + ']') raw_tags = reg_exp.split(tag_str) # Extract name-value pairs. name_value_pairs = [] for raw_tag in raw_tags: nv_pair = self._get_name_value_pair(raw_tag) scrubbed_name = self._scrub_tag_name(nv_pair[0]) scrubbed_value = self._scrub_tag_value(nv_pair[1]) # Append tag_name, tag_value tuple -- TODO use NamedTuple name_value_pairs.append((scrubbed_name, scrubbed_value)) return name_value_pairs
def test_strip_control_characters(): s = '\x00bla' assert util.strip_control_characters(s) == 'bla'
import json from galaxy.util import strip_control_characters from jinja2 import Environment, PackageLoader from pkg_resources import resource_string TITLE = "Tool Test Results (powered by Planemo)" env = Environment(loader=PackageLoader('planemo', 'reports')) env.filters['strip_control_characters'] = lambda x: strip_control_characters(x) if x else x def build_report(structured_data, report_type="html", **kwds): """ Use report_{report_type}.tpl to build page for report. """ environment = dict( title=TITLE, raw_data=structured_data, ) if report_type == 'html': # The HTML report format needs a lot of extra, custom data. # IMO, this seems to suggest it should be embedded. environment.update({ 'custom_style': __style("custom.css"), 'custom_script': __script("custom"), 'bootstrap_style': __style("bootstrap.min.css"), 'jquery_script': __script("jquery.min"), 'bootstrap_script': __script("bootstrap.min"), 'json': json, })
import json from galaxy.util import strip_control_characters from jinja2 import Environment, PackageLoader from pkg_resources import resource_string TITLE = "Tool Test Results (powered by Planemo)" env = Environment(loader=PackageLoader('planemo', 'reports')) env.filters['strip_control_characters'] = lambda x: strip_control_characters( x) if x else x def build_report(structured_data, report_type="html", **kwds): """ Use report_{report_type}.tpl to build page for report. """ environment = dict( title=TITLE, raw_data=structured_data, ) if report_type == 'html': # The HTML report format needs a lot of extra, custom data. # IMO, this seems to suggest it should be embedded. environment.update({ 'custom_style': __style("custom.css"), 'custom_script': __script("custom"), 'bootstrap_style': __style("bootstrap.min.css"), 'jquery_script': __script("jquery.min"), 'bootstrap_script': __script("bootstrap.min"), 'json': json, })