Giter VIP home page Giter VIP logo

pituophis's Introduction

Pituophis

Documentation Status PyPI version PyPI license

Python 3 library for building Gopher clients and servers

Installation

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.

Features

  • Make and send Gopher requests with the Request class
  • URL parsing with pituophis.parse_url()
  • Parse and iterate through Gopher menus with Response.menu()
  • Host Gopher servers on Python 3.7+, 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

Server

Pituophis can act as a powerful Gopher server, with full Bucktooth-style gophermap and globbing support. Scripting is also supported through alt handlers (used in the event of a 404) or fully custom handlers (replaces Pituophis' handler entirely).

The simplest method of getting a server up and running is with the pituophis.serve() function. See the examples and docs for more information. If you'd like to see a server built with Pituophis that can search an index, try Gophew.

server_def

Quick Start

A simple quick-start snippet is the following:

import pituophis
pituophis.serve('127.0.0.1', 7070, pub_dir='pub/')  # typical Gopher port is 70

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.Item(text='test!')]

You can return a list of Item 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)

Client

Pituophis can also grab files and parse menus from Gopher servers. Simple fetching is done with Request().get() and get(), and Request().stream() can be used for lower-level access as a BufferedReader. The get functions return a Response type. See the docs for more information.

TreeGopher

An interactive demo of Pituophis' client features is provided in the form of TreeGopher, a graphical Gopher client in <250 lines of code. It uses Pituophis, PySimpleGUI, and Pyperclip. It can browse Gopher in a hierarchical structure (similarly to WSGopher32, Cyberdog, and Little Gopher Client), cache menus, read text files, download and save binary files (writing in chunks using Request().stream(), and running on another thread), recognize URL: links and use search services.

Examples

Getting menus and files as plain text:

pituophis.get('gopher.floodgap.com').text()
pituophis.get('gopher://gopher.floodgap.com/1/').text()
pituophis.get('gopher://gopher.floodgap.com:70/0/gopher/proxy').text()

Getting a menu, parsed:

menu = pituophis.get('gopher.floodgap.com').menu()
for item in menu:
    print(item.type)
    print(item.text)
    print(item.path)
    print(item.host)
    print(item.port)

Using search services:

pituophis.get('gopher://gopher.floodgap.com:70/7/v2/vs%09toast').text()

Downloading a binary:

pituophis.get('gopher://gopher.floodgap.com:70/9/gopher/clients/win/hgopher2_3.zip').binary

Requests can also be created from a URL:

import pituophis
req = pituophis.parse_url('gopher://gopher.floodgap.com/7/v2/vs%09food')
print('Getting', req.url())
rsp = req.get()
print(rsp.text())

pituophis's People

Contributors

dotcomboom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dafulyu

pituophis's Issues

CLI commands

  • Development/test server (like python3 -m http.server)

  • Server script quickstart

  • Quickly grab gopher url contents (curl-like functionality)

Queries from selector path

Occasionally, I've seen selectors like this one used in the Bucktooth section of the Floodgap server.

1Interactive user's guide to Bucktooth	/buck/dbrowse?faquse	gopher.floodgap.com	70

These have a url-style question mark after the path in the path field.
When turning selectors into requests, Pituophis should separate the path from the query, so these types of requests work correctly.

Handle URLs with encoded spaces and some weird thingys

10:51 i'm used to like
10:51 percent-encoding spaces in urls
10:51 but if i do that in a gophermap, it returns a 404
10:51 so i have to literally put a space in the url
10:51 because it makes the url %2520
10:52 because it,,,percent encodes the percent sign

Gonna need to experiment with this in different clients.

Windows[?] relative path issues

image

Items in a parsed gophermap that use relative paths (such as somnolians/ as opposed to an absolute path like /somnolians/) seem to break on Windows. Those ending with a slash like a folder crash the script, just relative links to files in the same directory do not crash but do extremely silly things.

image

Read the Docs exploded

Current API reference at RTD is broken. Weirdly enough, a manual build works just fine for me.

Work towards feature parity with Gophernicus' gophermap format

gopher://rawtext.club/0/docs/gophernicus/README.Gophermap

Namely..

# Hide a few files from the menu listing generated by *
-hiddenfile.txt
-hiddendir

# Change filetypes for this directory
:png=g
:foo=b
Additional type characters supported by Gophernicus:
   #          comment - rest of the line is ignored
   !title     menu title (use on the first line)
   -file      hide file from listings
   :ext=type  change filetype (for this directory only)
   ~          include a list of users with valid ~/public_gopher
   %          include a list of available virtual hosts
   =mapfile   include or execute other gophermap
   *          stop processing gophermap, include file listing
   .          stop processing gophermap (default)

I imagine ! functions like a Gophertag.
Of type characters that will most likely be left out: ~, %, .. (* is a glob, those are already implemented). (Executable Gophermaps will most likely be left out for security reasons; an alt handler could be used instead.)

Handle more.. obscure text encodings

Older servers (like this instance of GopherSurfer 1.1b3r2 I got running on my Power Mac G4 for testing) use text encodings that aren't compatible with UTF-8, causing an error. In my case, macroman, which Python can decode fine like resp.binary.decode('macroman') where resp is a Response object.

(As for the other way around, rest assured that clients like TurboGopher, Cyberdog and GopherVR work fine with Pituophis-based servers on OS 9.)

Gopher globbing & gophertags

This will (hopefully) complete compatibility with maps that work with Bucktooth.

Info: gopher://gopher.floodgap.com:70/1/buck/dbrowse?faquse 1a

Information selectors don't have fields filled in

What it should be:
iApples and oranges(t)(t)error.host(t)0

What it is:
iApples and oranges

Result is that in clients that don't go quirks mode on it information selectors in served gophermaps don't work.

Sorting with Gopher globbing

Right now, when you have a glob (i.e. a line with just ?*\t, it's in a supposedly random order given by whatever glob thinks is a good idea. Instead, Pituophis should sort this listing alphabetically like how Bucktooth does it, and maybe provide some sort of options for sorting it in a different way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.