Table Of Contents

Previous topic

EdToolBar

Next topic

EdFile

This Page

phoenix_title ed_txt

Text/Unicode handling functions and File wrapper class


class_hierarchy Inheritance Diagram

Inheritance diagram for module ed_txt

Inheritance diagram of ed_txt


function_summary Functions Summary

CheckBom Try to look for a bom byte at the beginning of the given line
CheckMagicComment Try to decode the given text on the basis of a magic
DecodeString Decode the given string to Unicode using the provided
EncodeString Try and encode a given unicode object to a string
FallbackReader Guess the encoding of a file by brute force by trying one
GetEncodings Get a list of possible encodings to try from the locale information
GuessEncoding Attempt to guess an encoding

class_summary Classes Summary

EdFile Wrapper for representing a file object that stores data
FileLoadEvent Event to signal that a chunk of text haes been read
FileReadJob Job for running an async file read in a background thread
ReadError Error happened while trying to read the file
WriteError Error happened while trying to write the file

Functions



CheckBom(line)

Try to look for a bom byte at the beginning of the given line

Parameters:line – line (first line) of a file
Returns:encoding or None


CheckMagicComment(lines)

Try to decode the given text on the basis of a magic comment if one is present.

Parameters:lines – list of lines to check for a magic comment
Returns:encoding or None


DecodeString(string, encoding=None)

Decode the given string to Unicode using the provided encoding or the DEFAULT_ENCODING if None is provided.

Parameters:
  • string – string to decode
  • encoding – encoding to decode string with


EncodeString(string, encoding=None)

Try and encode a given unicode object to a string with the provided encoding returning that string. The default encoding will be used if None is given for the encoding.

Parameters:
  • string – unicode object to encode into a string
  • encoding – encoding to use for conversion


FallbackReader(fname)

Guess the encoding of a file by brute force by trying one encoding after the next until something succeeds.

Parameters:fname – file path to read from

Todo

deprecate this method



GetEncodings()

Get a list of possible encodings to try from the locale information

Returns:list of strings


GuessEncoding(fname, sample)

Attempt to guess an encoding

Parameters:
  • fname – filename
  • sample – pre-read amount
Returns:

encoding or None