def convert_css_selectors(rules): """Convert css rules to xpath rules element tree in place """ # XXX: There is a :root pseudo-class - http://www.w3.org/TR/css3-selectors/#root-pseudo # We may wish to add support to lxml.cssselect for it some day. for element in rules.xpath("//@*[namespace-uri()='%s']/.." % utils.namespaces["css"]): tag_localname = utils.localname(element.tag) tag_namespace = utils.namespace(element.tag) css_prefix = element.attrib.get(utils.fullname(utils.namespaces["css"], "prefix"), None) for name, value in element.attrib.items(): if not name.startswith("{%s}" % utils.namespaces["css"]): continue localname = utils.localname(name) if localname == "prefix": continue if not value: element.attrib[localname] = "" continue if css_prefix is not None: prefix = css_prefix elif ( tag_namespace == utils.namespaces["diazo"] and localname in ("content", "content-children", "if-content") or (tag_namespace == utils.namespaces["xsl"] and localname in ("match",)) ): prefix = "//" else: prefix = "descendant-or-self::" element.attrib[localname] = css_to_xpath(value, prefix=prefix) return rules
def convert_css_selectors(rules): """Convert css rules to xpath rules element tree in place """ # XXX: There is a # :root pseudo-class - http://www.w3.org/TR/css3-selectors/#root-pseudo # We may wish to add support to lxml.cssselect for it some day. for element in rules.xpath("//@*[namespace-uri()='%s']/.." % utils.namespaces['css']): tag_namespace = utils.namespace(element.tag) css_prefix = element.attrib.get(utils.fullname(utils.namespaces['css'], 'prefix'), None) for name, value in element.attrib.items(): if not name.startswith('{%s}' % utils.namespaces['css']): continue localname = utils.localname(name) if localname == 'prefix': continue if not value: element.attrib[localname] = "" continue if css_prefix is not None: prefix = css_prefix elif (tag_namespace == utils.namespaces['diazo'] and localname in ('content', 'content-children', 'if-content', 'if-not-content') or (tag_namespace == utils.namespaces['xsl'] and localname in ('match',))): prefix = '//' else: prefix = 'descendant-or-self::' element.attrib[localname] = css_to_xpath(value, prefix=prefix) return rules
"thead", "time", "title", "tr", "tt", "u", "ul", "var", "video", "wbr", } _tags |= {"h%d" % ii for ii in range(1, 7)} tags = namespace(_name_="Tags", **{key: type(key, (Tag, ), {"name": key}) for key in _tags}) t = tags _stags = { "area", "base", "basefont", "col", "embed", "frame", "meta", "img", "input", "link",
def main(cla): # Load the user-defined settings, and script settings # ---------------------------------------------------- user_config = cla.user_config print(f"user config: {user_config}") script_config = cla.script_config print(f"script config: {script_config}") if not script_config: ushdir = os.path.join(user_config['paths']['homerrfs'], 'configs') script_config = checks.load_config_file( os.path.join(ushdir, 'fv3_script.yml')) # Update script config with user-supplied config file # ---------------------------------------------------- utils.update_dict(script_config, user_config, quiet=cla.quiet) # Create Namespace of config for easier syntax # --------------------------------------------- config = argparse.Namespace() utils.namespace(config, script_config) # Now config and script_config contain identical information in Namespace # and dict formats, respectively. # Load each of the standard YAML config files # -------------------------------------------- # # Reminder: # checks.load_config_section(arg) takes a two-element list as it's input. # arg = [file_name, section_name(s)] # grid = cla.grid_config if not grid: grid = checks.load_config_section([ config.paths.grid.format(n=config), [config.grid_name, config.grid_gen_method], ]) machine = cla.machine_config if not machine: machine_path = config.paths.machine.format(n=config) machine = checks.load_config_section([ machine_path, config.machine, ]) namelist = cla.nml_config if not namelist: namelist = checks.load_config_section([ config.paths.namelist.format(n=config), config.phys_pkg, ]) # Update each of the provided configure files with user-supplied settings # ------------------------------------------------------------------------ for cfg in ['grid', 'machine', 'namelist']: utils.update_dict(locals()[cfg][0], script_config.get(cfg), quiet=cla.quiet) # Set up a kwargs dict for Forecast object # ----------------------------------------- fcst_kwargs = { 'grid': grid[0], 'nml': namelist[0], 'overwrite': cla.overwrite, } # Create the Forecast object # --------------------------- fcst = Forecast( config=script_config, machine=machine[0], starttime=cla.start_date, **fcst_kwargs, ) # Run the forecast job # --------------------- fcst.run(dry_run=cla.dry_run)
js = namespace( shower=JSLib(path="https://shwr.me/shower/shower.min.js"), mathjax=JSLib( path="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"), jquery=JSLib( path="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" ), bootstrap=JSLib( path= "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js", integrity= "sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6", crossorigin="anonymous", _async_=False, ), bs_jquery=JSLib( path="https://code.jquery.com/jquery-3.4.1.slim.min.js", integrity= "sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n", crossorigin="anonymous", _async_=False, ), bs_popper=JSLib( path= "https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js", integrity= "sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo", crossorigin="anonymous", _async_=False, ), )
from utils import namespace from utils.html import Library, st __all__ = ( "css", ) class CSSLib(Library): def __init__(self, path, *args, **kwargs): Library.__init__(self, path, *args, **kwargs) def add(self, *args, **kwargs): kwargs.update(self.options) kwargs["rel"] = "stylesheet" kwargs["href"] = self.path return st.link(**kwargs) css = namespace( bootstrap = CSSLib( "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css", integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh", crossorigin="anonymous", ), )
def config_namespace(config): ns = Namespace() utils.namespace(ns, config) return ns