4848uwsgi_defines = []
4949uwsgi_cflags = ffi .string (lib0 .uwsgi_get_cflags ()).split ()
5050for cflag in uwsgi_cflags :
51- if cflag .startswith ('-D' ):
51+ if cflag .startswith (b '-D' ):
5252 line = cflag [2 :]
53- if '=' in line :
54- (key , value ) = line .split ('=' , 1 )
53+ if b '=' in line :
54+ (key , value ) = line .decode (). split ('=' , 1 )
5555 uwsgi_cdef .append ('#define %s ...' % key )
5656 uwsgi_defines .append ('#define %s %s' % (key , value .replace ('\\ "' , '"' ).replace ('""' , '"' )))
5757 else :
58+ line = line .decode ()
5859 uwsgi_cdef .append ('#define %s ...' % line )
5960 uwsgi_defines .append ('#define %s 1' % line )
6061uwsgi_dot_h = ffi .string (lib0 .uwsgi_get_dot_h ())
166167 struct uwsgi_plugin *p[];
167168 ...;
168169};
169- struct uwsgi_server uwsgi;
170+ extern struct uwsgi_server uwsgi;
170171
171- struct uwsgi_plugin pypy_plugin ;
172+ extern struct uwsgi_plugin pypy3_plugin ;
172173
173- const char *uwsgi_pypy_version;
174+ extern const char *uwsgi_pypy_version;
174175
175176char *uwsgi_binary_path();
176177
177178void *uwsgi_malloc(size_t);
178179
179180struct uwsgi_logvar {
180- char key[256];
181- uint8_t keylen;
182- char val[256];
183- uint8_t vallen;
184- struct uwsgi_logvar *next;
181+ char key[256];
182+ uint8_t keylen;
183+ char val[256];
184+ uint8_t vallen;
185+ struct uwsgi_logvar *next;
185186};
186187
187188struct uwsgi_logvar *uwsgi_logvar_get(struct wsgi_request *, char *, uint8_t);
248249
249250int uwsgi_ready_fd(struct wsgi_request *);
250251
251- void set_user_harakiri(struct wsgi_request *, int);
252+ void set_user_harakiri(int);
252253
253254int uwsgi_metric_set(char *, char *, int64_t);
254255int uwsgi_metric_inc(char *, char *, int64_t);
269270%s
270271
271272extern struct uwsgi_server uwsgi;
272- extern struct uwsgi_plugin pypy_plugin ;
273+ extern struct uwsgi_plugin pypy3_plugin ;
273274%s
274- ''' % ('\n ' .join (uwsgi_defines ), uwsgi_dot_h , hooks )
275+ ''' % ('\n ' .join (uwsgi_defines ), uwsgi_dot_h . decode () , hooks )
275276
276277ffi .cdef (cdefines )
277278lib = ffi .verify (cverify )
286287
287288# fix argv if needed
288289if len (sys .argv ) == 0 :
289- sys .argv .insert (0 , ffi .string (lib .uwsgi_binary_path ()))
290+ sys .argv .insert (0 , ffi .string (lib .uwsgi_binary_path ()). decode () )
290291
291292
292293@ffi .callback ("void(char *)" )
@@ -307,12 +308,12 @@ def uwsgi_pypy_loader(module):
307308 global wsgi_application
308309 m = ffi .string (module )
309310 c = 'application'
310- if ':' in m :
311- m , c = m .split (':' )
312- if '.' in m :
313- mod = __import__ (m , None , None , '*' )
311+ if b ':' in m :
312+ m , c = m .split (b ':' )
313+ if b '.' in m :
314+ mod = __import__ (m . decode () , None , None , '*' )
314315 else :
315- mod = __import__ (m )
316+ mod = __import__ (m . decode () )
316317 wsgi_application = getattr (mod , c )
317318
318319
@@ -324,7 +325,7 @@ def uwsgi_pypy_file_loader(filename):
324325 global wsgi_application
325326 w = ffi .string (filename )
326327 c = 'application'
327- mod = imp .load_source ('uwsgi_file_wsgi' , w )
328+ mod = imp .load_source ('uwsgi_file_wsgi' , w . decode () )
328329 wsgi_application = getattr (mod , c )
329330
330331
@@ -335,15 +336,15 @@ def uwsgi_pypy_paste_loader(config):
335336 """
336337 global wsgi_application
337338 c = ffi .string (config )
338- if c .startswith ('config:' ):
339+ if c .startswith (b 'config:' ):
339340 c = c [7 :]
340- if c [0 ] != '/' :
341- c = os .getcwd () + '/' + c
341+ if c [0 ] != b '/'[ 0 ] :
342+ c = os .getcwd () + '/' + c . decode ()
342343 try :
343- from logging . config import fileConfig
344+ from paste . script . util . logging_config import fileConfig
344345 fileConfig (c )
345346 except ImportError :
346- print ("PyPy WARNING: unable to load logging.config " )
347+ print ("PyPy WARNING: unable to load paste.script.util.logging_config " )
347348 from paste .deploy import loadapp
348349 wsgi_application = loadapp ('config:%s' % c )
349350
@@ -364,8 +365,8 @@ def uwsgi_pypy_pythonpath(item):
364365 add an item to the pythonpath
365366 """
366367 path = ffi .string (item )
367- sys .path .append (path )
368- print ("added %s to pythonpath" % path )
368+ sys .path .append (path . decode () )
369+ print ("added %s to pythonpath" % path . decode () )
369370
370371
371372class WSGIfilewrapper (object ):
@@ -470,15 +471,17 @@ def writer(data):
470471 def start_response (status , headers , exc_info = None ):
471472 if exc_info :
472473 traceback .print_exception (* exc_info )
474+ status = status .encode ()
473475 lib .uwsgi_response_prepare_headers (wsgi_req , ffi .new ("char[]" , status ), len (status ))
474476 for hh in headers :
477+ hh = (hh [0 ].encode (), hh [1 ].encode ())
475478 lib .uwsgi_response_add_header (wsgi_req , ffi .new ("char[]" , hh [0 ]), len (hh [0 ]), ffi .new ("char[]" , hh [1 ]), len (hh [1 ]))
476479 return writer
477480
478481 environ = {}
479482 iov = wsgi_req .hvec
480483 for i in range (0 , wsgi_req .var_cnt , 2 ):
481- environ [ffi .string (ffi .cast ("char*" , iov [i ].iov_base ), iov [i ].iov_len )] = ffi .string (ffi .cast ("char*" , iov [i + 1 ].iov_base ), iov [i + 1 ].iov_len )
484+ environ [ffi .string (ffi .cast ("char*" , iov [i ].iov_base ), iov [i ].iov_len ). decode () ] = ffi .string (ffi .cast ("char*" , iov [i + 1 ].iov_base ), iov [i + 1 ].iov_len ). decode ( )
482485
483486 environ ['wsgi.version' ] = (1 , 0 )
484487 scheme = 'http'
@@ -598,8 +601,8 @@ def uwsgi_pypy_rpc(node, func, *args):
598601
599602def uwsgi_pypy_call (func , * args ):
600603 node = None
601- if '@' in func :
602- (func , node ) = func .split ('@' )
604+ if b '@' in func :
605+ (func , node ) = func .split (b '@' )
603606 return uwsgi_pypy_rpc (node , func , * args )
604607uwsgi .call = uwsgi_pypy_call
605608
@@ -975,13 +978,10 @@ def uwsgi_pypy_chunked_read_nb():
975978uwsgi .chunked_read_nb = uwsgi_pypy_chunked_read_nb
976979
977980
978- def uwsgi_pypy_set_user_harakiri (x ):
979- """
980- uwsgi.set_user_harakiri(sec)
981- """
982- wsgi_req = uwsgi_pypy_current_wsgi_req ()
983- lib .set_user_harakiri (wsgi_req , x )
984- uwsgi .set_user_harakiri = uwsgi_pypy_set_user_harakiri
981+ """
982+ uwsgi.set_user_harakiri(sec)
983+ """
984+ uwsgi .set_user_harakiri = lambda x : lib .set_user_harakiri (x )
985985
986986
987987def uwsgi_pypy_get_logvar (key ):
@@ -1067,7 +1067,7 @@ def uwsgi_pypy_continulet_switch(wsgi_req):
10671067
10681068
10691069def uwsgi_pypy_setup_continulets ():
1070- if lib .uwsgi . async < 1 :
1070+ if lib .uwsgi [ " async" ] < 1 :
10711071 raise Exception ("pypy continulets require async mode !!!" )
10721072 lib .uwsgi .schedule_to_main = uwsgi_pypy_continulet_switch
10731073 lib .uwsgi .schedule_to_req = uwsgi_pypy_continulet_schedule
0 commit comments