mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Empty sequences are false, there's no need to check the len.
This commit is contained in:
parent
5b89fe1beb
commit
032271a030
@ -205,7 +205,7 @@ class Arbiter(object):
|
|||||||
while True:
|
while True:
|
||||||
self.maybe_promote_master()
|
self.maybe_promote_master()
|
||||||
|
|
||||||
sig = self.SIG_QUEUE.pop(0) if len(self.SIG_QUEUE) else None
|
sig = self.SIG_QUEUE.pop(0, None)
|
||||||
if sig is None:
|
if sig is None:
|
||||||
self.sleep()
|
self.sleep()
|
||||||
self.murder_workers()
|
self.murder_workers()
|
||||||
|
|||||||
@ -210,7 +210,7 @@ class Body(object):
|
|||||||
|
|
||||||
while size > self.buf.tell():
|
while size > self.buf.tell():
|
||||||
data = self.reader.read(1024)
|
data = self.reader.read(1024)
|
||||||
if not len(data):
|
if not data:
|
||||||
break
|
break
|
||||||
self.buf.write(data)
|
self.buf.write(data)
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ class Body(object):
|
|||||||
def readlines(self, size=None):
|
def readlines(self, size=None):
|
||||||
ret = []
|
ret = []
|
||||||
data = self.read()
|
data = self.read()
|
||||||
while len(data):
|
while data:
|
||||||
pos = data.find(b"\n")
|
pos = data.find(b"\n")
|
||||||
if pos < 0:
|
if pos < 0:
|
||||||
ret.append(data)
|
ret.append(data)
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class Message(object):
|
|||||||
|
|
||||||
# Parse headers into key/value pairs paying attention
|
# Parse headers into key/value pairs paying attention
|
||||||
# to continuation lines.
|
# to continuation lines.
|
||||||
while len(lines):
|
while lines:
|
||||||
if len(headers) >= self.limit_request_fields:
|
if len(headers) >= self.limit_request_fields:
|
||||||
raise LimitRequestHeaders("limit request headers fields")
|
raise LimitRequestHeaders("limit request headers fields")
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class Message(object):
|
|||||||
name, value = name.strip(), [value.lstrip()]
|
name, value = name.strip(), [value.lstrip()]
|
||||||
|
|
||||||
# Consume value continuation lines
|
# Consume value continuation lines
|
||||||
while len(lines) and lines[0].startswith((" ", "\t")):
|
while lines and lines[0].startswith((" ", "\t")):
|
||||||
curr = lines.pop(0)
|
curr = lines.pop(0)
|
||||||
header_length += len(curr)
|
header_length += len(curr)
|
||||||
if header_length > self.limit_request_field_size > 0:
|
if header_length > self.limit_request_field_size > 0:
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class Unreader(object):
|
|||||||
|
|
||||||
while self.buf.tell() < size:
|
while self.buf.tell() < size:
|
||||||
chunk = self.chunk()
|
chunk = self.chunk()
|
||||||
if not len(chunk):
|
if not chunk:
|
||||||
ret = self.buf.getvalue()
|
ret = self.buf.getvalue()
|
||||||
self.buf = six.BytesIO()
|
self.buf = six.BytesIO()
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
@ -80,7 +80,7 @@ class Statsd(Logger):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Log to parent logger only if there is something to say
|
# Log to parent logger only if there is something to say
|
||||||
if msg is not None and len(msg) > 0:
|
if msg:
|
||||||
Logger.log(self, lvl, msg, *args, **kwargs)
|
Logger.log(self, lvl, msg, *args, **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
Logger.warning(self, "Failed to log to statsd", exc_info=True)
|
Logger.warning(self, "Failed to log to statsd", exc_info=True)
|
||||||
|
|||||||
@ -74,7 +74,7 @@ class request(object):
|
|||||||
yield lines[:pos+2]
|
yield lines[:pos+2]
|
||||||
lines = lines[pos+2:]
|
lines = lines[pos+2:]
|
||||||
pos = lines.find(b"\r\n")
|
pos = lines.find(b"\r\n")
|
||||||
if len(lines):
|
if lines:
|
||||||
yield lines
|
yield lines
|
||||||
|
|
||||||
def send_bytes(self):
|
def send_bytes(self):
|
||||||
@ -137,7 +137,7 @@ class request(object):
|
|||||||
def match_read(self, req, body, sizes):
|
def match_read(self, req, body, sizes):
|
||||||
data = self.szread(req.body.read, sizes)
|
data = self.szread(req.body.read, sizes)
|
||||||
count = 1000
|
count = 1000
|
||||||
while len(body):
|
while body:
|
||||||
if body[:len(data)] != data:
|
if body[:len(data)] != data:
|
||||||
raise AssertionError("Invalid body data read: %r != %r" % (
|
raise AssertionError("Invalid body data read: %r != %r" % (
|
||||||
data, body[:len(data)]))
|
data, body[:len(data)]))
|
||||||
@ -148,9 +148,9 @@ class request(object):
|
|||||||
if count <= 0:
|
if count <= 0:
|
||||||
raise AssertionError("Unexpected apparent EOF")
|
raise AssertionError("Unexpected apparent EOF")
|
||||||
|
|
||||||
if len(body):
|
if body:
|
||||||
raise AssertionError("Failed to read entire body: %r" % body)
|
raise AssertionError("Failed to read entire body: %r" % body)
|
||||||
elif len(data):
|
elif data:
|
||||||
raise AssertionError("Read beyond expected body: %r" % data)
|
raise AssertionError("Read beyond expected body: %r" % data)
|
||||||
data = req.body.read(sizes())
|
data = req.body.read(sizes())
|
||||||
if data:
|
if data:
|
||||||
@ -159,7 +159,7 @@ class request(object):
|
|||||||
def match_readline(self, req, body, sizes):
|
def match_readline(self, req, body, sizes):
|
||||||
data = self.szread(req.body.readline, sizes)
|
data = self.szread(req.body.readline, sizes)
|
||||||
count = 1000
|
count = 1000
|
||||||
while len(body):
|
while body:
|
||||||
if body[:len(data)] != data:
|
if body[:len(data)] != data:
|
||||||
raise AssertionError("Invalid data read: %r" % data)
|
raise AssertionError("Invalid data read: %r" % data)
|
||||||
if b'\n' in data[:-1]:
|
if b'\n' in data[:-1]:
|
||||||
@ -170,9 +170,9 @@ class request(object):
|
|||||||
count -= 1
|
count -= 1
|
||||||
if count <= 0:
|
if count <= 0:
|
||||||
raise AssertionError("Apparent unexpected EOF")
|
raise AssertionError("Apparent unexpected EOF")
|
||||||
if len(body):
|
if body:
|
||||||
raise AssertionError("Failed to read entire body: %r" % body)
|
raise AssertionError("Failed to read entire body: %r" % body)
|
||||||
elif len(data):
|
elif data:
|
||||||
raise AssertionError("Read beyond expected body: %r" % data)
|
raise AssertionError("Read beyond expected body: %r" % data)
|
||||||
data = req.body.readline(sizes())
|
data = req.body.readline(sizes())
|
||||||
if data:
|
if data:
|
||||||
@ -190,7 +190,7 @@ class request(object):
|
|||||||
raise AssertionError("Invalid body data read: %r != %r" % (
|
raise AssertionError("Invalid body data read: %r != %r" % (
|
||||||
line, body[:len(line)]))
|
line, body[:len(line)]))
|
||||||
body = body[len(line):]
|
body = body[len(line):]
|
||||||
if len(body):
|
if body:
|
||||||
raise AssertionError("Failed to read entire body: %r" % body)
|
raise AssertionError("Failed to read entire body: %r" % body)
|
||||||
data = req.body.readlines(sizes())
|
data = req.body.readlines(sizes())
|
||||||
if data:
|
if data:
|
||||||
@ -207,7 +207,7 @@ class request(object):
|
|||||||
raise AssertionError("Invalid body data read: %r != %r" % (
|
raise AssertionError("Invalid body data read: %r != %r" % (
|
||||||
line, body[:len(line)]))
|
line, body[:len(line)]))
|
||||||
body = body[len(line):]
|
body = body[len(line):]
|
||||||
if len(body):
|
if body:
|
||||||
raise AssertionError("Failed to read entire body: %r" % body)
|
raise AssertionError("Failed to read entire body: %r" % body)
|
||||||
try:
|
try:
|
||||||
data = six.next(iter(req.body))
|
data = six.next(iter(req.body))
|
||||||
@ -254,7 +254,7 @@ class request(object):
|
|||||||
p = RequestParser(cfg, sender())
|
p = RequestParser(cfg, sender())
|
||||||
for req in p:
|
for req in p:
|
||||||
self.same(req, sizer, matcher, cases.pop(0))
|
self.same(req, sizer, matcher, cases.pop(0))
|
||||||
assert len(cases) == 0
|
assert not cases
|
||||||
|
|
||||||
def same(self, req, sizer, matcher, exp):
|
def same(self, req, sizer, matcher, exp):
|
||||||
assert req.method == exp["method"]
|
assert req.method == exp["method"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user