Open lefalaf opened 4 years ago
Hi!
PYGMain
is actually the class that you need to implement inside of the .pyg file. The methods of the class are hooks into the application that pygopherd will invoke. There's a complicated example of how this works in the pygfarm directory.
Here's a simple hello world example:
from pygopherd.handlers.pyg import PYGBase
from pygopherd.gopherentry import GopherEntry
class PYGMain(PYGBase):
def canhandlerequest(self):
return True
def isdir(self):
return False
def getentry(self):
entry = GopherEntry(self.selector, self.config)
entry.type = '0'
entry.mimetype = 'text/plain'
entry.name = 'My custom .pyg handler!'
return entry
def write(self, wfile):
wfile.write("hello world!".encode())
If you're looking for something that just works like a CGI script, you can use the scriptexec.ExecHandler
instead. That one will set some environment variables for you and you can just write directly to stdout from inside of the script.
Thank you @michael-lazar !
Pygfarm example is indeed complicated, but I do understand better now what pyg files are and how they work.
Regarding Exechandler, I assume files must be executables python files ?
no problem!
Regarding Exechandler, I assume files must be executables python files ?
They can be any kind of file (python, bash, perl, etc.) as long as the file is set to executable and has the shebang at the top. The catch is that the Exechandler
can only generate text/plain files as the output, so it can't be used to generate proper gopher directories.
Hi,
I'm trying to use PYGhandler and generate a very simple print() just to see what happen so far my file test.pyg looks like this
But I get this error
Am I missing something in my file ?
Thanks !