MoinLight

Annotated moinformat/links/__init__.py

97:d3fb25874a0a
2018-07-26 Paul Boddie Supported interwiki mapping details in the make_linker convenience function. Supported mapping arguments in the conversion script. Added an interwiki link to the relevant test.
paul@91 1
#!/usr/bin/env python
paul@91 2
paul@91 3
"""
paul@91 4
Linking scheme implementations.
paul@91 5
paul@91 6
Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
paul@91 7
paul@91 8
This program is free software; you can redistribute it and/or modify it under
paul@91 9
the terms of the GNU General Public License as published by the Free Software
paul@91 10
Foundation; either version 3 of the License, or (at your option) any later
paul@91 11
version.
paul@91 12
paul@91 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@91 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@91 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@91 16
details.
paul@91 17
paul@91 18
You should have received a copy of the GNU General Public License along with
paul@91 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@91 20
"""
paul@91 21
paul@91 22
from moinformat.links.manifest import linkers
paul@91 23
paul@91 24
# Top-level functions.
paul@91 25
paul@91 26
def get_linker(name):
paul@91 27
paul@91 28
    """
paul@94 29
    Return the linking scheme handler class with the given 'name' or None if no
paul@94 30
    such handler is found.
paul@91 31
    """
paul@91 32
paul@91 33
    return linkers.get(name)
paul@91 34
paul@97 35
def make_linker(name, pagename, mapping=None):
paul@94 36
paul@94 37
    """
paul@94 38
    Return a linking scheme handler with the given 'name' and using the given
paul@97 39
    'pagename' and interwiki 'mapping'.
paul@94 40
    """
paul@94 41
paul@94 42
    linker_cls = get_linker(name)
paul@94 43
    if not linker_cls:
paul@94 44
        return None
paul@94 45
paul@97 46
    return linker_cls(pagename, mapping)
paul@94 47
paul@91 48
# vim: tabstop=4 expandtab shiftwidth=4