User agent constructor.

Basic tests present. Let me know if you want to test more extensively, though it's hard to see how I could write tests without simply repeating the logic of the code.

I 'borrowed' the implementation from Requests: just seemed like the safest thing to do here.