Skip to content

Commit 4d4a6cd

Browse files
authored
Merge pull request unbit#2717 from xrmx/more-backports
Backport tests and example from master
2 parents 58c3d78 + fd23c07 commit 4d4a6cd

File tree

113 files changed

+1890
-901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1890
-901
lines changed

contrib/emperormon.ru

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ template = <<eof
2323
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2424
<meta name="description" content="">
2525
<meta name="author" content="unbit">
26-
<link href="http://unbit.github.com/bootstrap/css/bootstrap.css" rel="stylesheet">
26+
<link href="https://unbit.github.com/bootstrap/css/bootstrap.css" rel="stylesheet">
2727
<style>
2828
body {
2929
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
3030
}
3131
</style>
32-
<link href="http://unbit.github.com/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
32+
<link href="https://unbit.github.com/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
3333
</head>
3434
<body>
3535
@@ -99,8 +99,8 @@ template = <<eof
9999
100100
101101
102-
<script src="http://unbit.github.com/jquery-1.7.2.min.js" type="text/javascript"></script>
103-
<script src="http://unbit.github.com/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
102+
<script src="https://unbit.github.com/jquery-1.7.2.min.js" type="text/javascript"></script>
103+
<script src="https://unbit.github.com/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
104104
</body>
105105
</html>
106106
eof

contrib/graphite_uwsgi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
CARBON_SERVER = "127.0.0.1:2003"
1717

18+
1819
def update_carbon(signum):
1920
# connect to the carbon server
2021
carbon_fd = uwsgi.connect(CARBON_SERVER)

contrib/pypy/uwsgi_pypy_greenlets.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212

1313
uwsgi_pypy_greenlets = {}
1414

15+
1516
def uwsgi_pypy_greenlet_wrapper():
1617
lib.async_schedule_to_req_green()
1718

19+
1820
@ffi.callback("void()")
1921
def uwsgi_pypy_greenlet_schedule():
2022
id = lib.uwsgi.wsgi_req.async_id
21-
modifier1 = lib.uwsgi.wsgi_req.uh.modifier1;
23+
modifier1 = lib.uwsgi.wsgi_req.uh.modifier1
2224

2325
# generate a new greenlet
2426
if not lib.uwsgi.wsgi_req.suspended:
@@ -36,10 +38,11 @@ def uwsgi_pypy_greenlet_schedule():
3638
if lib.uwsgi.p[modifier1].resume:
3739
lib.uwsgi.p[modifier1].resume(ffi.NULL)
3840

41+
3942
@ffi.callback("void(struct wsgi_request *)")
4043
def uwsgi_pypy_greenlet_switch(wsgi_req):
41-
id = wsgi_req.async_id
42-
modifier1 = wsgi_req.uh.modifier1;
44+
wsgi_req.async_id
45+
modifier1 = wsgi_req.uh.modifier1
4346

4447
# this is called in the current greenlet
4548
if lib.uwsgi.p[modifier1].suspend:
@@ -54,7 +57,7 @@ def uwsgi_pypy_greenlet_switch(wsgi_req):
5457
# update current running greenlet
5558
lib.uwsgi.wsgi_req = wsgi_req
5659

57-
if lib.uwsgi.async <= 1:
60+
if lib.uwsgi.async < 1:
5861
raise Exception("pypy greenlets require async mode !!!")
5962
lib.uwsgi.schedule_to_main = uwsgi_pypy_greenlet_switch
6063
lib.uwsgi.schedule_to_req = uwsgi_pypy_greenlet_schedule

contrib/pyuwsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
for arg in sys.argv[2:]:
1212
uwsgi_args.append(arg)
1313

14-
#pyuwsgi.run('welcome.ini')
14+
# pyuwsgi.run('welcome.ini')
1515
pyuwsgi.run(uwsgi_args)
1616

1717
# if you are here uWSGI has been reloaded

contrib/runuwsgi.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import sys
66

7+
78
class Command(BaseCommand):
89
help = "Runs this project as a uWSGI application. Requires the uwsgi binary in system path."
910

@@ -12,10 +13,10 @@ class Command(BaseCommand):
1213

1314
def handle(self, *args, **options):
1415
for arg in args:
15-
k,v = arg.split('=')
16+
k, v = arg.split('=')
1617
if k == 'http':
1718
if self.http_port:
18-
self.http_port = v
19+
self.http_port = v
1920
elif k == 'socket':
2021
self.http_port = None
2122
self.socket_addr = v
@@ -40,8 +41,8 @@ def handle(self, *args, **options):
4041
elif self.socket_addr:
4142
os.environ['UWSGI_SOCKET'] = self.socket_addr
4243

43-
# map admin static files
44-
os.environ['UWSGI_STATIC_MAP'] = '%s=%s' % (settings.ADMIN_MEDIA_PREFIX, os.path.join(django.__path__[0], 'contrib', 'admin', 'media'))
44+
# map admin static files
45+
os.environ['UWSGI_STATIC_MAP'] = '%s=%s' % (settings.ADMIN_MEDIA_PREFIX, os.path.join(django.__path__[0], 'contrib', 'admin', 'media'))
4546
# remove sockets/pidfile at exit
4647
os.environ['UWSGI_VACUUM'] = '1'
4748
# retrieve/set the PythonHome
@@ -57,7 +58,7 @@ def handle(self, *args, **options):
5758
# exec the uwsgi binary
5859
os.execvp('uwsgi', ('uwsgi',))
5960

