Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,13 +1296,11 @@ def json(self):
ctype = self.environ.get('CONTENT_TYPE', '').lower().split(';')[0]
if ctype in ('application/json', 'application/json-rpc'):
b = self._get_body_string(self.MEMFILE_MAX)
if not b:
return None
try:
return json_loads(b)
except (ValueError, TypeError):
raise HTTPError(400, 'Invalid JSON')
return None
if b:
try:
return json_loads(b)
except (ValueError, TypeError):
raise HTTPError(400, 'Invalid JSON')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed shorter and clearer.


def _iter_body(self, read, bufsize):
maxread = max(0, self.content_length)
Expand Down Expand Up @@ -1518,7 +1516,6 @@ def auth(self):
if basic: return basic
ruser = self.environ.get('REMOTE_USER')
if ruser: return (ruser, None)
return None

@property
def remote_route(self):
Expand Down Expand Up @@ -2981,7 +2978,7 @@ def parse_date(ims):
ts = email.utils.parsedate_tz(ims)
return calendar.timegm(ts[:8] + (0, )) - (ts[9] or 0)
except (TypeError, ValueError, IndexError, OverflowError):
return None
pass


def parse_auth(header):
Expand All @@ -2992,7 +2989,7 @@ def parse_auth(header):
user, pwd = touni(base64.b64decode(tob(data))).split(':', 1)
return user, pwd
except (KeyError, ValueError):
return None
pass


def parse_range_header(header, maxlen=0):
Expand Down Expand Up @@ -3090,7 +3087,6 @@ def cookie_decode(data, key, digestmod=None):
hashed = hmac.new(tob(key), msg, digestmod=digestmod).digest()
if _lscmp(sig[1:], base64.b64encode(hashed)):
return pickle.loads(base64.b64decode(msg))
return None


def cookie_is_encoded(data):
Expand Down