Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/google.py @ 25135:0f0016632be4 legacy-trunk
_formatparam(), set_param(): RFC 2231 encoding support by Oleg
Broytmann in SF patch #600096. Specifically, the former function now
encodes the triplets, while the latter adds optional charset and
language arguments.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Fri, 06 Sep 2002 03:55:04 +0000 |
| parents | 836c1dbf23a0 |
| children | 981fff7363b9 |
| rev | line source |
|---|---|
|
21185
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 import sys, webbrowser |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 def main(): |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 args = sys.argv[1:] |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 if not args: |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 print "Usage: %s querystring" % sys.argv[0] |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 return |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 list = [] |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 for arg in args: |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 if '+' in arg: |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 arg = arg.replace('+', '%2B') |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 if ' ' in arg: |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 arg = '"%s"' % arg |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 arg = arg.replace(' ', '+') |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 list.append(arg) |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 s = '+'.join(list) |
|
21888
836c1dbf23a0
www.google.com is better than google.com.
Guido van Rossum <guido@python.org>
parents:
21185
diff
changeset
|
19 url = "http://www.google.com/search?q=%s" % s |
|
21185
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 webbrowser.open(url) |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
aebce485b56b
A tiny but useful script that fires off a search on Google.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 main() |
