コード例 #1
0
def testis_URL():
    sample_schemes = ['http', 'https', 'ftp', 'ssh']
    for scheme in sample_schemes:
        result = wikiutil.is_URL(scheme + ':MoinMoin')
        assert result

    # arg without ':' which is a mandatory requirement
    result = wikiutil.is_URL('MoinMoin')
    assert not result
    # invalid scheme
    result = wikiutil.is_URL('invalid_scheme:MoinMoin')
    assert not result
コード例 #2
0
ファイル: __init__.py プロジェクト: steel-ne/moin
    def split_navilink(self, text):
        """
        Split navibar links into pagename, link to page

        Admin or user might want to use shorter navibar items by using
        the [[page|title]] or [[url|title]] syntax.

        Supported syntax:
            * PageName
            * WikiName:PageName
            * wiki:WikiName:PageName
            * url
            * all targets as seen above with title: [[target|title]]

        :param text: the text used in config or user preferences
        :rtype: tuple
        :returns: pagename or url, link to page or url
        """
        title = None
        wiki_local = ''  # means local wiki

        # Handle [[pagename|title]] or [[url|title]] formats
        if text.startswith('[[') and text.endswith(']]'):
            text = text[2:-2]
            try:
                target, title = text.split('|', 1)
                target = target.strip()
                title = title.strip()
            except (ValueError, TypeError):
                # Just use the text as is.
                target = text.strip()
        else:
            target = text

        if wikiutil.is_URL(target):
            if not title:
                title = target
            return target, title, wiki_local

        # remove wiki: url prefix
        if target.startswith("wiki:"):
            target = target[5:]

        wiki_name, namespace, field, item_name = split_interwiki(target)
        if wiki_name == 'Self':
            wiki_name = ''
        href = url_for_item(item_name,
                            namespace=namespace,
                            wiki_name=wiki_name,
                            field=field)
        if not title:
            title = shorten_fqname(CompositeName(namespace, field, item_name))
        return href, title, wiki_name