Пример #1
0
 def test_content_url_encoding_safe(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = '".jpg/abc'
     print((s.content_url(path, "")))
     print(("/" + quote(path, "")))
     assert s.content_url(path, "") == "/" + quote(path, "")
Пример #2
0
 def test_content_url_encoding_safe(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = '".jpg/abc'
     print(s.content_url(path, ""))
     print("/" + quote(path, ""))
     assert s.content_url(path, "") == "/" + quote(path, "")
Пример #3
0
def test_node_full_url_quoted():
    s = Site(TEST_SITE_ROOT)
    s.config.base_url = 'http://localhost'
    r = RootNode(TEST_SITE_ROOT.child_folder('content'), s)
    assert not r.module
    n = r.add_node(TEST_SITE_ROOT.child_folder('content/blo~g'))
    assert n.full_url == 'http://localhost/' + quote('blo~g')
    c = r.add_node(TEST_SITE_ROOT.child_folder('content/blo~g/2010/december'))
    assert c.full_url == 'http://localhost/' + quote('blo~g/2010/december')
Пример #4
0
def test_node_full_url_quoted():
    s = Site(TEST_SITE_ROOT)
    s.config.base_url = 'http://localhost'
    r = RootNode(TEST_SITE_ROOT.child_folder('content'), s)
    assert not r.module
    n = r.add_node(TEST_SITE_ROOT.child_folder('content/blo~g'))
    assert n.full_url == 'http://localhost/' + quote('blo~g')
    c = r.add_node(TEST_SITE_ROOT.child_folder('content/blo~g/2010/december'))
    assert c.full_url == 'http://localhost/' + quote('blo~g/2010/december')
Пример #5
0
    def test_textlinks(self):
        d = {
            'objects': 'template/variables',
            'plugins': 'plugins/metadata',
            'sorter': 'plugins/sorter'
        }
        text = """
{%% markdown %%}
[[!!img/hyde-logo.png]]
*   [Rich object model][hyde objects] and
    [overridable hierarchical metadata]([[ %(plugins)s ]]) thats available
    for use in templates.
*   Configurable [sorting][], filtering and grouping support.

[hyde objects]: [[ %(objects)s ]]
[sorting]: [[%(sorter)s]]
{%% endmarkdown %%}
"""
        site = Site(TEST_SITE)
        site.config.plugins = ['hyde.ext.plugins.text.TextlinksPlugin']
        site.config.base_url = 'http://example.com/'
        site.config.media_url = '/media'
        tlink = File(site.content.source_folder.child('tlink.html'))
        tlink.write(text % d)
        print((tlink.read_all()))
        gen = Generator(site)
        gen.generate_all()
        f = File(site.config.deploy_root_path.child(tlink.name))
        assert f.exists
        html = f.read_all()
        assert html
        for name, path in list(d.items()):

            assert site.config.base_url + quote(path) in html
        assert '/media/img/hyde-logo.png' in html
Пример #6
0
    def test_textlinks(self):
        d = {
            'objects': 'template/variables',
            'plugins': 'plugins/metadata',
            'sorter': 'plugins/sorter'
        }
        text = """
{%% markdown %%}
[[!!img/hyde-logo.png]]
*   [Rich object model][hyde objects] and
    [overridable hierarchical metadata]([[ %(plugins)s ]]) thats available
    for use in templates.
*   Configurable [sorting][], filtering and grouping support.

[hyde objects]: [[ %(objects)s ]]
[sorting]: [[%(sorter)s]]
{%% endmarkdown %%}
"""
        site = Site(TEST_SITE)
        site.config.plugins = ['hyde.ext.plugins.text.TextlinksPlugin']
        site.config.base_url = 'http://example.com/'
        site.config.media_url = '/media'
        tlink = File(site.content.source_folder.child('tlink.html'))
        tlink.write(text % d)
        print((tlink.read_all()))
        gen = Generator(site)
        gen.generate_all()
        f = File(site.config.deploy_root_path.child(tlink.name))
        assert f.exists
        html = f.read_all()
        assert html
        for name, path in list(d.items()):

            assert site.config.base_url + quote(path) in html
        assert '/media/img/hyde-logo.png' in html
Пример #7
0
 def test_content_url_encoding(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = '".jpg'
     assert s.content_url(path) == "/" + quote(path)
Пример #8
0
def _encode_path(base, path, safe):
    base = base.strip().replace(os.sep, '/')
    path = path.strip().replace(os.sep, '/')
    path = quote(path, safe) if safe is not None else quote(path)
    full_path = base.rstrip('/') + '/' + path.lstrip('/')
    return full_path
Пример #9
0
 def test_content_url_encoding(self):
     s = Site(self.SITE_PATH, config=self.config)
     s.load()
     path = '".jpg'
     assert s.content_url(path) == "/" + quote(path)
Пример #10
0
def _encode_path(base, path, safe):
    base = base.strip().replace(os.sep, '/')
    path = path.strip().replace(os.sep, '/')
    path = quote(path, safe) if safe is not None else quote(path)
    full_path = base.rstrip('/') + '/' + path.lstrip('/')
    return full_path
Пример #11
0
def urlencode(ctx, url, safe=None):
    if safe is not None:
        return quote(url.encode('utf8'), safe)
    else:
        return quote(url.encode('utf8'))