Move file_url from utils.jinja to utils.urlutils
This commit is contained in:
parent
070e30658f
commit
86be7ad82c
@ -26,7 +26,7 @@ import traceback
|
||||
import jinja2
|
||||
import jinja2.exceptions
|
||||
|
||||
from qutebrowser.utils import utils, log
|
||||
from qutebrowser.utils import urlutils, log
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
@ -74,15 +74,6 @@ def resource_url(path):
|
||||
return QUrl.fromLocalFile(image).toString(QUrl.FullyEncoded)
|
||||
|
||||
|
||||
def file_url(path):
|
||||
"""Return a file:// url (as string) to the given local path.
|
||||
|
||||
Arguments:
|
||||
path: The absolute path to the local file
|
||||
"""
|
||||
return QUrl.fromLocalFile(path).toString(QUrl.FullyEncoded)
|
||||
|
||||
|
||||
def render(template, **kwargs):
|
||||
"""Render the given template and pass the given arguments to it."""
|
||||
try:
|
||||
@ -97,4 +88,4 @@ def render(template, **kwargs):
|
||||
|
||||
_env = jinja2.Environment(loader=Loader('html'), autoescape=_guess_autoescape)
|
||||
_env.globals['resource_url'] = resource_url
|
||||
_env.globals['file_url'] = file_url
|
||||
_env.globals['file_url'] = urlutils.file_url
|
||||
|
@ -570,3 +570,12 @@ def incdec_number(url, incdec, segments=None):
|
||||
return url
|
||||
|
||||
raise IncDecError("No number found in URL!", url)
|
||||
|
||||
|
||||
def file_url(path):
|
||||
"""Return a file:// url (as string) to the given local path.
|
||||
|
||||
Arguments:
|
||||
path: The absolute path to the local file
|
||||
"""
|
||||
return QUrl.fromLocalFile(path).toString(QUrl.FullyEncoded)
|
||||
|
@ -26,7 +26,7 @@ import collections
|
||||
import pytest
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
from qutebrowser.utils import jinja
|
||||
from qutebrowser.utils import urlutils
|
||||
|
||||
|
||||
class DirLayout:
|
||||
@ -86,7 +86,7 @@ class DirLayout:
|
||||
|
||||
def file_url(self):
|
||||
"""Return a file:// link to the directory."""
|
||||
return jinja.file_url(str(self.layout))
|
||||
return urlutils.file_url(str(self.layout))
|
||||
|
||||
def path(self, *parts):
|
||||
"""Return the path to the given file inside the layout folder."""
|
||||
|
@ -28,7 +28,7 @@ from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtNetwork import QNetworkRequest
|
||||
|
||||
from qutebrowser.browser.network import filescheme
|
||||
from qutebrowser.utils import jinja
|
||||
from qutebrowser.utils import urlutils
|
||||
|
||||
|
||||
@pytest.mark.parametrize('create_file, create_dir, filterfunc, expected', [
|
||||
@ -106,7 +106,7 @@ def _file_url(path):
|
||||
Arguments:
|
||||
path: The filepath as LocalPath (as handled by py.path)
|
||||
"""
|
||||
return jinja.file_url(str(path))
|
||||
return urlutils.file_url(str(path))
|
||||
|
||||
|
||||
class TestDirbrowserHtml:
|
||||
|
@ -694,3 +694,7 @@ class TestIncDecNumber:
|
||||
|
||||
assert excinfo.value.url == url
|
||||
assert str(excinfo.value) == expected_str
|
||||
|
||||
|
||||
def test_file_url():
|
||||
assert urlutils.file_url('/foo/bar') == 'file:///foo/bar'
|
||||
|
Loading…
Reference in New Issue
Block a user