dotcomboom | Pituophis API

Back

Functions

def get(

host, port=70, path='/', query='', tls=False, tls_verify=True)

Client. Quickly creates and sends a Request. Returns a Response object.

def handle(

request)

Server. Default handler function for Gopher requests while hosting a server. Serves files and directories from the pub/ directory by default, but the path can be changed in serve's pub_dir argument or changing the Request's pub_dir directory.

def parse_gophermap(

source, def_host='127.0.0.1', def_port='70', gophermap_dir='/', pub_dir='pub/', tls=False)

Server. Converts a Bucktooth-style Gophermap (as a String or List) into a Gopher menu as a List of Selectors to send.

def parse_menu(

source)

Client. Parses a String as a Gopher menu. Returns a List of Selectors.

def parse_url(

url)

Client. Parses a Gopher URL and returns an equivalent Request.

def serve(

host='127.0.0.1', port=70, advertised_port=None, handler=<function handle at 0x101d231e0>, pub_dir='pub/', alt_handler=False, send_period=False, tls=False, tls_cert_chain='cacert.pem', tls_private_key='privkey.pem', debug=True)

Server. Listens for Gopher requests. Allows for using a custom handler that will return a Bytes, String, or List object (which can contain either Strings or Selectors) to send to the client, or the default handler which can serve a directory. Along with the default handler, you can set an alternate handler to use if a 404 error is generated for dynamic applications.

Classes

class Request

Client/Server. Represents a request to be sent to a Gopher server, or received from a client.

Ancestors (in MRO)

Static methods

def __init__(

self, host='127.0.0.1', port=70, advertised_port=None, path='/', query='', itype='9', tls=False, tls_verify=True, client='', pub_dir='pub/', alt_handler=False)

Initializes a new Request object.

def get(

self)

Client. Sends the Request and returns a Response object.

def url(

self)

Returns a URL equivalent to the Request's properties.

Instance variables

var advertised_port

Server. Used by the default handler. Set this if the server itself is being hosted on another port than the advertised port (like port 70), with a firewall or some other software rerouting that port to the server's real port.

var alt_handler

var client

Server. The IP address of the connected client.

var host

Client/Server. The hostname of the server.

var path

Client/Server. Path on the target server to request, or being requested.

var port

Client/Server. The port of the server. For regular Gopher servers, this is most commonly 70, and for S/Gopher servers it is typically 105.

var pub_dir

Server. The default handler uses this as which directory to serve. Default is 'pub/'.

var query

Client/Server. Search query for the server to process. Omitted when blank.

var tls

Client/Server. Whether the request is to be, or was sent to an S/Gopher server over TLS.

var tls_verify

Client. Whether to verify the certificate sent from the server, rejecting self-signed and invalid certificates.

var type

Client. Item type of the request. Purely for client-side usage, not used when sending or receiving requests.

class Response

Client. Returned by Request.get() and get(). Represents a received binary object from a Gopher server.

Ancestors (in MRO)

Static methods

def __init__(

self, stream)

Reads a BufferedReader to the object's binary property and initializes a new Response object.

def menu(

self)

Decodes the binary as text and parses it as a Gopher menu. Returns a List of Gopher menu items parsed as the Selector type.

def text(

self)

Returns the binary decoded as a UTF-8 String.

Instance variables

var binary

The data received from the server as a Bytes binary object.

class Selector

Server/Client. Represents a selector in a parsed Gopher menu.

Ancestors (in MRO)

Static methods

def __init__(

self, itype='i', text='', path='/', host='error.host', port=0, tls=False)

Initializes a new Selector object.

def request(

self)

Returns a Request equivalent to where the selector leads.

def source(

self)

Returns a representation of what the selector looks like in a Gopher menu.

Instance variables

var host

The hostname of the target server.

var path

Where the item links to on the target server.

var port

The port of the target server. For regular Gopher servers, this is most commonly 70, and for S/Gopher servers it is typically 105.

var text

The name, or text that is displayed when the item is in a menu.

var tls

True if the selector leads to an S/Gopher server with TLS enabled.

var type

The type of item.