bottlepy/bottle — pull request #9 by mikemill (2013-06-23 23:29:22+00:00)
Title: Prevent KeyError when accessing body outside of a request.

We ran into a problem using Bottle where we had a bit of code that was executed via HTTP requests as well as from cron jobs using the command line. When executed from outside of a request the _body function would throw a KeyError trying to read the `wsgi.input` from `self.environ`. Below is a sample program that demonstrates the issue:

```Python
import bottle
bottle.request.params
```
Result:
```
Traceback (most recent call last):
File "", line 1, in
File "bottle.py", line 163, in __get__
if key not in storage: storage[key] = self.getter(obj)
File "bottle.py", line 989, in params
for key, value in self.forms.allitems():
File "bottle.py", line 163, in __get__
if key not in storage: storage[key] = self.getter(obj)
File "bottle.py", line 977, in forms
for name, item in self.POST.allitems():
File "bottle.py", line 163, in __get__
if key not in storage: storage[key] = self.getter(obj)
File "bottle.py", line 1065, in POST
pairs = _parse_qsl(tonat(self.body.read(maxlen), 'latin1'))
File "bottle.py", line 1048, in body
self._body.seek(0)
File "bottle.py", line 163, in __get__
if key not in storage: storage[key] = self.getter(obj)
File "bottle.py", line 1030, in _body
stream = self.environ['wsgi.input']
KeyError: 'wsgi.input'
```

This pull request changes the function to return an empty string IO object if `wsgi.input` isn't in `self.environ`