Skip to main content

Generic classes I find myself rewriting over and over again.

Project description

A general library of classes I find myself rewriting time and time again.

Some use cases

  1. Hosting a simple socket server (INET & UNIX).
from cmyui.web import *

serv: TCPServer
conn: Connection

# for inet sockets, addr is a tuple of (host: str, port: int).
# for unix sockets, addr is simply a string of the file location.
serv_addr = ('127.0.0.1', 5001) # or '/tmp/myserv.sock'

with TCPServer(serv_addr) as serv:
    for conn in serv.listen(max_conns = 5):
        ''' Use your conn object here! '''

        print(
            # HTTP command as a string ('GET', 'POST', etc.).
            conn.req.cmd,

            # HTTP version as a float.
            conn.req.httpver,

            # HTTP headers as {k: v} pairs.
            conn.req.headers,

            # HTTP body as bytes.
            conn.req.body,

            # Args parsed from the request as {k: v} pairs.
            # GET: parse args from URI
            # POST (w/ form data): parse args from multipart
            conn.req.args,

            # Files included in the request as {k: v} pairs
            conn.req.files
        )

        conn.resp.add_header('Content-Type: image/png')
        conn.resp.send(b'abc', 200) # Attaches headers &
                                    # Content-Length before sending.

More documentation coming soon..

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmyui-1.2.0.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

cmyui-1.2.0-py3-none-any.whl (9.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page