eric7.Utilities.__init__

Package implementing various functions/classes needed everywhere within eric.

Global Attributes

_escape
_escape_map
_slashmap
_uescape
_uunescape
codingBytes_regexps
coding_regexps
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.
convertLineEnds Function to convert the end of line characters.
decode Function to decode some byte text into a string.
decodeBytes Function to decode some byte text into a string.
decodeString Function to decode a string containing Unicode encoded characters.
encode Function to encode text into a byte text.
escape_entities Function to encode html entities.
escape_uentities Function to encode html entities.
extractFlags Function to extract eric specific flags out of the given text.
extractFlagsFromFile Function to extract eric specific flags out of the given file.
extractLineFlags Function to extract flags starting and ending with '__' from a line comment.
filterAnsiSequences Function to filter out ANSI escape sequences (color only).
generateDistroInfo Module function to generate a string with distribution infos.
generatePluginsVersionInfo Module function to generate a string with plugins version infos.
generateVersionInfo Module function to generate a string with various version infos.
getCoverageFileName Function to build a file name for a coverage data file.
getCoverageFileNames Function to build a list of coverage data file names.
getPercentReplacement Function to get the replacement for code.
getPercentReplacementHelp Function to get the help text for the supported %-codes.
getProfileFileName Function to build a file name for a profile data file.
getProfileFileNames Function to build a list of profile data file names.
getSysPath Module function to get the Python path (sys.path) of a specific interpreter.
getTestFileNames Function to build the potential file names of a test file.
get_coding Function to get the coding of a text.
get_codingBytes Function to get the coding of a bytes text.
html_encode Function to correctly encode a text for html.
html_udecode Function to correctly decode a html text to a unicode text.
html_uencode Function to correctly encode a unicode text for html.
linesep Function to return the line separator used by the editor.
normalizeCode Function to normalize the given code.
parseOptionString Function used to convert an option string into a list of options.
readEncodedFile Function to read a file and decode its contents into proper text.
readEncodedFileWithEncoding Function to read a file and decode its contents into proper text.
readEncodedFileWithHash Function to read a file, calculate a hash value and decode its contents into proper text.
readStringFromStream Module function to read a string from the given stream.
rxIndex Function to get the index (start position) of a regular expression match within some text.
slash Function to convert an escaped string to a string containing escape codes.
unescape_uentities Function to decode html entities.
unslash Function to convert a string containing escape codes to an escaped string.
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

None

Class Methods

None

Methods

CodingError Constructor
__repr__ Special method returning a representation of the exception.
__str__ Special method returning a string representation of the exception.

Static Methods

None

CodingError (Constructor)

CodingError(coding)

Constructor

coding (str)
coding to include in the message

CodingError.__repr__

__repr__()

Special method returning a representation of the exception.

Return:
string representing the error message
Return Type:
str

CodingError.__str__

__str__()

Special method returning a string representation of the exception.

Return:
string representing the error message
Return Type:
str
Up


__showwarning

__showwarning(message, category, filename, lineno, file=None, line=None)

Module function to raise a SyntaxError for a SyntaxWarning.

message (Class)
warning object
category (SyntaxWarning)
type object of the warning
filename (str)
name of the file causing the warning
lineno (int)
line number causing the warning
file (file)
file to write the warning message to (unused)
line (int)
line causing the warning (unused)
Raises err:
exception of type SyntaxError
Up


_percentReplacementFunc

_percentReplacementFunc(matchobj)

Protected function called for replacing % codes.

matchobj (re.Match)
match object for the code
Return:
replacement string
Return Type:
str
Up


convertLineEnds

convertLineEnds(text, eol)

Function to convert the end of line characters.

text (str)
text to be converted
eol (str)
new eol setting
Return:
text with converted eols
Return Type:
str
Up


decode

decode(text)

Function to decode some byte text into a string.

text (bytes)
byte text to decode
Return:
tuple of decoded text and encoding
Return Type:
tuple of (str, str)
Up


decodeBytes

decodeBytes(buffer)

Function to decode some byte text into a string.

buffer (bytes)
byte buffer to decode
Return:
decoded text
Return Type:
str
Up


decodeString

decodeString(text)

Function to decode a string containing Unicode encoded characters.

