This would be even cooler if it implemented the `dict` interface:

```python
>>> c = PeerCertificate(sock)
>>> c['hostname']
'wolever.net'
```

You can do this by subclassing `UserDict.IterableUserDict`:

```python
try:
    from UserDict import IterableUserDict as UserDict
except ImportError:
    # Python 3 - yay!
    from collections import UserDict

class PeerCertificate(UserDict):
    def __init__(self, ssl_sock):
        UserDict.__init__(self, ssl_sock.getpeercert())
```

(and, alternatively, if you want to lazy-load the peer's cert, you could use [`DictMixin`](http://docs.python.org/2/library/userdict.html#UserDict.DictMixin) and implement the methods it suggests).