1
1
import sys
2
2
import os
3
3
sys .path .insert (0 , '.' )
4
- sys .path .extend (os .environ .get ('PYTHONPATH' ,'' ).split (os .pathsep ))
4
+ sys .path .extend (os .environ .get ('PYTHONPATH' , '' ).split (os .pathsep ))
5
5
import imp
6
6
import traceback
7
7
48
48
uwsgi_defines = []
49
49
uwsgi_cflags = ffi .string (lib0 .uwsgi_get_cflags ()).split ()
50
50
for cflag in uwsgi_cflags :
51
- if cflag .startswith ('-D' ):
52
- line = cflag [2 :]
51
+ if cflag .startswith (b '-D' ):
52
+ line = cflag [2 :]. decode ()
53
53
if '=' in line :
54
54
(key , value ) = line .split ('=' , 1 )
55
55
uwsgi_cdef .append ('#define %s ...' % key )
56
- uwsgi_defines .append ('#define %s %s' % (key , value .replace ('\\ "' ,'"' ).replace ('""' ,'"' )))
56
+ uwsgi_defines .append ('#define %s %s' % (key , value .replace ('\\ "' ,'"' ).replace ('""' ,'"' )))
57
57
else :
58
58
uwsgi_cdef .append ('#define %s ...' % line )
59
- uwsgi_defines .append ('#define %s 1' % line )
59
+ uwsgi_defines .append ('#define %s 1' % line )
60
60
uwsgi_dot_h = ffi .string (lib0 .uwsgi_get_dot_h ())
61
61
62
62
# uwsgi definitions
166
166
struct uwsgi_plugin *p[];
167
167
...;
168
168
};
169
- struct uwsgi_server uwsgi;
169
+ extern struct uwsgi_server uwsgi;
170
170
171
- struct uwsgi_plugin pypy_plugin;
171
+ extern struct uwsgi_plugin pypy_plugin;
172
172
173
- const char *uwsgi_pypy_version;
173
+ extern const char *uwsgi_pypy_version;
174
174
175
175
char *uwsgi_binary_path();
176
176
177
177
void *uwsgi_malloc(size_t);
178
178
179
+ struct uwsgi_logvar {
180
+ char key[256];
181
+ uint8_t keylen;
182
+ char val[256];
183
+ uint8_t vallen;
184
+ struct uwsgi_logvar *next;
185
+ };
186
+
187
+ struct uwsgi_logvar *uwsgi_logvar_get(struct wsgi_request *, char *, uint8_t);
188
+ void uwsgi_logvar_add(struct wsgi_request *, char *, uint8_t, char *, uint8_t);
189
+
179
190
int uwsgi_response_prepare_headers(struct wsgi_request *, char *, size_t);
180
191
int uwsgi_response_add_header(struct wsgi_request *, char *, uint16_t, char *, uint16_t);
181
192
int uwsgi_response_write_body_do(struct wsgi_request *, char *, size_t);
237
248
238
249
int uwsgi_ready_fd(struct wsgi_request *);
239
250
240
- void set_user_harakiri(int);
251
+ void set_user_harakiri(struct wsgi_request *, int);
241
252
242
253
int uwsgi_metric_set(char *, char *, int64_t);
243
254
int uwsgi_metric_inc(char *, char *, int64_t);
260
271
extern struct uwsgi_server uwsgi;
261
272
extern struct uwsgi_plugin pypy_plugin;
262
273
%s
263
- ''' % ('\n ' .join (uwsgi_defines ), uwsgi_dot_h , hooks )
274
+ ''' % ('\n ' .join (uwsgi_defines ), uwsgi_dot_h . decode () , hooks )
264
275
265
276
ffi .cdef (cdefines )
266
277
lib = ffi .verify (cverify )
267
278
libc = ffi .dlopen (None )
268
279
269
280
270
-
271
281
"""
272
282
this is a global object point the the WSGI callable
273
283
it sucks, i will fix it in the near future...
276
286
277
287
# fix argv if needed
278
288
if len (sys .argv ) == 0 :
279
- sys .argv .insert (0 , ffi .string (lib .uwsgi_binary_path ()))
289
+ sys .argv .insert (0 , ffi .string (lib .uwsgi_binary_path ()). decode () )
280
290
281
291
"""
282
292
execute source, we expose it as cffi callback to avoid deadlocks
@@ -293,7 +303,7 @@ def uwsgi_pypy_execute_source(s):
293
303
@ffi .callback ("void(char *)" )
294
304
def uwsgi_pypy_loader (module ):
295
305
global wsgi_application
296
- m = ffi .string (module )
306
+ m = ffi .string (module ). decode ()
297
307
c = 'application'
298
308
if ':' in m :
299
309
m , c = m .split (':' )
@@ -311,7 +321,7 @@ def uwsgi_pypy_file_loader(filename):
311
321
global wsgi_application
312
322
w = ffi .string (filename )
313
323
c = 'application'
314
- mod = imp .load_source ('uwsgi_file_wsgi' , w )
324
+ mod = imp .load_source ('uwsgi_file_wsgi' , w . decode () )
315
325
wsgi_application = getattr (mod , c )
316
326
317
327
"""
@@ -320,7 +330,7 @@ def uwsgi_pypy_file_loader(filename):
320
330
@ffi .callback ("void(char *)" )
321
331
def uwsgi_pypy_paste_loader (config ):
322
332
global wsgi_application
323
- c = ffi .string (config )
333
+ c = ffi .string (config ). decode ()
324
334
if c .startswith ('config:' ):
325
335
c = c [7 :]
326
336
if c [0 ] != '/' :
@@ -329,7 +339,7 @@ def uwsgi_pypy_paste_loader(config):
329
339
from logging .config import fileConfig
330
340
fileConfig (c )
331
341
except ImportError :
332
- print "PyPy WARNING: unable to load logging.config"
342
+ print ( "PyPy WARNING: unable to load logging.config" )
333
343
from paste .deploy import loadapp
334
344
wsgi_application = loadapp ('config:%s' % c )
335
345
@@ -347,9 +357,9 @@ def uwsgi_pypy_post_fork_hook():
347
357
"""
348
358
@ffi .callback ("void(char *)" )
349
359
def uwsgi_pypy_pythonpath (item ):
350
- path = ffi .string (item )
360
+ path = ffi .string (item ). decode ()
351
361
sys .path .append (path )
352
- print "added %s to pythonpath" % path
362
+ print ( "added %s to pythonpath" % path )
353
363
354
364
355
365
"""
@@ -443,15 +453,17 @@ def writer(data):
443
453
def start_response (status , headers , exc_info = None ):
444
454
if exc_info :
445
455
traceback .print_exception (* exc_info )
456
+ status = status .encode ()
446
457
lib .uwsgi_response_prepare_headers (wsgi_req , ffi .new ("char[]" , status ), len (status ))
447
458
for hh in headers :
459
+ hh = (hh [0 ].encode (), hh [1 ].encode ())
448
460
lib .uwsgi_response_add_header (wsgi_req , ffi .new ("char[]" , hh [0 ]), len (hh [0 ]), ffi .new ("char[]" , hh [1 ]), len (hh [1 ]))
449
461
return writer
450
462
451
463
environ = {}
452
464
iov = wsgi_req .hvec
453
465
for i in range (0 , wsgi_req .var_cnt , 2 ):
454
- 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 )
466
+ 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 ( )
455
467
456
468
environ ['wsgi.version' ] = (1 , 0 )
457
469
scheme = 'http'
@@ -568,8 +580,8 @@ def uwsgi_pypy_rpc(node, func, *args):
568
580
569
581
def uwsgi_pypy_call (func , * args ):
570
582
node = None
571
- if '@' in func :
572
- (func , node ) = func .split ('@' )
583
+ if b '@' in func :
584
+ (func , node ) = func .split (b '@' )
573
585
return uwsgi_pypy_rpc (node , func , * args )
574
586
uwsgi .call = uwsgi_pypy_call
575
587
@@ -708,7 +720,7 @@ def uwsgi_pypy_current_wsgi_req():
708
720
def uwsgi_pypy_suspend ():
709
721
wsgi_req = uwsgi_pypy_current_wsgi_req ()
710
722
if lib .uwsgi .schedule_to_main :
711
- lib .uwsgi .schedule_to_main (wsgi_req );
723
+ lib .uwsgi .schedule_to_main (wsgi_req )
712
724
uwsgi .suspend = uwsgi_pypy_suspend
713
725
714
726
"""
@@ -723,7 +735,7 @@ def uwsgi_pypy_workers():
723
735
worker ['requests' ] = lib .uwsgi .workers [i ].requests
724
736
worker ['delta_requests' ] = lib .uwsgi .workers [i ].delta_requests
725
737
worker ['signals' ] = lib .uwsgi .workers [i ].signals
726
- worker ['exceptions' ] = lib .uwsgi_worker_exceptions (i );
738
+ worker ['exceptions' ] = lib .uwsgi_worker_exceptions (i )
727
739
worker ['apps' ] = []
728
740
if lib .uwsgi .workers [i ].cheaped :
729
741
worker ['status' ] == 'cheap'
@@ -750,8 +762,8 @@ def uwsgi_pypy_workers():
750
762
"""
751
763
def uwsgi_pypy_async_sleep (timeout ):
752
764
if timeout > 0 :
753
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
754
- lib .async_add_timeout (wsgi_req , timeout );
765
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
766
+ lib .async_add_timeout (wsgi_req , timeout )
755
767
uwsgi .async_sleep = uwsgi_pypy_async_sleep
756
768
757
769
"""
@@ -770,7 +782,7 @@ def uwsgi_pypy_async_connect(addr):
770
782
uwsgi.wait_fd_read(fd, timeout=0)
771
783
"""
772
784
def uwsgi_pypy_wait_fd_read (fd , timeout = 0 ):
773
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
785
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
774
786
if lib .async_add_fd_read (wsgi_req , fd , timeout ) < 0 :
775
787
raise Exception ("unable to add fd %d to the event queue" % fd )
776
788
uwsgi .wait_fd_read = uwsgi_pypy_wait_fd_read
@@ -779,7 +791,7 @@ def uwsgi_pypy_wait_fd_read(fd, timeout=0):
779
791
uwsgi.wait_fd_write(fd, timeout=0)
780
792
"""
781
793
def uwsgi_pypy_wait_fd_write (fd , timeout = 0 ):
782
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
794
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
783
795
if lib .async_add_fd_write (wsgi_req , fd , timeout ) < 0 :
784
796
raise Exception ("unable to add fd %d to the event queue" % fd )
785
797
uwsgi .wait_fd_write = uwsgi_pypy_wait_fd_write
@@ -788,7 +800,7 @@ def uwsgi_pypy_wait_fd_write(fd, timeout=0):
788
800
uwsgi.ready_fd()
789
801
"""
790
802
def uwsgi_pypy_ready_fd ():
791
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
803
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
792
804
return lib .uwsgi_ready_fd (wsgi_req )
793
805
uwsgi .ready_fd = uwsgi_pypy_ready_fd
794
806
@@ -800,7 +812,7 @@ def uwsgi_pypy_send(*args):
800
812
if len (args ) == 0 :
801
813
raise ValueError ("uwsgi.send() takes at least 1 argument" )
802
814
elif len (args ) == 1 :
803
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
815
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
804
816
fd = wsgi_req .fd
805
817
data = args [0 ]
806
818
else :
@@ -819,7 +831,7 @@ def uwsgi_pypy_recv(*args):
819
831
if len (args ) == 0 :
820
832
raise ValueError ("uwsgi.recv() takes at least 1 argument" )
821
833
elif len (args ) == 1 :
822
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
834
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
823
835
fd = wsgi_req .fd
824
836
l = args [0 ]
825
837
else :
@@ -846,8 +858,8 @@ def uwsgi_pypy_recv(*args):
846
858
uwsgi.websocket_recv()
847
859
"""
848
860
def uwsgi_pypy_websocket_recv ():
849
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
850
- ub = lib .uwsgi_websocket_recv (wsgi_req );
861
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
862
+ ub = lib .uwsgi_websocket_recv (wsgi_req )
851
863
if ub == ffi .NULL :
852
864
raise IOError ("unable to receive websocket message" )
853
865
ret = ffi .buffer (ub .buf , ub .pos )[:]
@@ -859,8 +871,8 @@ def uwsgi_pypy_websocket_recv():
859
871
uwsgi.websocket_recv_nb()
860
872
"""
861
873
def uwsgi_pypy_websocket_recv_nb ():
862
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
863
- ub = lib .uwsgi_websocket_recv_nb (wsgi_req );
874
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
875
+ ub = lib .uwsgi_websocket_recv_nb (wsgi_req )
864
876
if ub == ffi .NULL :
865
877
raise IOError ("unable to receive websocket message" )
866
878
ret = ffi .buffer (ub .buf , ub .pos )[:]
@@ -872,7 +884,7 @@ def uwsgi_pypy_websocket_recv_nb():
872
884
uwsgi.websocket_handshake(key, origin)
873
885
"""
874
886
def uwsgi_pypy_websocket_handshake (key = '' , origin = '' , proto = '' ):
875
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
887
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
876
888
c_key = ffi .new ('char[]' , key )
877
889
c_origin = ffi .new ('char[]' , origin )
878
890
c_proto = ffi .new ('char[]' , proto )
@@ -884,7 +896,7 @@ def uwsgi_pypy_websocket_handshake(key='', origin='', proto=''):
884
896
uwsgi.websocket_send(msg)
885
897
"""
886
898
def uwsgi_pypy_websocket_send (msg ):
887
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
899
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
888
900
if lib .uwsgi_websocket_send (wsgi_req , ffi .new ('char[]' , msg ), len (msg )) < 0 :
889
901
raise IOError ("unable to send websocket message" )
890
902
uwsgi .websocket_send = uwsgi_pypy_websocket_send
@@ -893,7 +905,7 @@ def uwsgi_pypy_websocket_send(msg):
893
905
uwsgi.chunked_read(timeout=0)
894
906
"""
895
907
def uwsgi_pypy_chunked_read (timeout = 0 ):
896
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
908
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
897
909
rlen = ffi .new ("size_t*" )
898
910
chunk = lib .uwsgi_chunked_read (wsgi_req , rlen , timeout , 0 )
899
911
if chunk == ffi .NULL :
@@ -905,7 +917,7 @@ def uwsgi_pypy_chunked_read(timeout=0):
905
917
uwsgi.chunked_read_nb()
906
918
"""
907
919
def uwsgi_pypy_chunked_read_nb ():
908
- wsgi_req = uwsgi_pypy_current_wsgi_req ();
920
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
909
921
rlen = ffi .new ("size_t*" )
910
922
chunk = lib .uwsgi_chunked_read (wsgi_req , rlen , 0 , 1 )
911
923
if chunk == ffi .NULL :
@@ -915,14 +927,42 @@ def uwsgi_pypy_chunked_read_nb():
915
927
return ffi .buffer (chunk , rlen [0 ])[:]
916
928
uwsgi .chunked_read_nb = uwsgi_pypy_chunked_read_nb
917
929
918
- """
919
- uwsgi.set_user_harakiri(sec)
920
- """
921
- uwsgi .set_user_harakiri = lambda x : lib .set_user_harakiri (x )
930
+
931
+ def uwsgi_pypy_set_user_harakiri (x ):
932
+ """
933
+ uwsgi.set_user_harakiri(sec)
934
+ """
935
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
936
+ lib .set_user_harakiri (wsgi_req , x )
937
+ uwsgi .set_user_harakiri = uwsgi_pypy_set_user_harakiri
938
+
939
+
940
+ def uwsgi_pypy_get_logvar (key ):
941
+ """
942
+ uwsgi.get_logvar(key)
943
+ """
944
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
945
+ c_key = ffi .new ('char[]' , key )
946
+ lv = lib .uwsgi_logvar_get (wsgi_req , c_key , len (key ))
947
+ if lv :
948
+ return ffi .string (lv .val [0 :lv .vallen ])
949
+ return None
950
+ uwsgi .get_logvar = uwsgi_pypy_get_logvar
951
+
952
+
953
+ def uwsgi_pypy_set_logvar (key , val ):
954
+ """
955
+ uwsgi.set_logvar(key, value)
956
+ """
957
+ wsgi_req = uwsgi_pypy_current_wsgi_req ()
958
+ c_key = ffi .new ('char[]' , key )
959
+ c_val = ffi .new ('char[]' , val )
960
+ lib .uwsgi_logvar_add (wsgi_req , c_key , len (key ), c_val , len (val ))
961
+ uwsgi .set_logvar = uwsgi_pypy_set_logvar
922
962
923
963
924
- print "Initialized PyPy with Python" , sys .version
925
- print "PyPy Home:" , sys .prefix
964
+ print ( "Initialized PyPy with Python %s" % sys .version )
965
+ print ( "PyPy Home: %s" % sys .prefix )
926
966
927
967
928
968
"""
@@ -939,7 +979,7 @@ def uwsgi_pypy_continulet_wrapper(cont):
939
979
@ffi .callback ("void()" )
940
980
def uwsgi_pypy_continulet_schedule ():
941
981
id = lib .uwsgi .wsgi_req .async_id
942
- modifier1 = lib .uwsgi .wsgi_req .uh .modifier1 ;
982
+ modifier1 = lib .uwsgi .wsgi_req .uh .modifier1
943
983
944
984
# generate a new continulet
945
985
if not lib .uwsgi .wsgi_req .suspended :
@@ -961,7 +1001,7 @@ def uwsgi_pypy_continulet_schedule():
961
1001
@ffi .callback ("void(struct wsgi_request *)" )
962
1002
def uwsgi_pypy_continulet_switch (wsgi_req ):
963
1003
id = wsgi_req .async_id
964
- modifier1 = wsgi_req .uh .modifier1 ;
1004
+ modifier1 = wsgi_req .uh .modifier1
965
1005
966
1006
# this is called in the current continulet
967
1007
if lib .uwsgi .p [modifier1 ].suspend :
@@ -977,8 +1017,8 @@ def uwsgi_pypy_continulet_switch(wsgi_req):
977
1017
lib .uwsgi .wsgi_req = wsgi_req
978
1018
979
1019
def uwsgi_pypy_setup_continulets ():
980
- if lib .uwsgi . async <= 1 :
1020
+ if lib .uwsgi [ " async" ] < 1 :
981
1021
raise Exception ("pypy continulets require async mode !!!" )
982
1022
lib .uwsgi .schedule_to_main = uwsgi_pypy_continulet_switch
983
1023
lib .uwsgi .schedule_to_req = uwsgi_pypy_continulet_schedule
984
- print "*** PyPy Continulets engine loaded ***"
1024
+ print ( "*** PyPy Continulets engine loaded ***" )
0 commit comments