text (str)
text containing encoded chars
Return:
decoded text
Return Type:
str
Up


encode

encode(text, origEncoding, forcedEncoding="")

Function to encode text into a byte text.

text (str)
text to be encoded
origEncoding (str)
type of the original encoding
forcedEncoding (str)
encoding to be used for writing, if no coding line is present
Return:
tuple of encoded text and encoding used
Return Type:
tuple of (bytes, str)
Raises CodingError:
raised to indicate an invalid encoding
Up


escape_entities

escape_entities(m, escmap=_escape_map)

Function to encode html entities.

m (re.Match)
the match object
escmap (dict)
the map of entities to encode
Return:
the converted text
Return Type:
str
Up


escape_uentities

escape_uentities(m)

Function to encode html entities.

m (re.Match)
the match object
Return:
the converted text
Return Type:
str
Up


extractFlags

extractFlags(text)

Function to extract eric specific flags out of the given text.

Flags are contained in comments and are introduced by 'eflag:'. The rest of the line is interpreted as 'key = value'. value is analyzed for being an integer or float value. If that fails, it is assumed to be a string. If a key does not contain a '=' character, it is assumed to be a boolean flag. Flags are expected at the very end of a file. The search is ended, if a line without the 'eflag:' marker is found.

text (str)
text to be scanned
Return:
dictionary of string, boolean, complex, float and int
Return Type:
dict
Up


extractFlagsFromFile

extractFlagsFromFile(filename)

Function to extract eric specific flags out of the given file.

filename (str)
name of the file to be scanned
Return:
dictionary of string, boolean, complex, float and int
Return Type:
dict
Up


extractLineFlags

