import pituophis def alt(request): if request.path == '/test': return [pituophis.Item(text='test!')] pituophis.serve("127.0.0.1", 70, pub_dir='pub/', alt_handler=alt, tls=False) # typical Gopher port is 70
def tls(): pituophis.serve("127.0.0.1", 50500, pub_dir='pub/', alt_handler=alt, tls=True, tls_cert_chain='cacert.pem', tls_private_key='privkey.pem') # typical S/Gopher port is 105
import pituophis import dotenv from classes.User import User, userCache from routes.unconnected import UnconnectedRoutes from routes.connected import ConnectedRoutes #REQUEST HANDLER def requestHandler(request: pituophis.Request): # IF CLIENT IS CONNECTED if "/connected/" in request.path: print(request.path) user : User = userCache.pop(request.path.split("/")[2]) userCache[user.id] = user return ConnectedRoutes(request, userCache, user.id) # IF CLIENT NOT CONNECTED else: return UnconnectedRoutes(request, userCache) dotenv.get_key(".","HOST") pituophis.serve('localhost', 70, pub_dir="pub/", alt_handler=requestHandler)
yes = False if len(types) == 0: yes = True else: if req.type in types: yes = True if yes: try: menu.append(p.Item(text='')) menu.append(p.Item(itype=req.type, text=items[item]['titles'][0], path=req.path, host=req.host, port=req.port)) menu.append(p.Item(text='URL: ' + req.url())) if len(items[items]['titles']) > 1: if settings['alternate_titles']: menu.append(item(text='Alternate titles:')) for title in items[item]['titles'][1:]: menu.append(item(text=' ' + title)) if settings['referrers']: menu.append(p.Item(text='Referred by:')) for referrer in items[item]['referrers']: menu.append(p.Item(text=' ' + referrer)) except: pass return menu else: e = copy.copy(p.errors['404']) e.text = e.text.format(request.path) return e p.serve(settings['host'], settings['port'], pub_dir=settings['pub_dir'], alt_handler=alt) # typical Gopher port is 70
import pituophis # This example directly reroutes the client's request to another server and port. # It then fetches the request, then sends the received binary data. def handle(request): request.host = 'gopher.floodgap.com' request.port = 70 resp = request.get() return resp.binary # serve with custom handler pituophis.serve("127.0.0.1", 70, handler=handle)