Skip to content

Commit

Permalink
Merge pull request #986 from berkerpeksag/remove-asserts
Browse files Browse the repository at this point in the history
Raise TypeError instead of AssertionError.
  • Loading branch information
tilgovi committed Feb 23, 2015
2 parents b6430c3 + d376b6f commit 5eff21f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def get(self):
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):
Expand Down
9 changes: 4 additions & 5 deletions gunicorn/http/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def start_response(self, status, headers, exc_info=None):

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":
Expand Down Expand Up @@ -322,9 +322,8 @@ def send_headers(self):

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:
Expand Down
3 changes: 2 additions & 1 deletion gunicorn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down

0 comments on commit 5eff21f

Please sign in to comment.