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

View File

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

View File

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