Building Gopher services with Python

I've been working on a Gopher-based project in Python, because reasons. It was a refreshingly simple change from my usual web development work. Three evenings of work gave me a gopher server that presents all the content from a much more complex website.

Pituophis, a Python module for writing both Gopher servers and clients. Pituophis's default "handler" function acts as a basic Gopher server, publishing items in a specific directory to Gopherspace and uses an optional user-defined alternate handler function that responds when a missing file is requested. You can also replace the default handler and build your own Gopher application from the ground up.

One limitation of Pituophis compared to a web framework is the lack of a routing engine. That's easy enough to work around with a list of regular expressions and "controller" functions:

if request.path in ('', '/'):
    return homePage(request)

paths = [
    (re.compile('/image/([\w-]+)\.(gif|jpg|png)$', re.IGNORECASE), sendImage),
    (re.compile('/([a-z]{2})$'), statePage),
    (re.compile('/([a-z]{2})/([\w-]+)$'), cityPage),
]

for pat, func in paths:
    m = pat.match(request.path)
    if m:
        return func(request, m)

About Me

Developer at Brown University Library specializing in instructional design and technology, Python-based data science, and XML-driven web development.