GMime.Charset

Fields

Name

Type

Access

Description

level

int

r/w

charset level

mask

int

r/w

charset mask

Methods

class

best (inbuf, inlen)

class

canon_name (charset)

class

iconv_name (charset)

class

iso_to_windows (isocharset)

class

language (charset)

class

locale_name ()

class

map_init ()

class

map_shutdown ()

class

name (charset)

best_name ()

can_encode (charset, text, len)

init ()

step (inbuf, inlen)

Details

class GMime.Charset

State used by GMime.Charset.best() and GMime.Charset.best_name().

classmethod best(inbuf, inlen)
Parameters:
  • inbuf (str) – a UTF-8 text buffer

  • inlen (int) – input buffer length

Returns:

the charset name best suited for the input text or None if it is ascii-safe.

Return type:

str or None

Computes the best charset to use to encode this text buffer.

classmethod canon_name(charset)
Parameters:

charset (str) – charset name

Returns:

a canonical charset name for charset.

Return type:

str

Attempts to find a canonical charset name for charset.

Note: Will normally return the same value as GMime.Charset.iconv_name() unless the system iconv does not use the canonical ISO charset names (such as using ISO8859-1 rather than the canonical form ISO-8859-1).

classmethod iconv_name(charset)
Parameters:

charset (str) – charset name

Returns:

an iconv-friendly charset name for charset.

Return type:

str

Attempts to find an iconv-friendly charset name for charset.

classmethod iso_to_windows(isocharset)
Parameters:

isocharset (str) – ISO-8859-# charset

Returns:

equivalent Windows charset.

Return type:

str

Maps the ISO-8859-# charset to the equivalent Windows-CP125# charset.

classmethod language(charset)
Parameters:

charset (str) – charset name

Returns:

a language code that is specific to charset, or None on fail.

Return type:

str or None

Attempts to find a specific language code that is specific to charset. Currently only handles CJK and Russian/Ukranian charset->lang mapping. Everything else will return None.

classmethod locale_name()
Returns:

the user’s locale charset (or iso-8859-1 by default).

Return type:

str

Gets the user’s locale charset (or iso-8859-1 by default).

Note: This function is deprecated. Use GMime.locale_charset() instead.

classmethod map_init()

Initializes character set maps.

Note: GMime.init() calls this routine for you.

classmethod map_shutdown()

Frees internal lookup tables created in GMime.Charset.map_init().

classmethod name(charset)
Parameters:

charset (str) – charset name

Returns:

an iconv-friendly charset name for charset.

Return type:

str

Attempts to find an iconv-friendly charset name for charset.

Note: This function is deprecated. Use GMime.Charset.iconv_name() instead.

best_name()
Returns:

the charset name that best represents the charset mask self or None for us-ascii.

Return type:

str or None

Gets the best charset name based on the charset mask self.

can_encode(charset, text, len)
Parameters:
  • charset (str) – a charset

  • text (str) – utf-8 text to check

  • len (int) – length of text

Returns:

True if it is safe to encode text into charset or False otherwise.

Return type:

bool

Check to see if the UTF-8 text will fit safely within charset.

init()

Initializes a charset mask structure.

step(inbuf, inlen)
Parameters:
  • inbuf (str) – input text buffer (must be in UTF-8)

  • inlen (int) – input buffer length

Steps through the input buffer 1 unicode character (glyph) at a time (ie, not necessarily 1 byte at a time). Bitwise ‘and’ our self->mask with the mask for each glyph. This has the effect of limiting what charsets our self->mask can match.