60-
def usage(self, subcomand):
61+
def usage(self, subcommand):
6162
return r"""
6263
run this project on the uWSGI server
6364

contrib/spoolqueue/producer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from tasksconsumer import enqueue
22

3+
34
def application(env, sr):
45

5-
sr('200 OK', [('Content-Type','text/html')])
6+
sr('200 OK', [('Content-Type', 'text/html')])
67

78
enqueue(queue='fast', pippo='pluto')
89

910
return "Task enqueued"
10-
11-

contrib/spoolqueue/tasks.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from tasksconsumer import *
1+
from __future__ import print_function
2+
3+
from tasksconsumer import queueconsumer
4+
25

36
@queueconsumer('fast', 4)
47
def fast_queue(arguments):
5-
print "fast", arguments
8+
print("fast", arguments)
9+
610

711
@queueconsumer('slow')
812
def slow_queue(arguments):
9-
print "foobar", arguments
13+
print("foobar", arguments)

contrib/spoolqueue/tasksconsumer.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
from uwsgidecorators import *
2-
import Queue
1+
from uwsgidecorators import spool
32
from threading import Thread
43

4+
from six.moves import queue
5+
56
queues = {}
67

8+
79
class queueconsumer(object):
810

911
def __init__(self, name, num=1, **kwargs):
1012
self.name = name
11-
self.num = num
12-
self.queue = Queue.Queue()
13-
self.threads = []
14-
self.func = None
15-
queues[self.name] = self
16-
13+
self.num = num
14+
self.queue = queue.Queue()
15+
self.threads = []
16+
self.func = None
17+
queues[self.name] = self
1718

1819
@staticmethod
1920
def consumer(self):
2021
while True:
21-
req = self.queue.get()
22-
print req
23-
self.func(req)
24-
self.queue.task_done()
22+
req = self.queue.get()
23+
print(req)
24+
self.func(req)
25+
self.queue.task_done()
2526

2627
def __call__(self, f):
2728
self.func = f
28-
for i in range(self.num):
29-
t = Thread(target=self.consumer,args=(self,))
30-
self.threads.append(t)
31-
t.daemon = True
32-
t.start()
29+
for i in range(self.num):
30+
t = Thread(target=self.consumer, args=(self,))
31+
self.threads.append(t)
32+
t.daemon = True
33+
t.start()
34+
3335

3436
@spool
3537
def spooler_enqueuer(arguments):

contrib/twuwsgi.py

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from twisted.internet import defer, protocol, reactor
22
from twisted.protocols import basic
3-
from twisted.web2 import server, http, resource, responsecode, stream, channel
4-
from twisted.application import service, strports
3+
from twisted.web2 import http, resource, responsecode, stream
54

65
import struct
76

87

98
class uWSGIClientResource(resource.LeafResource):
109

11-
def __init__(self,app='', port=3030, host='localhost'):
10+
def __init__(self, app='', port=3030, host='localhost'):
1211
resource.LeafResource.__init__(self)
1312
self.host = host
1413
self.port = port
15-
self.app = app
16-
14+
self.app = app
15+
1716
def renderHTTP(self, request):
1817
return uWSGI(request, self.app, self.host, self.port)
1918

19+
2020
def uWSGI(request, app, host, port):
2121
if request.stream.length is None:
2222
return http.Response(responsecode.LENGTH_REQUIRED)
@@ -25,60 +25,59 @@ def uWSGI(request, app, host, port):
2525
factory = uWSGIClientProtocolFactory(request)
2626
reactor.connectTCP(host, port, factory)
2727
return factory.deferred
28-
28+
29+
2930
class uWSGIClientProtocol(basic.LineReceiver):
30-
31+
3132
def __init__(self, request, deferred):
3233
self.request = request
3334
self.deferred = deferred
3435
self.stream = stream.ProducerStream()
3536
self.response = http.Response(stream=self.stream)
36-
self.status_parsed = None
37+
self.status_parsed = None
3738

38-
def build_uwsgi_var(self,key,value):
39-
return struct.pack('<H',len(key)) + key + struct.pack('<H',len(value)) + value
39+
def build_uwsgi_var(self, key, value):
40+
return struct.pack('<H', len(key)) + key + struct.pack('<H', len(value)) + value
4041

4142
def connectionMade(self):
42-
print self.request.__dict__
43-
# reset response parser
44-
self.status_parsed = None
45-
# build header and vars
46-
vars = ''
47-
48-
if self.request.stream.length:
49-
vars += self.build_uwsgi_var('CONTENT_LENGTH',str(self.request.stream.length))
50-
51-
for hkey, hval in self.request.headers.getAllRawHeaders():
52-
# use a list, probably it will be extended
53-
if hkey.lower() not in ('content-type'):
54-
vars += self.build_uwsgi_var('HTTP_'+hkey.upper().replace('-','_'),','.join(hval))
55-
else:
56-
vars += self.build_uwsgi_var(hkey.upper().replace('-','_'),','.join(hval))
57-
58-
59-
vars += self.build_uwsgi_var('REQUEST_METHOD', self.request.method)
60-
vars += self.build_uwsgi_var('SCRIPT_NAME', self.request.uwsgi_app)
61-
vars += self.build_uwsgi_var('PATH_INFO', self.request.path[len(self.request.uwsgi_app):])
62-
vars += self.build_uwsgi_var('QUERY_STRING', self.request.querystring)
63-
vars += self.build_uwsgi_var('SERVER_NAME', self.request.host)
64-
vars += self.build_uwsgi_var('SERVER_PORT', str(self.request.port))
65-
vars += self.build_uwsgi_var('SERVER_PROTOCOL', self.request.scheme.upper()+'/'+str(self.request.clientproto[0]) +'.'+str(self.request.clientproto[1]))
66-
67-
vars += self.build_uwsgi_var('REQUEST_URI', self.request.uri)
68-
vars += self.build_uwsgi_var('REMOTE_ADDR', self.request.remoteAddr.host)
69-
70-
71-
self.transport.write(struct.pack('<BHB',0, len(vars),0))
72-
self.transport.write(vars)
73-
74-
# send request data
43+
print(self.request.__dict__)
44+
# reset response parser
45+
self.status_parsed = None
46+
# build header and vars
47+
vars = ''
48+
49+
if self.request.stream.length:
50+
vars += self.build_uwsgi_var('CONTENT_LENGTH', str(self.request.stream.length))
51+
52+
for hkey, hval in self.request.headers.getAllRawHeaders():
53+
# use a list, probably it will be extended
54+
if hkey.lower() not in ('content-type'):
55+
vars += self.build_uwsgi_var('HTTP_' + hkey.upper().replace('-', '_'), ','.join(hval))
56+
else:
57+
vars += self.build_uwsgi_var(hkey.upper().replace('-', '_'), ','.join(hval))
58+
59+
vars += self.build_uwsgi_var('REQUEST_METHOD', self.request.method)
60+
vars += self.build_uwsgi_var('SCRIPT_NAME', self.request.uwsgi_app)
61+
vars += self.build_uwsgi_var('PATH_INFO', self.request.path[len(self.request.uwsgi_app):])
62+
vars += self.build_uwsgi_var('QUERY_STRING', self.request.querystring)
63+
vars += self.build_uwsgi_var('SERVER_NAME', self.request.host)
64+
vars += self.build_uwsgi_var('SERVER_PORT', str(self.request.port))
65+
vars += self.build_uwsgi_var('SERVER_PROTOCOL', self.request.scheme.upper() + '/' + str(self.request.clientproto[0]) + '.' + str(self.request.clientproto[1]))
66+
67+
vars += self.build_uwsgi_var('REQUEST_URI', self.request.uri)
68+
vars += self.build_uwsgi_var('REMOTE_ADDR', self.request.remoteAddr.host)
69+
70+
self.transport.write(struct.pack('<BHB', 0, len(vars), 0))
71+
self.transport.write(vars)
72+
73+
# send request data
7574
stream.StreamProducer(self.request.stream).beginProducing(self.transport)
76-
75+
7776
def lineReceived(self, line):
78-
if self.status_parsed is None:
79-
self.response.code = line.split(' ',2)[1]
80-
self.status_parsed = True
81-
return
77+
if self.status_parsed is None:
78+
self.response.code = line.split(' ', 2)[1]
79+
self.status_parsed = True
80+
return
8281

8382
# end of headers
8483
if line == '':
@@ -87,33 +86,33 @@ def lineReceived(self, line):
8786
self.response = None
8887
return
8988

90-
name, value = line.split(':',1)
89+
name, value = line.split(':', 1)
9190
value = value.strip()
9291

9392
self.response.headers.addRawHeader(name, value)
94-
93+
9594
def rawDataReceived(self, data):
9695
self.stream.write(data)
97-
96+
9897
def connectionLost(self, reason):
9998
self.stream.finish()
100-
101-
99+
100+
102101
class uWSGIClientProtocolFactory(protocol.ClientFactory):
103102

104103
protocol = uWSGIClientProtocol
105-
noisy = False # Make Factory shut up
106-
104+
noisy = False # Make Factory shut up
105+
107106
def __init__(self, request):
108107
self.request = request
109108
self.deferred = defer.Deferred()
110-
109+
111110
def buildProtocol(self, addr):
112111
return self.protocol(self.request, self.deferred)
113-
112+
114113
def clientConnectionFailed(self, connector, reason):
115114
self.sendFailureResponse(reason)
116-
115+
117116
def sendFailureResponse(self, reason):
118117
response = http.Response(code=responsecode.BAD_GATEWAY, stream=str(reason.value))
119118
self.deferred.callback(response)

0 commit comments

Comments
 (0)