eric4.Utilities.__init__
Package implementing various functions/classes needed everywhere within eric4.
Global Attributes
_escape |
_escape_map |
_uescape |
coding_regexps |
configDir |
supportedCodecs |
Classes
CodingError |
Class implementing an exception, which is raised, if a given coding is incorrect. |
Functions
__showwarning |
Module function to raise a SyntaxError for a SyntaxWarning. |
_percentReplacementFunc |
Protected function called for replacing % codes. |
checkBlacklistedVersions |
Module functions to check for blacklisted versions of the prerequisites. |
compactPath |
Function to return a compacted path fitting inside the given width. |
compile |
Function to compile one Python source file to Python bytecode. |
convertLineEnds |
Function to convert the end of line characters. |
decode |
Function to decode a text. |
decodeBytes |
Function to decode some text into a unicode string. |
decodeWithHash |
Function to decode a text and calculate the MD5 hash. |
direntries |
Function returning a list of all files and directories. |
encode |
Function to encode a text. |
escape_entities |
Function to encode html entities. |
escape_uentities |
Function to encode html entities. |
fromNativeSeparators |
Function returning a path, that is using "/" separator characters. |
generateDistroInfo |
Module function to generate a string with distribution infos. |
generatePluginsVersionInfo |
Module function to generate a string with plugins version infos. |
generatePySideToolPath |
Module function to generate the executable path for a PySide tool. |
generateQtToolName |
Module function to generate the executable name for a Qt tool like designer. |
generateVersionInfo |
Module function to generate a string with various version infos. |
getConfigDir |
Module function to get the name of the directory storing the config data. |
getDirs |
Function returning a list of all directories below path. |
getEnvironmentEntry |
Module function to get an environment entry. |
getExecutablePath |
Function to build the full path of an executable file from the environment. |
getHomeDir |
Function to get a users home directory |
getPercentReplacement |
Function to get the replacement for code. |
getPercentReplacementHelp |
Function to get the help text for the supported %-codes. |
getPythonLibPath |
Function to determine the path to Python's library. |
getPythonVersion |
Function to get the Python version (major, minor) as an integer value. |
getQtMacBundle |
Module function to determine the correct Mac OS X bundle name for Qt tools. |
getTestFileName |
Function to build the filename of a unittest file. |
getUserName |
Function to get the user name. |
get_coding |
Function to get the coding of a text. |
hasEnvironmentEntry |
Module function to check, if the environment contains an entry. |
html_encode |
Function to correctly encode a text for html. |
html_uencode |
Function to correctly encode a unicode text for html. |
isExecutable |
Function to check, if a file is executable. |
isinpath |
Function to check for an executable file. |
joinext |
Function to join a file extension to a path. |
linesep |
Function to return the lineseparator used by the editor. |
normabsjoinpath |
Function returning a normalized, absolute path of the joined parts passed into it. |
normabspath |
Function returning a normalized, absolute path. |
normcaseabspath |
Function returning an absolute path, that is normalized with respect to its case and references. |
normcasepath |
Function returning a path, that is normalized with respect to its case and references. |
normjoinpath |
Function returning a normalized path of the joined parts passed into it. |
parseEnvironmentString |
Function used to convert an environment string into a list of environment settings. |
parseOptionString |
Function used to convert an option string into a list of options. |
parseString |
Function used to convert a string into a list. |
posix_GetUserName |
Function to get the user name under Posix systems. |
prepareQtMacBundle |
Module function for starting Qt tools that are Mac OS X bundles. |
pwDecode |
Module function to decode a password. |
pwEncode |
Module function to encode a password. |
readEncodedFile |
Function to read a file and decode it's contents into proper text. |
relpath |
Return a relative version of a path. |
samepath |
Function to compare two paths. |
setConfigDir |
Module function to set the name of the directory storing the config data. |
splitPath |
Function to split a pathname into a directory part and a file part. |
toNativeSeparators |
Function returning a path, that is using native separator characters. |
toUnicode |
Public method to convert a string to unicode. |
win32_GetUserName |
Function to get the user name under Win32. |
win32_Kill |
Function to provide an os.kill equivalent for Win32. |
writeEncodedFile |
Function to write a file with properly encoded text. |
CodingError
Class implementing an exception, which is raised, if a given coding is incorrect.
Derived from
Exception
Class Attributes
Class Methods
Methods
CodingError |
Constructor |
__repr__ |
Private method returning a representation of the exception. |
__str__ |
Private method returning a string representation of the exception. |
Static Methods
CodingError (Constructor)
CodingError(coding)
Constructor
CodingError.__repr__
__repr__()
Private method returning a representation of the exception.
- Returns:
-
string representing the error message
CodingError.__str__
__str__()
Private method returning a string representation of the exception.
- Returns:
-
string representing the error message
__showwarning
__showwarning(message, category, filename, lineno, file = None, line = "")
Module function to raise a SyntaxError for a SyntaxWarning.
- message
-
warning object
- category
-
type object of the warning
- filename
-
name of the file causing the warning (string)
- lineno
-
line number causing the warning (integer)
- file
-
file to write the warning message to (ignored)
- line
-
line causing the warning (ignored)
- Raises SyntaxError:
-
_percentReplacementFunc
_percentReplacementFunc(matchobj)
Protected function called for replacing % codes.
- matchobj
-
matchobject for the code
- Returns:
-
replacement string
checkBlacklistedVersions
checkBlacklistedVersions()
Module functions to check for blacklisted versions of the prerequisites.
- Returns:
-
flag indicating good versions were found (boolean)
compactPath
compactPath(path, width, measure = len)
Function to return a compacted path fitting inside the given width.
- path
-
path to be compacted (string)
- width
-
width for the compacted path (integer)
- measure
-
reference to a function used to measure the length of the string
- Returns:
-
compacted path (string)
compile
compile(file, codestring = "")
Function to compile one Python source file to Python bytecode.
- file
-
source filename (string)
- codestring
-
string containing the code to compile (string)
- Returns:
-
A tuple indicating status (1 = an error was found), the
filename, the linenumber, the index number, the code string and
the error message (boolean, string, string, string, string, string).
The values are only valid, if the status equals 1.
convertLineEnds
convertLineEnds(text, eol)
Function to convert the end of line characters.
- text
-
text to be converted (string)
- eol
-
new eol setting (string)
- Returns:
-
text with converted eols (string)
decode
decode(text)
Function to decode a text.
- text
-
text to decode (string)
- Returns:
-
decoded text and encoding
decodeBytes
decodeBytes(buffer)
Function to decode some text into a unicode string.
- buffer
-
string buffer to decode (string)
- Returns:
-
decoded text (unicode)
decodeWithHash
decodeWithHash(text)
Function to decode a text and calculate the MD5 hash.
- text
-
text to decode (string)
- Returns:
-
decoded text, encoding and MD5 hash
direntries
direntries(path, filesonly=False, pattern=None, followsymlinks=True, checkStop=None)
Function returning a list of all files and directories.
- path
-
root of the tree to check
- filesonly
-
flag indicating that only files are wanted
- pattern
-
a filename pattern to check against
- followsymlinks
-
flag indicating whether symbolic links
should be followed
- checkStop
-
function to be called to check for a stop
- Returns:
-
list of all files and directories in the tree rooted
at path. The names are expanded to start with path.
encode
encode(text, orig_coding)
Function to encode a text.
- text
-
text to encode (string)
- orig_coding
-
type of the original coding (string)
- Returns:
-
encoded text and encoding
escape_entities
escape_entities(m, map=_escape_map)
Function to encode html entities.
- m
-
the match object
- map
-
the map of entities to encode
- Returns:
-
the converted text (string)
escape_uentities
escape_uentities(m)
Function to encode html entities.
- m
-
the match object
- Returns:
-
the converted text (string)
fromNativeSeparators
fromNativeSeparators(path)
Function returning a path, that is using "/" separator characters.
- path
-
path to be converted (QString)
- Returns:
-
path with converted separator characters (QString)
generateDistroInfo
generateDistroInfo(linesep = '\n')
Module function to generate a string with distribution infos.
- linesep
-
string to be used to separate lines (string)
- Returns:
-
string with plugins version infos (string)
generatePluginsVersionInfo
generatePluginsVersionInfo(linesep = '\n')
Module function to generate a string with plugins version infos.
- linesep
-
string to be used to separate lines (string)
- Returns:
-
string with plugins version infos (string)
generatePySideToolPath
generatePySideToolPath(toolname)
Module function to generate the executable path for a PySide tool.
- toolname
-
base name of the tool (string or QString)
- Returns:
-
the PySide tool path with extension (string)
generateQtToolName
generateQtToolName(toolname)
Module function to generate the executable name for a Qt tool like designer.
- toolname
-
base name of the tool (string or QString)
- Returns:
-
the Qt tool name without extension (string)
generateVersionInfo
generateVersionInfo(linesep = '\n')
Module function to generate a string with various version infos.
- linesep
-
string to be used to separate lines (string)
- Returns:
-
string with version infos (string)
getConfigDir
getConfigDir()
Module function to get the name of the directory storing the config data.
- Returns:
-
directory name of the config dir (string)
getDirs
getDirs(path, excludeDirs)
Function returning a list of all directories below path.
- path
-
root of the tree to check
- excludeDirs
-
basename of directories to ignore
- Returns:
-
list of all directories found
getEnvironmentEntry
getEnvironmentEntry(key, default = None)
Module function to get an environment entry.
- key
-
key of the requested environment entry (string)
- default
-
value to be returned, if the environment doesn't contain
the requested entry (string)
- Returns:
-
the requested entry or the default value, if the entry wasn't
found (string or None)
getExecutablePath
getExecutablePath(file)
Function to build the full path of an executable file from the environment.
- file
-
filename of the executable to check (string)
- Returns:
-
full executable name, if the executable file is accessible
via the searchpath defined by the PATH environment variable, or an
empty string otherwise.
getHomeDir
getHomeDir()
Function to get a users home directory
- Returns:
-
home directory (string)
getPercentReplacement
getPercentReplacement(code)
Function to get the replacement for code.
- code
-
code indicator (string or QString)
- Returns:
-
replacement string (string)
getPercentReplacementHelp
getPercentReplacementHelp()
Function to get the help text for the supported %-codes.
- Returns:
-
help text (QString)
getPythonLibPath
getPythonLibPath()
Function to determine the path to Python's library.
- Returns:
-
path to the Python library (string)
getPythonVersion
getPythonVersion()
Function to get the Python version (major, minor) as an integer value.
- Returns:
-
An integer representing major and minor version number (integer)
getQtMacBundle
getQtMacBundle(toolname)
Module function to determine the correct Mac OS X bundle name for Qt tools.
- toolname
-
plain name of the tool (e.g. "designer") (string or QString)
- Returns:
-
bundle name of the Qt tool (string)
getTestFileName
getTestFileName(fn)
Function to build the filename of a unittest file.
The filename for the unittest file is built by prepending
the string "test" to the filename passed into this function.
- fn
-
filename basis to be used for the unittest filename (string)
- Returns:
-
filename of the corresponding unittest file (string)
getUserName
getUserName()
Function to get the user name.
- Returns:
-
user name (string)
get_coding
get_coding(text)
Function to get the coding of a text.
- text
-
text to inspect (string)
- Returns:
-
coding string
hasEnvironmentEntry
hasEnvironmentEntry(key)
Module function to check, if the environment contains an entry.
- key
-
key of the requested environment entry (string)
- Returns:
-
flag indicating the presence of the requested entry (boolean)
html_encode
html_encode(text, pattern=_escape)
Function to correctly encode a text for html.
- text
-
text to be encoded (string)
- pattern
-
search pattern for text to be encoded (string)
- Returns:
-
the encoded text (string)
html_uencode
html_uencode(text, pattern=_uescape)
Function to correctly encode a unicode text for html.
- text
-
text to be encoded (string)
- pattern
-
search pattern for text to be encoded (string)
- Returns:
-
the encoded text (string)
isExecutable
isExecutable(exe)
Function to check, if a file is executable.
- exe
-
filename of the executable to check (string)
- Returns:
-
flag indicating executable status (boolean)
isinpath
isinpath(file)
Function to check for an executable file.
- file
-
filename of the executable to check (string)
- Returns:
-
flag to indicate, if the executable file is accessible
via the searchpath defined by the PATH environment variable.
joinext
joinext(prefix, ext)
Function to join a file extension to a path.
The leading "." of ext is replaced by a platform specific extension
separator if necessary.
- prefix
-
the basepart of the filename (string)
- ext
-
the extension part (string)
- Returns:
-
the complete filename (string)
linesep
linesep()
Function to return the lineseparator used by the editor.
- Returns:
-
line separator used by the editor (string)
normabsjoinpath
normabsjoinpath(a, *p)
Function returning a normalized, absolute path of the joined parts passed into it.
- a
-
first path to be joined (string)
- p
-
variable number of path parts to be joind (string)
- Returns:
-
absolute, normalized path (string)
normabspath
normabspath(path)
Function returning a normalized, absolute path.
- path
-
file path (string)
- Returns:
-
absolute, normalized path (string)
normcaseabspath
normcaseabspath(path)
Function returning an absolute path, that is normalized with respect to its case
and references.
- path
-
file path (string)
- Returns:
-
absolute, normalized path (string)
normcasepath
normcasepath(path)
Function returning a path, that is normalized with respect to its case and references.
- path
-
file path (string)
- Returns:
-
case normalized path (string)
normjoinpath
normjoinpath(a, *p)
Function returning a normalized path of the joined parts passed into it.
- a
-
first path to be joined (string)
- p
-
variable number of path parts to be joind (string)
- Returns:
-
normalized path (string)
parseEnvironmentString
parseEnvironmentString(s)
Function used to convert an environment string into a list of environment settings.
- s
-
environment string (string or QString)
- Returns:
-
list of environment settings (list of strings)
parseOptionString
parseOptionString(s)
Function used to convert an option string into a list of options.
- s
-
option string (string or QString)
- Returns:
-
list of options (list of strings)
parseString
parseString(s, rx)
Function used to convert a string into a list.
- s
-
string to be parsed (string or QString)
- rx
-
regex defining the parse pattern (QRegExp)
- Returns:
-
list of parsed data (list of strings)
posix_GetUserName
posix_GetUserName()
Function to get the user name under Posix systems.
- Returns:
-
user name (string)
prepareQtMacBundle
prepareQtMacBundle(toolname, version, args)
Module function for starting Qt tools that are Mac OS X bundles.
- toolname
-
plain name of the tool (e.g. "designer") (string or QString)
- version
-
indication for the requested version (Qt 4) (integer)
- args
-
name of input file for tool, if any (QStringList)
- Returns:
-
command-name and args for QProcess (tuple)
pwDecode
pwDecode(epw)
Module function to decode a password.
- pw
-
encoded password to decode (string or QString)
- Returns:
-
decoded password (string)
pwEncode
pwEncode(pw)
Module function to encode a password.
- pw
-
password to encode (string or QString)
- Returns:
-
encoded password (string)
readEncodedFile
readEncodedFile(filename)
Function to read a file and decode it's contents into proper text.
- filename
-
name of the file to read (string)
- Returns:
-
tuple of decoded text and encoding (string, string)
relpath
relpath(path, start = os.path.curdir)
Return a relative version of a path.
- path
-
path to make relative (string)
- start
-
path to make relative from (string)
samepath
samepath(f1, f2)
Function to compare two paths.
- f1
-
first path for the compare (string)
- f2
-
second path for the compare (string)
- Returns:
-
flag indicating whether the two paths represent the
same path on disk.
setConfigDir
setConfigDir(d)
Module function to set the name of the directory storing the config data.
- d
-
name of an existing directory (string)
splitPath
splitPath(name)
Function to split a pathname into a directory part and a file part.
- name
-
path name (string or QString)
- Returns:
-
a tuple of 2 strings (dirname, filename).
toNativeSeparators
toNativeSeparators(path)
Function returning a path, that is using native separator characters.
- path
-
path to be converted (QString)
- Returns:
-
path with converted separator characters (QString)
toUnicode
toUnicode(s)
Public method to convert a string to unicode.
If the passed in string is of type QString, it is
simply returned unaltered, assuming, that it is already
a unicode string. For all other strings, various codes
are tried until one converts the string without an error.
If all codecs fail, the string is returned unaltered.
- s
-
string to be converted (string or QString)
- Returns:
-
converted string (unicode or QString)
win32_GetUserName
win32_GetUserName()
Function to get the user name under Win32.
- Returns:
-
user name (string)
win32_Kill
win32_Kill(pid)
Function to provide an os.kill equivalent for Win32.
- pid
-
process id
writeEncodedFile
writeEncodedFile(filename, text, orig_coding)
Function to write a file with properly encoded text.
- filename
-
name of the file to read (string)
- text
-
text to be written (string)
- orig_coding
-
type of the original encoding (string)
- Returns:
-
encoding used for writing the file (string)