Skip to main content

irctokens

Build Status

rationale

there's far too many IRC client implementations out in the world that do not tokenise data correctly and thus fall victim to things like colons either being where you don't expect them or not being where you expect them.

usage

installation

$ pip3 install irctokens

tokenisation

>>> import irctokens
>>> line = irctokens.tokenise(
...     "@id=123 :jess!~jess@hostname PRIVMSG #chat :hello there!")
>>>
>>> line.tags
{'id': '123'}
>>> line.source
'jess!~jess@hostname'
>>> line.hostmask
Hostmask(nickname='jess', username='~jess', hostname='hostname')
>>> line.command
'PRIVMSG'
>>> line.params
['#chat', 'hello there!']

formatting

>>> irctokens.build("USER", ["user", "0", "*", "real name"]).format()
'USER user 0 * :real name'

stateful

below is an example of a fully socket-wise safe IRC client connection that will connect and join a channel. both protocol sending and receiving are handled by irctokens.

import irctokens, socket

NICK = "nickname"
CHAN = "#channel"

d = irctokens.StatefulDecoder()
e = irctokens.StatefulEncoder()
s = socket.socket()
s.connect(("127.0.0.1", 6667))

def _send(line):
    print(f"> {line.format()}")
    e.push(line)
    while e.pending():
        e.pop(s.send(e.pending()))

_send(irctokens.build("USER", ["username", "0", "*", "real name"]))
_send(irctokens.build("NICK", [NICK]))

while True:
    lines = d.push(s.recv(1024))
    if lines == None:
        print("! disconnected")
        break

    for line in lines:
        print(f"< {line.format()}")
        if line.command == "PING":
            to_send = irctokens.build("PONG", [line.params[0]])
            _send(to_send)

        elif line.command == "001":
            to_send = irctokens.build("JOIN", [CHAN])
            _send(to_send)

contact

Come say hi at #irctokens on irc.libera.chat

Metadata

Release files for irctokens 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for irctokens 2.0.2
File Size Uploaded Provenance
irctokens-2.0.2.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for irctokens 2.0.2
File Interpreter ABI Platform
irctokens-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / irctokens-2.0.2.tar.gz

Download URL irctokens-2.0.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b08bf7ca10b185914bb84d33d780a31fdb0fd0cea438ee8918850d9520efbd47
BLAKE2b-256 checksum
How to use checksums
0a90edd160b5ccd094dc9c9a41cdd2d48adc985c65d9b03d385fcbe37a037589
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.2

Release files / irctokens-2.0.2-py3-none-any.whl

Download URL irctokens-2.0.2-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67d423a1bef581fb6c059de080f51271081de3e65e577b846db7d2340dcd7e24
BLAKE2b-256 checksum
How to use checksums
b88469f068ac3cf70bc5f9b3add20ba997b8f02733bdef54cfab71b879b70c6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.2

Security for irctokens 2.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page