# HG changeset patch # User Paul Boddie # Date 1633471386 -7200 # Node ID d81233407d703e9a37226998bfb2749e7b794ae3 # Parent 4ee5060ca9b4a170185db7d1910f668f3f40d6ce Introduced support for multiple identifiers when registering components, thus supporting format aliases such as "dot" for "graphviz" and "wiki" for "moin", also eliminating the superfluous wiki parser. diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/imports.py --- a/moinformat/imports.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/imports.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Import utilities. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -48,10 +48,10 @@ store_name = prefix and "%s.%s" % (prefix, leafname) or leafname stores[store_name] = import_module("%s.%s" % (modname, leafname)) -def get_mapping(modules, get_key, get_value): +def get_mapping(modules, get_keys, get_value): """ - Using the 'modules' mapping, employ 'get_key' and 'get_value' to register + Using the 'modules' mapping, employ 'get_keys' and 'get_value' to register objects provided by the modules in a mapping. """ @@ -60,7 +60,13 @@ # Use the callables to obtain the keys and values from modules. for name, module in modules.items(): - mapping[get_key(name, module)] = get_value(module) + keys = get_keys(name, module) + if keys: + + # Make a mapping for each key to the module concerned. + + for key in keys: + mapping[key] = get_value(module) return mapping diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/input/manifest.py --- a/moinformat/input/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/input/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Input context implementation manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -30,6 +30,6 @@ # Use names declared in each class to register the contexts: # input.name -> input -inputs = get_mapping(modules, lambda n, m: m.input.name, lambda m: m.input) +inputs = get_mapping(modules, lambda n, m: [m.input.name], lambda m: m.input) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/links/manifest.py --- a/moinformat/links/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/links/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Linking scheme implementation manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -30,6 +30,6 @@ # Use names declared in each class to register the linkers: # linker.name -> linker -linkers = get_mapping(modules, lambda n, m: m.linker.name, lambda m: m.linker) +linkers = get_mapping(modules, lambda n, m: [m.linker.name], lambda m: m.linker) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/macros/manifest.py --- a/moinformat/macros/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/macros/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin macro implementation manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -30,6 +30,6 @@ # Use names declared in each class to register the handlers: # macro.name -> macro -macros = get_mapping(modules, lambda n, m: m.macro.name, lambda m: m.macro) +macros = get_mapping(modules, lambda n, m: [m.macro.name], lambda m: m.macro) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/output/manifest.py --- a/moinformat/output/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/output/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Output context implementation manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -30,6 +30,6 @@ # Use names declared in each class to register the contexts: # output.name -> output -outputs = get_mapping(modules, lambda n, m: m.output.name, lambda m: m.output) +outputs = get_mapping(modules, lambda n, m: [m.output.name], lambda m: m.output) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/parsers/graphviz.py --- a/moinformat/parsers/graphviz.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/parsers/graphviz.py Wed Oct 06 00:03:06 2021 +0200 @@ -34,7 +34,7 @@ "A parser for Graphviz content, identifying format directives." - format = "graphviz" + formats = ["graphviz", "dot"] # Parser handler methods. diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/parsers/manifest.py --- a/moinformat/parsers/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/parsers/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin wiki parser manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -28,8 +28,8 @@ # Obtain all parsers. # Use names declared in each class to register the parsers: -# parser.format -> parser +# parser.formats -> parser -parsers = get_mapping(modules, lambda n, m: m.parser.format, lambda m: m.parser) +parsers = get_mapping(modules, lambda n, m: m.parser.formats, lambda m: m.parser) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/parsers/moin.py --- a/moinformat/parsers/moin.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/parsers/moin.py Wed Oct 06 00:03:06 2021 +0200 @@ -54,7 +54,7 @@ "A wiki region parser." - format = "moin" + formats = ["moin", "wiki"] def __init__(self, metadata, parsers=None, root=None): diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/parsers/table.py --- a/moinformat/parsers/table.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/parsers/table.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin wiki table parser. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -33,7 +33,7 @@ "A parser for improved table syntax." - format = "table" + formats = ["table"] # Principal parser methods. diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/parsers/wiki.py --- a/moinformat/parsers/wiki.py Wed Oct 06 00:00:30 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -#!/usr/bin/env python - -""" -Moin wiki table parser (alias). - -Copyright (C) 2018 Paul Boddie - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -from moinformat.parsers.moin import MoinParser - -# Parser functionality. - -class WikiParser(MoinParser): - - "An alias for the Moin parser." - - format = "wiki" - -parser = WikiParser - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/common.py --- a/moinformat/serialisers/common.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/common.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin serialiser support. -Copyright (C) 2017, 2018, 2019 Paul Boddie +Copyright (C) 2017, 2018, 2019, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,7 +23,8 @@ "General serialisation support." - format = None # defined by subclasses + input_formats = None # defined by subclasses + formats = None # defined by subclasses def __init__(self, metadata, serialisers=None): diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/html/graphviz.py --- a/moinformat/serialisers/html/graphviz.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/html/graphviz.py Wed Oct 06 00:03:06 2021 +0200 @@ -49,6 +49,9 @@ "Serialisation of Graphviz regions." + input_formats = ["graphviz", "dot"] + formats = ["html"] + def init(self): self.directives = {} diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/html/moin.py --- a/moinformat/serialisers/html/moin.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/html/moin.py Wed Oct 06 00:03:06 2021 +0200 @@ -27,7 +27,8 @@ "Serialisation of the page." - format = "html" + input_formats = ["moin", "wiki"] + formats = ["html"] def _region_tag(self, type): diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/html/table.py --- a/moinformat/serialisers/html/table.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/html/table.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ HTML serialiser. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -26,6 +26,8 @@ "Serialisation of the page." + input_formats = ["table"] + def continuation(self, text): pass diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/manifest.py --- a/moinformat/serialisers/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin wiki serialiser manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -30,6 +30,19 @@ # Use module paths to register the handlers: # output_format.input_format -> serialiser -serialisers = get_mapping(modules, lambda n, m: n, lambda m: m.serialiser) +def get_formats(n, m): + + """ + Given module name 'n', inspect the serialiser in module 'm', returning a + list of format names. + """ + + l = [] + for output_format in m.serialiser.formats: + for input_format in m.serialiser.input_formats: + l.append("%s.%s" % (output_format, input_format)) + return l + +serialisers = get_mapping(modules, get_formats, lambda m: m.serialiser) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/moin/graphviz.py --- a/moinformat/serialisers/moin/graphviz.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/moin/graphviz.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin Graphviz region serialiser. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -25,6 +25,9 @@ "Serialisation of the page." + input_formats = ["graphviz", "dot"] + formats = ["moin", "wiki"] + def start_block(self): pass diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/moin/moin.py --- a/moinformat/serialisers/moin/moin.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/moin/moin.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin wiki text serialiser. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -25,7 +25,8 @@ "Serialisation of the page." - format = "moin" + input_formats = ["moin", "wiki"] + formats = ["moin", "wiki"] def start_region(self, level, indent, type, extra): out = self.out diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/serialisers/moin/table.py --- a/moinformat/serialisers/moin/table.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/serialisers/moin/table.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Moin wiki table serialiser. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -25,6 +25,8 @@ "Serialisation of the page." + input_formats = ["table"] + def init(self): self.first_cell = False self.first_row = False diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/themes/manifest.py --- a/moinformat/themes/manifest.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/themes/manifest.py Wed Oct 06 00:03:06 2021 +0200 @@ -3,7 +3,7 @@ """ Theme implementation manifest. -Copyright (C) 2017, 2018 Paul Boddie +Copyright (C) 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -38,6 +38,6 @@ # Use module paths to register the contexts: # theme_name.output_format -> theme -themes = get_mapping(modules, lambda n, m: n, lambda m: m.theme) +themes = get_mapping(modules, lambda n, m: [n], lambda m: m.theme) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 4ee5060ca9b4 -r d81233407d70 moinformat/tree/moin.py --- a/moinformat/tree/moin.py Wed Oct 06 00:00:30 2021 +0200 +++ b/moinformat/tree/moin.py Wed Oct 06 00:03:06 2021 +0200 @@ -230,7 +230,7 @@ # Retain the same serialiser if no appropriate serialiser could be # obtained. - serialiser_name = "%s.%s" % (out.format, self.type) + serialiser_name = "%s.%s" % (out.formats[0], self.type) serialiser = out.get_serialiser(serialiser_name) # Serialise the region.