Gopher library for Python 31.0 | Download Source | Examples | API | Repository | BSD 2-Clause License
Pituophis is a Gopher library/module for Python 3 that has functions for client and server.
- Make and send Gopher requests to both S/Gopher (TLS) and regular Gopher servers with the Request class
- URL parsing with pituophis.parse_url()
- Parse and iterate through Gopher menus with Response.menu()
- Host both S/Gopher (TLS) and regular Gopher servers, accepting requests asynchronously (using the same Request class)
- Serve directories, files, and gophermaps out of the box from a publish directory ('pub/' by default) with the default handler
- Use either a custom handler altogether or a handler to use when the default handler encounters a 404 for dynamic functionality
How to Install
At a prompt, run
pip3 install pituophis or
pip install pituophis depending on your setup. You'll be able to import the package with `import pituophis`.
Server Quick Start
If you want to host a Pituophis-based Gopher server, put this code in a file:
import pituophis pituophis.serve("127.0.0.1", 7070, pub_dir='pub/', tls=False) # typical Gopher port is 70
127.0.0.1 is the hostname as advertised to the client, and
7070 is the port.
pub/ is the publish directory relative to the script.
Here's a basic alt handler, if you're familiar with Python scripting and would like to add more interactivity to your server:
def alt(request): if request.path == '/test': return [pituophis.Selector(text='test!')]
You can return a list of Selector objects, bytes, or text. To use your alt handler, add the argument
alt_handler=alt to your serve() like this:
pituophis.serve("127.0.0.1", 7070, pub_dir='pub/', alt_handler=alt, tls=False)
Writing a Gophermap, a simplified form of a Gopher menu is pretty easy: just stick a file called
gophermap in a folder within your publish directory and use the straight-forward menu syntax. This little webapp can help you get to grips with it (note that this uses jQuery). Copy the Gophermap code into your file.
Made with Pituophis
These are my personal projects that use Pituophis:
- Gopherlens - HTTP to Gopher proxy
- Gophew - PoC Gopher crawler & search engine (might work pretty well for single servers, Veronica-2 has it down though)
If you use Pituophis in your project, contact me and I'd be happy to put it down here.