Utility#

sopel.irc.utils contains low-level tools for IRC protocol handling.

Warning

This is all internal code, not intended for direct use by plugins. It is subject to change between versions, even patch releases, without any advance notice.

class sopel.irc.utils.MyInfo#

Store client, servername, and version from RPL_MYINFO events.

client: str#

Alias for field number 0

servername: str#

Alias for field number 1

version: str#

Alias for field number 2

sopel.irc.utils.safe(string: str) str#

Remove disallowed bytes from a string, and ensure Unicode.

Parameters:

string – input text to process

Returns:

the string as Unicode without characters prohibited in IRC messages

Raises:

TypeError – when string is None

This function removes newlines and null bytes from a string. It will always return a Unicode str, even if given non-Unicode input, but doesn’t strip or alter the string in any other way:

>>> safe('some \x00text\r\n')
'some text'

This is useful to ensure a string can be used in a IRC message. Parameters can never contain NUL, CR, or LF octets, per RFC 2812 § section-2.3.1.

Changed in version 7.1: This function now raises a TypeError instead of an unpredictable behaviour when given None.

Changed in version 8.0.1: Also remove NUL (\x00) in addition to CR/LF.