Merge pull request #986 from berkerpeksag/remove-asserts

Raise TypeError instead of AssertionError.
This commit is contained in:
Randall Leeds 2015-02-23 14:30:31 -08:00
commit 5eff21ff0f
3 changed files with 8 additions and 7 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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")