Rename about:... to qute:...
This commit is contained in:
parent
38ef8fe8c7
commit
90e56e6477
@ -48,7 +48,7 @@ from PyQt5.QtCore import pyqtSlot, QTimer, QEventLoop
|
||||
import qutebrowser
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
import qutebrowser.utils.config as config
|
||||
import qutebrowser.network.about as about
|
||||
import qutebrowser.network.qutescheme as qutescheme
|
||||
from qutebrowser.widgets.mainwindow import MainWindow
|
||||
from qutebrowser.widgets.crash import CrashDialog
|
||||
from qutebrowser.commands.keys import KeyParser
|
||||
@ -401,8 +401,8 @@ class QuteBrowser(QApplication):
|
||||
out = repr(r)
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
out = ': '.join([e.__class__.__name__, str(e)])
|
||||
about.pyeval_output = out
|
||||
self.mainwindow.tabs.openurl('about:pyeval')
|
||||
qutescheme.pyeval_output = out
|
||||
self.mainwindow.tabs.openurl('qute:pyeval')
|
||||
|
||||
def crash(self):
|
||||
"""Crash for debugging purposes.
|
||||
|
@ -21,7 +21,7 @@ import logging
|
||||
|
||||
from PyQt5.QtNetwork import QNetworkAccessManager
|
||||
|
||||
from qutebrowser.network.about import AboutSchemeHandler
|
||||
from qutebrowser.network.qutescheme import QuteSchemeHandler
|
||||
|
||||
|
||||
class NetworkManager(QNetworkAccessManager):
|
||||
@ -39,7 +39,7 @@ class NetworkManager(QNetworkAccessManager):
|
||||
super().__init__(parent)
|
||||
self._requests = {}
|
||||
self._scheme_handlers = {
|
||||
'about': AboutSchemeHandler,
|
||||
'qute': QuteSchemeHandler,
|
||||
}
|
||||
|
||||
def abort_requests(self):
|
||||
|
@ -15,12 +15,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Handler functions for different about:... pages."""
|
||||
"""Handler functions for different qute:... pages."""
|
||||
|
||||
from qutebrowser.network.schemehandler import (SchemeHandler,
|
||||
SpecialNetworkReply)
|
||||
from qutebrowser.utils.version import version
|
||||
from qutebrowser.utils.url import is_about_url, urlstring
|
||||
from qutebrowser.utils.url import urlstring
|
||||
|
||||
|
||||
_HTML_TEMPLATE = """
|
||||
@ -41,35 +41,33 @@ pyeval_output = None
|
||||
|
||||
|
||||
def handle(url):
|
||||
"""Handle about page with an url.
|
||||
"""Handle qute page with an url.
|
||||
|
||||
Args:
|
||||
url: The url (string) to serve the about page for.
|
||||
url: The url (string) to serve the qute page for.
|
||||
|
||||
Raise:
|
||||
ValueError if passed URL is not an about URL
|
||||
ValueError if passed URL is not an qute URL
|
||||
|
||||
Return:
|
||||
HTML content as bytes.
|
||||
|
||||
"""
|
||||
if not is_about_url(url):
|
||||
raise ValueError("URL {} is not an about URL".format(url))
|
||||
handler = getattr(AboutHandlers, _transform_url(url))
|
||||
handler = getattr(QuteHandlers, _transform_url(url))
|
||||
return handler()
|
||||
|
||||
|
||||
def _transform_url(url):
|
||||
"""Transform a special URL to an AboutHandlers method name.
|
||||
"""Transform a special URL to an QuteHandlers method name.
|
||||
|
||||
Args:
|
||||
url: The URL as string.
|
||||
|
||||
Return:
|
||||
The method name about_*
|
||||
The method name qute_*
|
||||
|
||||
"""
|
||||
return url.replace('http://', '').replace('about:', 'about_')
|
||||
return url.replace('http://', '').replace('qute:', 'qute_')
|
||||
|
||||
|
||||
def _get_html(title, snippet):
|
||||
@ -86,9 +84,9 @@ def _get_html(title, snippet):
|
||||
return _HTML_TEMPLATE.format(title=title, body=snippet).encode('UTF-8')
|
||||
|
||||
|
||||
class AboutSchemeHandler(SchemeHandler):
|
||||
class QuteSchemeHandler(SchemeHandler):
|
||||
|
||||
"""Scheme handler for about: URLs."""
|
||||
"""Scheme handler for qute: URLs."""
|
||||
|
||||
def createRequest(self, op, request, outgoingData=None):
|
||||
"""Create a new request.
|
||||
@ -110,16 +108,16 @@ class AboutSchemeHandler(SchemeHandler):
|
||||
return SpecialNetworkReply(request, data, "text/html", self.parent())
|
||||
|
||||
|
||||
class AboutHandlers:
|
||||
class QuteHandlers:
|
||||
|
||||
"""Handlers for about:... pages."""
|
||||
"""Handlers for qute:... pages."""
|
||||
|
||||
@classmethod
|
||||
def about_pyeval(cls):
|
||||
"""Handler for about:pyeval. Return HTML content as bytes."""
|
||||
def qute_pyeval(cls):
|
||||
"""Handler for qute:pyeval. Return HTML content as bytes."""
|
||||
return _get_html('pyeval', '<pre>{}</pre>'.format(pyeval_output))
|
||||
|
||||
@classmethod
|
||||
def about_version(cls):
|
||||
"""Handler for about:version. Return HTML content as bytes."""
|
||||
def qute_version(cls):
|
||||
"""Handler for qute:version. Return HTML content as bytes."""
|
||||
return _get_html('Version', '<pre>{}</pre>'.format(version()))
|
@ -154,9 +154,12 @@ def fuzzy_url(url):
|
||||
return newurl
|
||||
|
||||
|
||||
def is_about_url(url):
|
||||
def is_special_url(url):
|
||||
"""Return True if url is an about:... or other special URL."""
|
||||
return urlstring(url).replace('http://', '').startswith('about:')
|
||||
# FIXME this needs to be done is some nicer way
|
||||
_special_schemes = ['about', 'qute']
|
||||
return any([urlstring(url).replace('http://', '').startswith(scheme) for
|
||||
scheme in _special_schemes])
|
||||
|
||||
|
||||
def is_url(url):
|
||||
@ -195,9 +198,9 @@ def is_url(url):
|
||||
# An URL will never contain a space
|
||||
logging.debug('Contains space -> no url')
|
||||
return False
|
||||
elif is_about_url(url):
|
||||
# About URLs are always URLs, even with autosearch=False
|
||||
logging.debug('Is an about URL.')
|
||||
elif is_special_url(url):
|
||||
# Special URLs are always URLs, even with autosearch=False
|
||||
logging.debug('Is an special URL.')
|
||||
return True
|
||||
elif autosearch == 'dns':
|
||||
logging.debug('Checking via DNS')
|
||||
|
Loading…
Reference in New Issue
Block a user