def _data_url(self, path): """Get a data: url for the broken qutebrowser logo.""" data = utils.read_file(path, binary=True) filename = utils.resource_filename(path) mimetype = mimetypes.guess_type(filename) assert mimetype is not None, path return urlutils.data_url(mimetype[0], data).toString()
def data_url(path): """Get a data: url for the broken qutebrowser logo.""" data = utils.read_file(path, binary=True) filename = utils.resource_filename(path) mimetype = mimetypes.guess_type(filename) assert mimetype is not None, path b64 = base64.b64encode(data).decode('ascii') return 'data:{};charset=utf-8;base64,{}'.format(mimetype[0], b64)
def resource_url(path): """Load images from a relative path (to qutebrowser). Arguments: path: The relative path to the image """ image = utils.resource_filename(path) return QUrl.fromLocalFile(image).toString(QUrl.FullyEncoded)
def _resource_url(self, path): """Load images from a relative path (to qutebrowser). Arguments: path: The relative path to the image """ image = utils.resource_filename(path) return QUrl.fromLocalFile(image).toString(QUrl.FullyEncoded)
def dirbrowser_html(path): """Get the directory browser web page. Args: path: The directory path. Return: The HTML of the web page. """ title = "Browse directory: {}".format(path) template = jinja.env.get_template('dirbrowser.html') # pylint: disable=no-member # https://bitbucket.org/logilab/pylint/issue/490/ folder_icon = utils.resource_filename('img/folder.svg') file_icon = utils.resource_filename('img/file.svg') folder_url = QUrl.fromLocalFile(folder_icon).toString(QUrl.FullyEncoded) file_url = QUrl.fromLocalFile(file_icon).toString(QUrl.FullyEncoded) if is_root(path): parent = None else: parent = os.path.dirname(path) try: all_files = os.listdir(path) except OSError as e: html = jinja.env.get_template('error.html').render( title="Error while reading directory", url='file://%s' % path, error=str(e), icon='') return html.encode('UTF-8', errors='xmlcharrefreplace') files = get_file_list(path, all_files, os.path.isfile) directories = get_file_list(path, all_files, os.path.isdir) html = template.render(title=title, url=path, icon='', parent=parent, files=files, directories=directories, folder_url=folder_url, file_url=file_url) return html.encode('UTF-8', errors='xmlcharrefreplace')
def _resource_url(self, path: str) -> str: """Load images from a relative path (to qutebrowser). Arguments: path: The relative path to the image """ image = utils.resource_filename(path) url = QUrl.fromLocalFile(image) urlstr = url.toString(QUrl.FullyEncoded) # type: ignore[arg-type] return urlstr
def resource_url(path, qutescheme=False): """Load images from a relative path (to qutebrowser). Arguments: path: The relative path to the image qutescheme: If the logo needs to be served via a qute:// scheme. This is the case when we want to show an error page from there. """ if qutescheme: url = QUrl() url.setScheme('qute') url.setHost('resource') url.setPath('/' + path) qtutils.ensure_valid(url) return url.toString(QUrl.FullyEncoded) else: full_path = utils.resource_filename(path) return QUrl.fromLocalFile(full_path).toString(QUrl.FullyEncoded)
def _data_url(self, path: str) -> str: """Get a data: url for the broken qutebrowser logo.""" data = utils.read_file(path, binary=True) filename = utils.resource_filename(path) mimetype = utils.guess_mimetype(filename) return urlutils.data_url(mimetype, data).toString()