adds Response.__len__ #854

I think it should be okay to use response headers for content length, falling back on len(response.content) if they aren't provided. I tested this against httpbin('stream') and it seems okay. #854


I think this is a bad idea, see how `len()` builtin is limited on python2 32bit

```
>>> class A(object):
...     def __len__(self):
...         return 2*1024**3 # use sys.maxint+1 to reproduce on 64bits 
...     
...     
>>> a = A()
>>> a.__len__()
2147483648L
>>> len(a)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)

/home/daniel/src/<ipython console> in <module>()

OverflowError: long int too large to convert to int
```

and you are trying to add the same weird feature I faced this issue in discoproject/disco#270


@dangra that's a great point. Although, on 64 bit machines (like I'm on at the moment) I did this:

```
>>> import sys
>>> class A:
...     def __len__(self):
...             return sys.maxint+1
... 
>>> a = A()
>>> a.__len__()
9223372036854775808L
>>> len(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __len__() should return an int
>>> class A:
...     def __len__(self):
...             return int(sys.maxint + 1)
... 
>>> a = A()
>>> len(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __len__() should return an int
>>> a.__len__()
9223372036854775808L
```

Just so no one tries to say you're wrong, this is in fact the same problem. I'm also using py26, which probably explains the difference in Errors. Also python3 doesn't apparently have `sys.maxint` so I just used the value returned above from py26 and got the OverflowError.


Hrmmm. Is there a workaround for this? Is this a showstopper? Does
downloading a 2GB file with requests break anything else?

On Mon, Sep 17, 2012 at 8:00 AM, Ian Cordasco notifications@github.comwrote:

> @dangra https://github.com/dangra that's a great point. Although, on 64
> bit machines (like I'm on at the moment) I did this:
> 
> > > > import sys
> > > > class A:
> > > > ...     def **len**(self):
> > > > ...             return sys.maxint+1
> > > > ...
> > > > a = A()
> > > > a.**len**()
> > > > 9223372036854775808L
> > > > len(a)
> > > > Traceback (most recent call last):
> > > >   File "<stdin>", line 1, in <module>
> > > > TypeError: **len**() should return an int
> > > > class A:
> > > > ...     def **len**(self):
> > > > ...             return int(sys.maxint + 1)
> > > > ...
> > > > a = A()
> > > > len(a)
> > > > Traceback (most recent call last):
> > > >   File "<stdin>", line 1, in <module>
> > > > TypeError: **len**() should return an int
> > > > a.**len**()
> > > > 9223372036854775808L
> 
> Just so no one tries to say you're wrong, this is in fact the same
> problem. I'm also using py26, which probably explains the difference in
> Errors. Also python3 doesn't apparently have sys.maxint so I just used
> the value returned above from py26 and got the OverflowError.
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kennethreitz/requests/pull/856#issuecomment-8613139.

## 

-Ben Toews


the point is that if other parts of requests (or even third party libraries) start using `len()` builtin to reliable get the response size, they will become broken for files larger than 2GB in 32bits systems.

this is a limitation of the len() builtin, why not add a `content_length()` method if you really want this shortcut to response size?


I think it is more Pythonic and elegant to use the len() method, but I
agree that it is a problem if len() cannot return longs.

On Mon, Sep 17, 2012 at 9:44 AM, Daniel Graña notifications@github.comwrote:

> the point is that if other parts of requests (or even third party
> libraries) start using len() builtin to reliable get the response size,
> they will become broken for files larger than 2G in 32bits systems.
> 
> this is a limitation of the len() builtin, why not add a content_lenght()method if you really want this shortcut to response size?
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/kennethreitz/requests/pull/856#issuecomment-8617045.

## 

-Ben Toews


I considered this early on when working on Requests. I decided to keep it out because you aren't interacting with a Response object like a string. If you do unicode(Response), it doesn't contain the value of the response. So, len didn't make sense to me either.


Thanks for the contribution though, I'll definitely consider it again in the future. The longs issue def makes it a no-brainer to not include at the moment.


On an entirely unrelated note @mastahyeti , it appears your commiter email address and the address you used to sign up for GitHub are not one and the same. You can add that email address to your GitHub profile if you want the committer/author on the diffs to point back to you.