WebBrowser/Tools/WebBrowserTools.py

Sat, 06 Feb 2016 17:43:59 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 06 Feb 2016 17:43:59 +0100
branch
QtWebEngine
changeset 4725
b19ff70ba509
child 4741
f9e1adc69076
permissions
-rw-r--r--

Continued porting the web browser.

# -*- coding: utf-8 -*-

# Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing tool functions for the web browser.
"""

from __future__ import unicode_literals
try:
    str = unicode       # __IGNORE_EXCEPTION__
except NameError:
    pass

from PyQt5.QtCore import QFile, QByteArray


def readAllFileContents(filename):
    """
    Function to read the string contents of the given file.
    
    @param filename name of the file
    @type str
    @return contents of the file
    @rtype str
    """
    return str(readAllFileByteContents(filename), encoding="utf-8")


def readAllFileByteContents(filename):
    """
    Function to read the bytes contents of the given file.
    
    @param filename name of the file
    @type str
    @return contents of the file
    @rtype str
    """
    dataFile = QFile(filename)
    if filename and dataFile.open(QFile.ReadOnly):
        contents = dataFile.readAll()
        dataFile.close()
        return contents
    
    return QByteArray()

eric ide

mercurial