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:
|
||||
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:
|
||||
self.sleep()
|
||||
self.murder_workers()
|
||||
|
||||
@ -210,7 +210,7 @@ class Body(object):
|
||||
|
||||
while size > self.buf.tell():
|
||||
data = self.reader.read(1024)
|
||||
if not len(data):
|
||||
if not data:
|
||||
break
|
||||
self.buf.write(data)
|
||||
|
||||
@ -248,7 +248,7 @@ class Body(object):
|
||||
def readlines(self, size=None):
|
||||
ret = []
|
||||
data = self.read()
|
||||
while len(data):
|
||||
while data:
|
||||
pos = data.find(b"\n")
|
||||
if pos < 0:
|
||||
ret.append(data)
|
||||
|
||||
@ -64,7 +64,7 @@ class Message(object):
|
||||
|
||||
# Parse headers into key/value pairs paying attention
|
||||
# to continuation lines.
|
||||
while len(lines):
|
||||
while lines:
|
||||
if len(headers) >= self.limit_request_fields:
|
||||
raise LimitRequestHeaders("limit request headers fields")
|
||||
|
||||
@ -81,7 +81,7 @@ class Message(object):
|
||||
name, value = name.strip(), [value.lstrip()]
|
||||
|
||||
# Consume value continuation lines
|
||||
while len(lines) and lines[0].startswith((" ", "\t")):
|
||||
while lines and lines[0].startswith((" ", "\t")):
|
||||
curr = lines.pop(0)
|
||||
header_length += len(curr)
|
||||
if header_length > self.limit_request_field_size > 0:
|
||||
|
||||
@ -40,7 +40,7 @@ class Unreader(object):
|
||||
|
||||
while self.buf.tell() < size:
|
||||
chunk = self.chunk()
|
||||
if not len(chunk):
|
||||
if not chunk:
|
||||
ret = self.buf.getvalue()
|
||||
self.buf = six.BytesIO()
|
||||
return ret
|
||||
|
||||
@ -80,7 +80,7 @@ class Statsd(Logger):
|
||||
pass
|
||||
|
||||
# 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)
|
||||
except Exception:
|
||||
Logger.warning(self, "Failed to log to statsd", exc_info=True)
|
||||
|
||||
@ -74,7 +74,7 @@ class request(object):
|
||||
yield lines[:pos+2]
|
||||
lines = lines[pos+2:]
|
||||
pos = lines.find(b"\r\n")
|
||||
if len(lines):
|
||||
if lines:
|
||||
yield lines
|
||||
|
||||
def send_bytes(self):
|
||||
@ -137,7 +137,7 @@ class request(object):
|
||||
def match_read(self, req, body, sizes):
|
||||
data = self.szread(req.body.read, sizes)
|
||||
count = 1000
|
||||
while len(body):
|
||||
while body:
|
||||
if body[:len(data)] != data:
|
||||
raise AssertionError("Invalid body data read: %r != %r" % (
|
||||
data, body[:len(data)]))
|
||||
@ -148,9 +148,9 @@ class request(object):
|
||||
if count <= 0:
|
||||
raise AssertionError("Unexpected apparent EOF")
|
||||
|
||||
if len(body):
|
||||
if body:
|
||||
raise AssertionError("Failed to read entire body: %r" % body)
|
||||
elif len(data):
|
||||
elif data:
|
||||
raise AssertionError("Read beyond expected body: %r" % data)
|
||||
data = req.body.read(sizes())
|
||||
if data:
|
||||
@ -159,7 +159,7 @@ class request(object):
|
||||
def match_readline(self, req, body, sizes):
|
||||
data = self.szread(req.body.readline, sizes)
|
||||
count = 1000
|
||||
while len(body):
|
||||
while body:
|
||||
if body[:len(data)] != data:
|
||||
raise AssertionError("Invalid data read: %r" % data)
|
||||
if b'\n' in data[:-1]:
|
||||
@ -170,9 +170,9 @@ class request(object):
|
||||
count -= 1
|
||||
if count <= 0:
|
||||
raise AssertionError("Apparent unexpected EOF")
|
||||
if len(body):
|
||||
if body:
|
||||
raise AssertionError("Failed to read entire body: %r" % body)
|
||||
elif len(data):
|
||||
elif data:
|
||||
raise AssertionError("Read beyond expected body: %r" % data)
|
||||
data = req.body.readline(sizes())
|
||||
if data:
|
||||
@ -190,7 +190,7 @@ class request(object):
|
||||
raise AssertionError("Invalid body data read: %r != %r" % (
|
||||
line, body[:len(line)]))
|
||||
body = body[len(line):]
|
||||
if len(body):
|
||||
if body:
|
||||
raise AssertionError("Failed to read entire body: %r" % body)
|
||||
data = req.body.readlines(sizes())
|
||||
if data:
|
||||
@ -207,7 +207,7 @@ class request(object):
|
||||
raise AssertionError("Invalid body data read: %r != %r" % (
|
||||
line, body[:len(line)]))
|
||||
body = body[len(line):]
|
||||
if len(body):
|
||||
if body:
|
||||
raise AssertionError("Failed to read entire body: %r" % body)
|
||||
try:
|
||||
data = six.next(iter(req.body))
|
||||
@ -254,7 +254,7 @@ class request(object):
|
||||
p = RequestParser(cfg, sender())
|
||||
for req in p:
|
||||
self.same(req, sizer, matcher, cases.pop(0))
|
||||
assert len(cases) == 0
|
||||
assert not cases
|
||||
|
||||
def same(self, req, sizer, matcher, exp):
|
||||
assert req.method == exp["method"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user