mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #986 from berkerpeksag/remove-asserts
Raise TypeError instead of AssertionError.
This commit is contained in:
commit
5eff21ff0f
@ -268,7 +268,8 @@ class Setting(object):
|
||||
return self.value
|
||||
|
||||
def set(self, val):
|
||||
assert six.callable(self.validator), "Invalid validator: %s" % self.name
|
||||
if not six.callable(self.validator):
|
||||
raise TypeError('Invalid validator: %s' % self.name)
|
||||
self.value = self.validator(val)
|
||||
|
||||
def __lt__(self, other):
|
||||
|
||||
@ -257,8 +257,8 @@ class Response(object):
|
||||
|
||||
def process_headers(self, headers):
|
||||
for name, value in headers:
|
||||
assert isinstance(name, string_types), "%r is not a string" % name
|
||||
|
||||
if not isinstance(name, string_types):
|
||||
raise TypeError('%r is not a string' % name)
|
||||
value = str(value).strip()
|
||||
lname = name.lower().strip()
|
||||
if lname == "content-length":
|
||||
@ -322,9 +322,8 @@ class Response(object):
|
||||
|
||||
def write(self, arg):
|
||||
self.send_headers()
|
||||
|
||||
assert isinstance(arg, binary_type), "%r is not a byte." % arg
|
||||
|
||||
if not isinstance(arg, binary_type):
|
||||
raise TypeError('%r is not a byte' % arg)
|
||||
arglen = len(arg)
|
||||
tosend = arglen
|
||||
if self.response_length is not None:
|
||||
|
||||
@ -503,7 +503,8 @@ def to_bytestring(value):
|
||||
"""Converts a string argument to a byte string"""
|
||||
if isinstance(value, bytes):
|
||||
return value
|
||||
assert isinstance(value, text_type)
|
||||
if not isinstance(value, text_type):
|
||||
raise TypeError('%r is not a string' % value)
|
||||
return value.encode("utf-8")
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user