irc3.utils Utils

class irc3.utils.IrcString[source]

Argument wrapper

hostname

return host name:

>>> print(IrcString('foo!user@host').hostname)
host
>>> IrcString('#foo').hostname is None
True
>>> IrcString('irc.freenode.net').hostname is None
True
is_channel

return True if the string is a channel:

>>> IrcString('#channel').is_channel
True
>>> IrcString('&channel').is_channel
True
is_nick

return True if the string is a nickname:

>>> IrcString('foo').is_nick
True
is_server

return True if the string is a server:

>>> IrcString('irc.freenode.net').is_server
True
lnick

return nick name in lowercase:

>>> print(IrcString('Foo').lnick)
foo
nick

return nick name:

>>> print(IrcString('foo').nick)
foo
>>> print(IrcString('foo!user@host').nick)
foo
>>> IrcString('#foo').nick is None
True
>>> IrcString('irc.freenode.net').nick is None
True
tagdict

return a dict converted from this string interpreted as a tag-string

>>> from pprint import pprint
>>> dict_ = IrcString('aaa=bbb;ccc;example.com/ddd=eee').tagdict
>>> pprint({str(k): str(v) for k, v in dict_.items()})
{'aaa': 'bbb', 'ccc': 'None', 'example.com/ddd': 'eee'}
username

return user name:

>>> print(IrcString('foo!user@host').username)
user
>>> IrcString('#foo').username is None
True
>>> IrcString('irc.freenode.net').username is None
True
irc3.utils.as_list(value)[source]

clever string spliting:

>>> print(as_list('value'))
['value']
>>> print(as_list('v1 v2'))
['v1', 'v2']
>>> print(as_list(None))
[]
>>> print(as_list(['v1']))
['v1']
irc3.utils.as_channel(value)[source]

Always return a channel name:

>>> print(as_channel('chan'))
#chan
>>> print(as_channel('#chan'))
#chan
>>> print(as_channel('&chan'))
&chan
irc3.utils.split_message(message, max_length)[source]

Split long messages

class irc3.utils.Logger(name, level=0)[source]

Replace the default logger to add a set_irc_targets() method

set_irc_targets(bot, *targets)[source]

Add a irc Handler using bot and log to targets (can be nicks or channels:

>>> log = logging.getLogger('irc.mymodule')
>>> log.set_irc_targets(bot, '#chan', 'admin')
class irc3.utils.Config[source]

Simple dict wrapper:

>>> c = Config(dict(a=True))
>>> c.a
True
irc3.utils.parse_config(main_section, *filenames)[source]

parse config files

irc3.utils.extract_config(config, prefix)[source]

return all keys with the same prefix without the prefix

irc3.utils.maybedotted(name)[source]

Resolve dotted names:

>>> maybedotted('irc3.config')
<module 'irc3.config' from '...'>
>>> maybedotted('irc3.utils.IrcString')
<class 'irc3.utils.IrcString'>