Browse Source

Add a todo + some commented debug lines + foo_pep333.py enhancement

Yann Weber 5 years ago
parent
commit
7004f544e4
4 changed files with 24 additions and 2 deletions
  1. 15
    2
      foo_pep333.py
  2. 2
    0
      include/pyworker.h
  3. 1
    0
      src/python_ioin.c
  4. 6
    0
      src/pyutils.c

+ 15
- 2
foo_pep333.py View File

1
 import sys
1
 import sys
2
 import os
2
 import os
3
 import time
3
 import time
4
+from pprint import pformat
4
 
5
 
5
 def entrypoint(env, start_response):
6
 def entrypoint(env, start_response):
6
 	write_body = start_response("200 OK", [('Content-type', 'text/plain')])
7
 	write_body = start_response("200 OK", [('Content-type', 'text/plain')])
7
-	write_body('Hello world !')
8
-	return ['Hello world !']
8
+
9
+	if not "wsgi.input" in env:
10
+		raise ValueError("Given environ does not contain any 'wsgi.input' key !")
11
+	data_in = env["wsgi.input"]
12
+	#for l in data_in:
13
+	#	write_body("POST data line : %s" % repr(l))
14
+	#data = data_in.readlines()
15
+	while True:
16
+		data = data_in.read(98)
17
+		write_body("POST data : %s\n====\n" % repr(data))
18
+		if not data:
19
+			break
20
+	write_body("Environ data :\n'%s'\n====\n" % pformat(env))
21
+	return ['Hello world !\n']

+ 2
- 0
include/pyworker.h View File

152
 
152
 
153
 /**@brief empty pipes and log content for pep333 workers
153
 /**@brief empty pipes and log content for pep333 workers
154
  * @todo enhance logging : 1 lines per logline + line counter ?
154
  * @todo enhance logging : 1 lines per logline + line counter ?
155
+ * @todo sys.stdout & sys.stderr can have an implementation like
156
+ * libpyfcgi.IoIn to avoir useless buffering
155
  * @param int pipes for stdout
157
  * @param int pipes for stdout
156
  * @param int pipes for stderr
158
  * @param int pipes for stderr
157
  * @param PyObject[2] python flush methods
159
  * @param PyObject[2] python flush methods

+ 1
- 0
src/python_ioin.c View File

363
 			break;
363
 			break;
364
 		}
364
 		}
365
 	}
365
 	}
366
+//dprintf(2, "read : %s\n", PyBytes_AsString(res));
366
 	Py_DECREF(res);
367
 	Py_DECREF(res);
367
 	return res;
368
 	return res;
368
 }
369
 }

+ 6
- 0
src/pyutils.c View File

385
 
385
 
386
 	PyDict_Update(pyenv, PyFCGI_conf.context.wsgi_dict);
386
 	PyDict_Update(pyenv, PyFCGI_conf.context.wsgi_dict);
387
 	PyObject_SetAttrString(py_osmod, "environ", pyenv);
387
 	PyObject_SetAttrString(py_osmod, "environ", pyenv);
388
+/*//Debug print env on stderr
389
+PyObject* repr = PyObject_ASCII(pyenv);
390
+Py_INCREF(repr);
391
+dprintf(2, "%s\n", PyUnicode_AsUTF8(repr));
392
+Py_DECREF(repr);
393
+*/
388
 	return pyenv;
394
 	return pyenv;
389
 }
395
 }
390
 
396
 

Loading…
Cancel
Save