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
|
return self.value
|
||||||
|
|
||||||
def set(self, val):
|
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)
|
self.value = self.validator(val)
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
|||||||
@ -257,8 +257,8 @@ class Response(object):
|
|||||||
|
|
||||||
def process_headers(self, headers):
|
def process_headers(self, headers):
|
||||||
for name, value in 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()
|
value = str(value).strip()
|
||||||
lname = name.lower().strip()
|
lname = name.lower().strip()
|
||||||
if lname == "content-length":
|
if lname == "content-length":
|
||||||
@ -322,9 +322,8 @@ class Response(object):
|
|||||||
|
|
||||||
def write(self, arg):
|
def write(self, arg):
|
||||||
self.send_headers()
|
self.send_headers()
|
||||||
|
if not isinstance(arg, binary_type):
|
||||||
assert isinstance(arg, binary_type), "%r is not a byte." % arg
|
raise TypeError('%r is not a byte' % arg)
|
||||||
|
|
||||||
arglen = len(arg)
|
arglen = len(arg)
|
||||||
tosend = arglen
|
tosend = arglen
|
||||||
if self.response_length is not None:
|
if self.response_length is not None:
|
||||||
|
|||||||
@ -503,7 +503,8 @@ def to_bytestring(value):
|
|||||||
"""Converts a string argument to a byte string"""
|
"""Converts a string argument to a byte string"""
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
return value
|
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")
|
return value.encode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user