extractLineFlags(line, startComment=")

Function to extract flags starting and ending with '__' from a line comment.

line (str)
line to extract flags from
startComment (str)
string identifying the start of the comment
endComment (str)
string identifying the end of a comment
flagsLine (bool)
flag indicating to check for a flags only line
Return:
list containing the extracted flags
Return Type:
list of str
Up


filterAnsiSequences

filterAnsiSequences(txt)

Function to filter out ANSI escape sequences (color only).

txt (str)
text to be filtered
Return:
text without ANSI escape sequences
Return Type:
str
Up


generateDistroInfo

generateDistroInfo(linesep="\n")

Module function to generate a string with distribution infos.

linesep (str)
string to be used to separate lines
Return:
string with distribution infos
Return Type:
str
Up


generatePluginsVersionInfo

generatePluginsVersionInfo(linesep="\n")

Module function to generate a string with plugins version infos.

linesep (str)
string to be used to separate lines
Return:
string with plugins version infos
Return Type:
str
Up


generateVersionInfo

generateVersionInfo(linesep="\n")

Module function to generate a string with various version infos.

linesep (str)
string to be used to separate lines
Return:
string with version infos
Return Type:
str
Up


getCoverageFileName

getCoverageFileName(fn, mustExist=True)

Function to build a file name for a coverage data file.

fn (str)
file name basis to be used for the coverage data file name
mustExist (bool (optional))
flag indicating to check that the file exists (defaults to True)
Return:
coverage data file name
Return Type:
str
Up


getCoverageFileNames

getCoverageFileNames(fn)

Function to build a list of coverage data file names.

fn (str)
file name basis to be used for the coverage data file
Return:
list of existing coverage data files
Return Type:
list of str
Up


getPercentReplacement

getPercentReplacement(code)

Function to get the replacement for code.

code (str)
code indicator
Return:
replacement string
Return Type:
str
Up


getPercentReplacementHelp

getPercentReplacementHelp()

Function to get the help text for the supported %-codes.

Return:
help text
Return Type:
str
Up


getProfileFileName

getProfileFileName(fn, mustExist=True)

Function to build a file name for a profile data file.

fn (str)
file name basis to be used for the profile data file name
mustExist (bool (optional))
flag indicating to check that the file exists (defaults to True)
Return:
profile data file name
Return Type:
str
Up


getProfileFileNames

getProfileFileNames(fn)

Function to build a list of profile data file names.

fn (str)
file name basis to be used for the profile data file
Return:
list of existing profile data files
Return Type:
list of str
Up


getSysPath

getSysPath(interpreter)

Module function to get the Python path (sys.path) of a specific interpreter.

interpreter (str)
Python interpreter executable to get sys.path for
Return:
list containing sys.path of the interpreter; an empty list is returned, if the interpreter is the one used to run eric itself
Return Type:
list of str
Up


getTestFileNames

getTestFileNames(fn)

Function to build the potential file names of a test file.

The file names for the test file is built by prepending the string "test" and "test_" to the file name passed into this function and by appending the string "_test".

fn (str)
file name basis to be used for the test file names
Return:
file names of the corresponding test file
Return Type:
list of str
Up


get_coding

get_coding(text)

Function to get the coding of a text.

text (str)
text to inspect
Return:
coding string
Return Type:
str
Up


get_codingBytes

get_codingBytes(text)

Function to get the coding of a bytes text.

text (bytes)
bytes text to inspect
Return:
coding string
Return Type:
str
Up


html_encode

html_encode(text, pattern=_escape)

Function to correctly encode a text for html.

text (str)
text to be encoded
pattern (str)
search pattern for text to be encoded
Return:
the encoded text
Return Type:
str
Up


html_udecode

html_udecode(text, pattern=_uunescape)

Function to correctly decode a html text to a unicode text.

text (str)
text to be decoded
pattern (str)
search pattern for text to be decoded
Return:
the decoded text
Return Type:
str
Up


html_uencode

html_uencode(text, pattern=_uescape)

Function to correctly encode a unicode text for html.

text (str)
text to be encoded
pattern (str)
search pattern for text to be encoded
Return:
the encoded text
Return Type:
str
Up


linesep

linesep()

Function to return the line separator used by the editor.

Return:
line separator used by the editor
Return Type:
str
Up


normalizeCode

normalizeCode(codestring)

Function to normalize the given code.

codestring (str)
code to be normalized
Return:
normalized code
Return Type:
str
Up


parseOptionString

parseOptionString(s)

Function used to convert an option string into a list of options.

s (str)
option string
Return:
list of options
Return Type:
list of str
Up


readEncodedFile

readEncodedFile(filename)

Function to read a file and decode its contents into proper text.

filename (str)
name of the file to read
Return:
tuple of decoded text and encoding
Return Type:
tuple of (str, str)
Up


readEncodedFileWithEncoding

readEncodedFileWithEncoding(filename, encoding)

Function to read a file and decode its contents into proper text.

filename (str)
name of the file to read
encoding (str)
encoding to be used to read the file
Return:
tuple of decoded text and encoding
Return Type:
tuple of (str, str)
Up


readEncodedFileWithHash

readEncodedFileWithHash(filename)

Function to read a file, calculate a hash value and decode its contents into proper text.

filename (str)
name of the file to read
Return:
tuple of decoded text, encoding and hash value
Return Type:
tuple of (str, str, str)
Up


readStringFromStream

readStringFromStream(stream)

Module function to read a string from the given stream.

stream (QDataStream)
data stream opened for reading
Return:
string read from the stream
Return Type:
str
Up


rxIndex

rxIndex(rx, txt)

Function to get the index (start position) of a regular expression match within some text.

rx (re.Pattern)
regular expression object as created by re.compile()
txt (str)
text to be scanned
Return:
start position of the match or -1 indicating no match was found
Return Type:
int
Up


slash

slash(txt)

Function to convert an escaped string to a string containing escape codes.

Note: This is the reverse of 'unslash()'.

txt (str)
string to be converted
Return:
converted string containing escaped escape codes
Return Type:
str
Up


unescape_uentities

unescape_uentities(m)

Function to decode html entities.

m (re.Match)
the match object
Return:
the converted text
Return Type:
str
Up


unslash

unslash(txt)

Function to convert a string containing escape codes to an escaped string.

txt (str)
string to be converted
Return:
converted string containing escape codes
Return Type:
str
Up


writeEncodedFile

writeEncodedFile(filename, text, origEncoding, forcedEncoding="")

Function to write a file with properly encoded text.

filename (str)
name of the file to read
text (str)
text to be written
origEncoding (str)
type of the original encoding
forcedEncoding (str)
encoding to be used for writing, if no coding line is present
Return:
encoding used for writing the file
Return Type:
str
Up