From 1c80c2fdd7dd9873abc7b0a74936dab7beda7c5c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 1 Sep 2012 23:04:44 +1200 Subject: [PATCH] Add a collection of standard User-Agent strings. These will be used in both mitmproxy and pathod. --- netlib/http_uastrings.py | 77 +++++++++++++++++++++++++++++++++++++ test/test_http_uastrings.py | 7 ++++ 2 files changed, 84 insertions(+) create mode 100644 netlib/http_uastrings.py create mode 100644 test/test_http_uastrings.py diff --git a/netlib/http_uastrings.py b/netlib/http_uastrings.py new file mode 100644 index 000000000..826c31a52 --- /dev/null +++ b/netlib/http_uastrings.py @@ -0,0 +1,77 @@ +""" + A small collection of useful user-agent header strings. These should be + kept reasonably current to reflect common usage. +""" + +# A collection of (name, shortcut, string) tuples. + +UASTRINGS = [ + ( + "android", + "a", + "Mozilla/5.0 (Linux; U; Android 4.1.1; en-gb; Nexus 7 Build/JRO03D) AFL/01.04.02" + ), + + ( + "blackberry", + "l", + "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+" + ), + + ( + "bingbot", + "b", + "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" + ), + + ( + "chrome", + "c", + "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1" + ), + + ( + "firefox", + "f", + "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1" + ), + + ( + "googlebot", + "g", + "Googlebot/2.1 (+http://www.googlebot.com/bot.html)" + ), + + ( + "ie9", + "i", + "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))" + ), + + ( + "ipad", + "p", + "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko ) Version/5.1 Mobile/9B176 Safari/7534.48.3" + ), + + ( + "iphone", + "h", + "Mozilla/5.0 (iPhone; CPU iPhone OS 4_2_1 like Mac OS X) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5", + ), + + ( + "safari", + "s", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10" + ) +] + + +def get_by_shortcut(s): + """ + Retrieve a user agent entry by shortcut. + """ + for i in UASTRINGS: + if s == i[1]: + return i diff --git a/test/test_http_uastrings.py b/test/test_http_uastrings.py new file mode 100644 index 000000000..c70b7048e --- /dev/null +++ b/test/test_http_uastrings.py @@ -0,0 +1,7 @@ +from netlib import http_uastrings + + +def test_get_shortcut(): + assert http_uastrings.get_by_shortcut("c")[0] == "chrome" + assert not http_uastrings.get_by_shortcut("_") +