Case-insensitive types¶
IStr¶
- class pyrcb2.IStr¶
Bases:
strA case-insensitive string class based on IRC case rules. (
{}|^are lowercase equivalents of[]\~.)Equality comparisons are case-insensitive, but the original string is preserved.
strcan be used to obtain a case-sensitive version of the string. For example:>>> IStr("STRing^") == "string^" True >>> IStr("STRing^") == "STRING~" True >>> str(IStr("STRing^")) == "STRING~" False
Throughout pyrcb2, all parameters and attributes that represent nicknames or channels are of type
IStr, so they can be tested for equality without worrying about case-sensitivity.Arguments are passed to and handled by
str. This class behaves just likestr, except for equality comparisons and methods which rely on equality comparisons, such asstr.index().When used as keys in dictionaries, IStr objects will act like the lowercase version of the string they represent. If you want a case-insensitive dictionary, use
IDict.
IDict¶
- class pyrcb2.IDict¶
Bases:
collections.OrderedDictA case-insensitive dictionary class based on IRC case rules.
Key equality is case-insensitive. Keys are converted to
IStrupon assignment (as long as they are instances ofstr).This class is a subclass of
OrderedDict, so keys are kept in the order they were added in.
IDefaultDict¶
ISet¶
- class pyrcb2.ISet(iterable=None)¶
Bases:
setA case-insensitive
setclass based on IRC case rules.Item equality is case-insensitive. Items are converted to
IStrduring all operations. For example:>>> x = ISet(["TEST"]) >>> x.add("another_test") >>> x ISet({IStr('TEST'), IStr('another_test')}) >>> x - {"test"} ISet({IStr('another_test')})
User¶
- class pyrcb2.User(*args, prefixes=None, **kwargs)¶
Bases:
IStrA subclass of
IStrthat represents a nickname and also stores the associated user’s prefixes in a certain channel. This class behaves just likeIStr; it simply has extra attributes.Nicknames in
IRCBot.usersare of this type, so you can easily check if a user has a certain prefix. SeeIRCBot.usersfor more information.It shouldn’t be necessary to create objects of this type.
- has_prefix(prefix)¶
Checks if the user has a certain prefix.
- Parameters
prefix (str) – The prefix to check for (should be one character).
- Return type
bool
- prefixes¶
The user’s prefixes.
- Type
frozensetofstr
Sender¶
- class pyrcb2.Sender(*args, username=None, hostname=None, **kwargs)¶
Bases:
IStrA subclass of
IStrthat represents a nickname and also stores the associated user’s username and hostname. This class behaves just likeIStr; it simply has extra attributes.In events, nicknames are sometimes of this type (when the command originated from the associated user). See individual
Eventdecorators for more information.It shouldn’t be necessary to create objects of this type.
- username¶
The user’s username.
- Type
str
- hostname¶
The user’s hostname.
- Type
str