Skip to content

Commit

Permalink
Default handler now serves directories, files and gophermaps from a p…
Browse files Browse the repository at this point in the history
…ub/ directory
  • Loading branch information
dotcomboom committed Feb 8, 2019
1 parent c76b785 commit a51e7d5
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 117 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Python 3 library for building Gopher clients and servers

**NOTICE:** This is under active, *active* development and basically nothing is finalized. This whole thing can be turned on its head in the matter of two days, so I wouldn't use it for anything quite yet.

Pituophis, at the moment, requires five modules: os, re, sockets, asyncio and ssl; all of which are standard in most Python 3 installations. Pituophis can simply be loaded as a module like this:
Pituophis, at the moment, requires six modules: os, re, sockets, asyncio, ssl, and mimetypes; all of which are standard in most Python 3 installations. Pituophis can simply be loaded as a module like this:
```python
import pituophis
```
Expand Down
99 changes: 53 additions & 46 deletions examples/catenifer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pituophis

splash = """
Expand All @@ -10,62 +11,68 @@

home = 'gopher://gopher.floodgap.com/1/'
typeIcons = {
"i": "ℹ️",
"1": "🚪",
"0": "📝",
"h": "🌎",
"7": "🔍",
"9": "⚙️"
"i": "ℹ️",
"3": "⚠️",
"1": "🚪",
"0": "📝",
"h": "🌎",
"7": "🔍",
"9": "⚙️"
}
noLinkTypes = {"i", "h"}
noLinkTypes = {"i", "h", "3"}
compatibleTypes = {'0', '1', '7'}
menuTypes = {'1', '7'}
lastType = '1'


def bold(txt):
return "\033[1m" + txt + "\033[0;0m"
return "\033[1m" + txt + "\033[0;0m"


requests = {}


def go(url, itype=''):
req = pituophis.parse_url(url)
if req.url().endswith('/'):
req.type = '1'
if itype == '7':
req.type = itype
if req.type in menuTypes:
os.system('clear')
print(splash)
print(bold('URL: ' + req.url()))
if req.type == '7':
if req.query == '':
req.query = input(bold('Search term: '))
if req.type in compatibleTypes:
resp = req.get()
req = pituophis.parse_url(url)
if req.url().endswith('/'):
req.type = '1'
if itype == '7':
req.type = itype
if req.type in menuTypes:
menu = resp.menu()
selectors = 0
for selector in menu:
text = typeIcons['9']
if selector.type in typeIcons:
text = typeIcons[selector.type]
text = text + ' ' + selector.text
if selector.type not in noLinkTypes:
selectors += 1
requests[selectors] = selector.request()
text = text + ' (' + requests[selectors].url() + ') ' + bold('[#' + str(selectors) + ']')
if selector.path.startswith('URL:'):
text = text + ' (' + selector.path.split('URL:')[1] + ')'
print(text)
elif req.type == '0':
print(resp.text())
else:
print("nyi binaries")
os.system('clear')
print(splash)
print(bold('URL: ' + req.url()))
if req.type == '7':
if req.query == '':
req.query = input(bold('Search term: '))
if req.type in compatibleTypes:
resp = req.get()
if req.type in menuTypes:
menu = resp.menu()
selectors = 0
for selector in menu:
text = typeIcons['9']
if selector.type in typeIcons:
text = typeIcons[selector.type]
text = text + ' ' + selector.text
if selector.type not in noLinkTypes:
selectors += 1
requests[selectors] = selector.request()
text = text + ' (' + requests[selectors].url() + ') ' + bold('[#' + str(selectors) + ']')
if selector.path.startswith('URL:'):
text = text + ' (' + selector.path.split('URL:')[1] + ')'
print(text)
elif req.type == '0':
print(resp.text())
else:
print("nyi binaries")


go(home)
while True:
cmd = input(bold('# or URL: '))
try:
cmd = int(cmd)
go(requests[cmd].url(), requests[cmd].type)
except Exception:
go(cmd)
cmd = input(bold('# or URL: '))
try:
cmd = int(cmd)
go(requests[cmd].url(), requests[cmd].type)
except Exception:
go(cmd)
19 changes: 19 additions & 0 deletions examples/tests_server_tls_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from multiprocessing import Process

import pituophis


def reg():
pituophis.serve("127.0.0.1", 50400, pub_dir='pub/', tls=False) # typical Gopher port is 70


def tls():
pituophis.serve("127.0.0.1", 50500, pub_dir='pub/', tls=True,
tls_cert_chain='cacert.pem', tls_private_key='privkey.pem') # typical S/Gopher port is 105


if __name__ == '__main__':
processes = [Process(target=reg),
Process(target=tls)]
for process in processes:
process.start()
Loading

0 comments on commit a51e7d5

Please sign in to comment.