From 8de0445661a75b3f6586720976b7fa95a55376af Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 13 Jun 2017 11:29:21 +0200 Subject: [PATCH] Move UserAgent to configdata --- qutebrowser/config/configdata.yml | 46 ++++++++++++++++++++- qutebrowser/config/configtypes.py | 69 ------------------------------- scripts/dev/ua_fetch.py | 25 ++++------- 3 files changed, 54 insertions(+), 86 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index ebe2cefba..06a6aef1b 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -421,8 +421,52 @@ content.referer_header: content.user_agent: default: "" type: - name: UserAgent + name: String none_ok: true + completions: + # To update the following list of user agents, run the script 'ua_fetch.py' + # Vim-protip: Place your cursor below this comment and run + # :r!python scripts/dev/ua_fetch.py + - - "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:53.0) Gecko/20100101 + Firefox/53.0" + - Firefox 53.0 Win8.1 + - - "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 + Firefox/53.0" + - Firefox 53.0 Linux + - - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 + Firefox/53.0" + - Firefox 53.0 MacOSX + + - - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 + (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4" + - Safari Generic MacOSX + - - "Mozilla/5.0 (iPad; CPU OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 + (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1" + - Mobile Safari 10.0 iOS + + - - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, + like Gecko) Chrome/58.0.3029.110 Safari/537.36" + - Chrome Generic Win10 + - - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 + (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" + - Chrome Generic MacOSX + - - "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like + Gecko) Chrome/58.0.3029.110 Safari/537.36" + - Chrome Generic Linux + + - - "Mozilla/5.0 (compatible; Googlebot/2.1; + +http://www.google.com/bot.html" + - Google Bot + - - "Wget/1.16.1 (linux-gnu)" + - wget 1.16.1 + - - "curl/7.40.0" + - curl 7.40.0 + - - "Mozilla/5.0 (Linux; U; Android 7.1.2) AppleWebKit/534.30 (KHTML, like + Gecko) Version/4.0 Mobile Safari/534.30" + - Mobile Generic Android + - - "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" + - IE 11.0 for Desktop Win7 64-bit + desc: User agent to send. Empty to send the default. content.proxy: diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index fae84de70..dd2270926 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1301,75 +1301,6 @@ class NewTabPosition(BaseType): ('last', "At the end.")) -class UserAgent(BaseType): - - """The user agent to use.""" - - # FIXME:conf refactor - - def validate(self, value): - self._basic_validation(value) - try: - value.encode('ascii') - except UnicodeEncodeError as e: - msg = "User-Agent contains non-ascii characters: {}".format(e) - raise configexc.ValidationError(value, msg) - - # To update the following list of user agents, run the script 'ua_fetch.py' - # Vim-protip: Place your cursor below this comment and run - # :r!python scripts/dev/ua_fetch.py - def complete(self): - """Complete a list of common user agents.""" - out = [ - ('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 ' - 'Firefox/47.0', - "Firefox Generic Win7"), - ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) ' - 'Gecko/20100101 Firefox/47.0', - "Firefox Generic MacOSX"), - ('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 ' - 'Firefox/47.0', - "Firefox Generic Linux"), - - ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) ' - 'AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 ' - 'Safari/601.7.7', - "Safari Generic MacOSX"), - ('Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) ' - 'AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 ' - 'Mobile/13F69 Safari/601.1', - "Mobile Safari 9.0 iOS"), - - ('Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 ' - '(KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', - "Chrome Generic Win10"), - ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) ' - 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 ' - 'Safari/537.36', - "Chrome Generic MacOSX"), - ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' - '(KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36', - "Chrome Generic Linux"), - - ('Mozilla/5.0 (compatible; Googlebot/2.1; ' - '+http://www.google.com/bot.html', - "Google Bot"), - ('Wget/1.16.1 (linux-gnu)', - "wget 1.16.1"), - ('curl/7.40.0', - "curl 7.40.0"), - - ('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like ' - 'Gecko', - "IE 11.0 for Desktop Win7 64-bit"), - - ('Mozilla/5.0 (Linux; U; Android 7.1.2) AppleWebKit/534.30 ' - '(KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', - "Mobile Generic Android") - ] - return out - - class TimestampTemplate(BaseType): """An strftime-like template for timestamps. diff --git a/scripts/dev/ua_fetch.py b/scripts/dev/ua_fetch.py index 7c39ad596..b276eff27 100755 --- a/scripts/dev/ua_fetch.py +++ b/scripts/dev/ua_fetch.py @@ -24,7 +24,7 @@ """Fetch list of popular user-agents. The script is based on a gist posted by github.com/averrin, the output of this -script is formatted to be pasted into configtypes.py. +script is formatted to be pasted into configdata.yml """ import requests @@ -90,7 +90,10 @@ def add_diversity(table): "curl 7.40.0"), ('Mozilla/5.0 (Linux; U; Android 7.1.2) AppleWebKit/534.30 ' '(KHTML, like Gecko) Version/4.0 Mobile Safari/534.30', - "Mobile Generic Android") + "Mobile Generic Android"), + ('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like ' + 'Gecko', + "IE 11.0 for Desktop Win7 64-bit"), ] return table @@ -106,24 +109,14 @@ def main(): filtered = filter_list(fetched, lut) filtered = add_diversity(filtered) - tab = " " - print(tab + "def complete(self):") - print((2 * tab) + "\"\"\"Complete a list of common user agents.\"\"\"") - print((2 * tab) + "out = [") - + tab = " " for browser in ["Firefox", "Safari", "Chrome", "Obscure"]: for it in filtered[browser]: - print("{}(\'{}\',\n{} \"{}\"),".format(3 * tab, it[0], - 3 * tab, it[1])) + print('{}- - "{}"'.format(3 * tab, it[0])) + desc = it[1].replace('\xa0', ' ').replace(' ', ' ') + print("{}- {}".format(4 * tab, desc)) print("") - print("""\ - ('Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like ' - 'Gecko', - "IE 11.0 for Desktop Win7 64-bit")""") - - print("{}]\n{}return out\n".format(2 * tab, 2 * tab)) - if __name__ == '__main__': main()