turn into lib

master v0.1.3
Simon de Vlieger 1 month ago
parent 0b3de0e410
commit 2b79a28d9f
Signed by: supakeen
GPG Key ID: D6C290547A1167B2

@ -5,44 +5,28 @@
![rtd badge](https://readthedocs.org/projects/gb/badge/?version=latest) ![license badge](https://gb.readthedocs.io/en/latest/_static/license.svg) ![black badge](https://img.shields.io/badge/code%20style-black-000000.svg)
## About
`gb` or gopherball is a gopher server written in Python with the main goals of
`gb` or gopherball is a gopher library written in Python with the main goals of
ease of use and integration. The name gopherball is inspired by a recurring
theme in the Calvin & Hobbes comicbooks and a tongue in cheek reference of an
alternative to the World Wide Web as we know it today.
## Examples
Quick examples to get you running.
There are several other projects that are built on top of `gb` to get you running:
`gb --mode=implicit .` will start a gopher server on `127.0.0.1` port `7070` serving
a recursive index of files starting from the current directory.
### Server
Check out the [gbs](https://github.com/supakeen/gbs) project.
`gb --mode=implicit --magic .` will start `gb` in magic-mode on `127.0.0.1` port
`7070`. Magic mode will make `gb` guess at filetypes.
### Client
Check out the [gbc](https://github.com/supakeen/gbc) project.
`gb --mode=implicit --host="127.1.1.1" --port 1025 .` will start `gb` in implicit
mode on the chosen ip and port. Note that using ports under 1024 requires
superuser permissions!
### Proxy
Check out the [gbx](https://github.com/supakeen/gbx) project.
## Technology
`gb` is written with the help of Python 3.9 and higher and the Tornado
framework for its networking.
## Modes
`gb` has one main mode of operation that is commonly used. More modes are
planned for the future.
### implicit
Implicit mode serves a directory recursively. Indexes are automatically
generated and text files are served to the client. Data files are also
supported.
## Magic
`gb` will serve all non-directories as type 9 files, these are non-readable
files and most clients will prompt for download. Turning on magic with
`--magic` will let `gb` try to determine the correct filetypes.
## Contributing
The source code for `gb` lives on my Gitea where you can also submit issues and
pull requests. It mostly needs help by people with the ability to test in
The source code for `gb` lives on my GitHub where you can also submit issues
and pull requests. It mostly needs help by people with the ability to test in
various clients and libraries that might still support the gopher protocol.

@ -1,12 +1,12 @@
[tool.poetry]
name = "gb"
version = "0.1.2"
description = "A Python gopher server."
version = "0.1.3"
description = "A Python gopher library."
authors = ["Simon de Vlieger <cmdr@supakeen.com>"]
license = "MIT"
readme = "README.md"
keywords = ["gopher", "server"]
repository = "https://src.tty.cat/supakeen/gb"
keywords = ["gopher", "library"]
repository = "https://github.com/supakeen/gb"
classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
@ -60,8 +60,6 @@ exclude = '''
| dist
)/
'''
[tool.poetry.scripts]
gb = 'gb.__main__:main'
[tool.mypy]
python_version = "3.7"

@ -1,4 +0,0 @@
from gb.command import main
raise SystemExit(main(auto_envvar_prefix="GB"))

@ -1,104 +0,0 @@
import sys
import ipaddress
import logging
import click
import tornado.iostream
import gb.server
log = logging.getLogger(__name__)
modes = {
"implicit": gb.server.ImplicitGopherServer,
}
def bail(message: str) -> None:
"""Write a message to stderr and exit unsuccesfully."""
print(message, file=sys.stderr)
raise SystemExit(1)
@click.command()
@click.option(
"--mode",
"-m",
required=True,
type=click.Choice([str(mode) for mode in modes.keys()]),
help="Mode to run as.",
)
@click.option(
"--host",
"-h",
default="127.0.0.1",
show_default=True,
help="IP address to listen on.",
)
@click.option(
"--port", "-p", default=7070, show_default=True, help="Port to listen on."
)
@click.option(
"--verbose",
"-v",
count=True,
help="Verbosity, passing more heightens the verbosity.",
)
@click.option(
"--magic",
default=False,
help="Enable magic mode to try and guess filetypes by extension and content.",
show_default=True,
is_flag=True,
)
@click.option(
"--utf8",
"-u",
default=False,
help="Use UTF-8 as the default encoding instead of the standard ISO-8859-1",
is_flag=True,
)
@click.argument(
"path", required=True, type=click.Path(exists=True), envvar="GB_PATH"
)
def main(
mode: str,
host: str,
port: int,
path: click.Path,
verbose: int,
magic: bool,
utf8: bool,
) -> int:
"""`gb` or gopherball is a modern server for the Gopher protocol."""
if port < 0 or port > 65535:
bail("Invalid port supplied.")
try:
host = str(ipaddress.ip_address(host))
except ValueError:
bail("Unparseable IP supplied.")
if mode not in modes:
bail("Invalid mode supplied.")
if utf8:
encoding = "utf8"
else:
encoding = "iso-8859-1"
logging.basicConfig(level=logging.INFO)
server = modes[mode](str(path), "localhost", 7070, magic, encoding)
server.listen(port)
server.start(0)
tornado.ioloop.IOLoop.current().start()
return 0
if __name__ == "__main__":
raise SystemExit(main(auto_envvar_prefix="GB"))
Loading…
Cancel
Save