News for hackers. Stuff that matters.
Re:Python finally offloads some batteries by tyingq on Thursday March 17, 2022 @09:39PM (#30717818)
There seems to be overlap with wsgiref, and that ships with Python. There's a CGIHandler class that can use stdin/stdout.

Most of the examples show spinning up and listening to a port, but you can google around to find examples that work with just stdin/stdout.

Re:Python finally offloads some batteries by tyingq on Thursday March 17, 2022 @10:18PM (#30718089)
Since there's no dead simple examples:

  #!/usr/bin/env python
  from wsgiref.handlers import CGIHandler

  def app(environ, start_response):
      start_response('200 OK', [('Content-Type', 'text/html')])
      return [
         b"<html><head><title>foo</title></head><body>bar</body></html>\n"
      ]

  if __name__ == '__main__':
      CGIHandler().run(app)