> Thanks you for the pointer. I have begun modifying the code for class
> _spoolraw so that it converts all the 'arguments' dictionary keys and
> values to bytes, and the vars dictionary keys and values in the
> manage_spool_request back to strings. If I add some logic to only
> perform this conversion if running under Python 3, do you think I can
> contribute a diff to uwsgidecorators.py so that it is included in the main
> branch?
Here is what changed in the 'uwsgidecorators.py' file to make spooling work for
me on Python 3:
diff --git a/uwsgidecorators.py b/uwsgidecorators.py
index ec24edc..f982e01 100644
--- a/uwsgidecorators.py
+++ b/uwsgidecorators.py
@@ -17,6 +17,8 @@ spooler_functions = {}
mule_functions = {}
postfork_chain = []
+py = sys.version_info
+py3k = py >= (3, 0, 0)
def get_free_signal():
for signum in range(0, 256):
@@ -27,6 +29,16 @@ def get_free_signal():
def manage_spool_request(vars):
+ if py3k:
+ string_vars = {}
+ for key in vars:
+ value = vars[key]
+ if not isinstance(value, str):
+ value = value.decode()
+ if not isinstance(key, str):
+ key = key.decode()
+ string_vars[key] = value
+ vars = string_vars
f = spooler_functions[vars['ud_spool_func']]
if 'args' in vars:
args = pickle.loads(vars.pop('args'))
@@ -80,6 +92,16 @@ class _spoolraw(object):
spooler_args.update({key: kwargs.pop(key)})
arguments.update(spooler_args)
arguments.update({'args': pickle.dumps(args), 'kwargs':
pickle.dumps(kwargs)})
+ if py3k:
+ bytes_arguments = {}
+ for key in arguments:
+ value = arguments[key]
+ if not isinstance(value, bytes):
+ value = str(value).encode()
+ if not isinstance(key, bytes):
+ key = str(key).encode()
+ bytes_arguments[key] = value
+ arguments = bytes_arguments
return uwsgi.spool(arguments)
# For backward compatibility (uWSGI < 1.9.13)
I tested it with Python 2.7 as well and it still works, which suggests it
doesn't break anything for Python 2 (at least any recent version). It's no
great coding I'm sure, but it appears to get the job done. If you want to go
with it and would prefer it via a Github pull request, just let me know.
-Martin
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi