| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
0 parents commit 375a88e
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + { | ||
| 2 | + // 使用 IntelliSense 了解相关属性。 | ||
| 3 | + // 悬停以查看现有属性的描述。 | ||
| 4 | + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| 5 | + "version": "0.2.0", | ||
| 6 | + "configurations": [ | ||
| 7 | + { | ||
| 8 | + "name": "Python: Current File", | ||
| 9 | + "type": "python", | ||
| 10 | + "request": "launch", | ||
| 11 | + "program": "${file}", | ||
| 12 | + "args": [ | ||
| 13 | + "123" | ||
| 14 | + ] | ||
| 15 | + }, | ||
| 16 | + ] | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + { | ||
| 2 | + "python.pythonPath": "/Users/Noah/anaconda3/envs/python3/bin/python" | ||
| 3 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + import sys | ||
| 2 | + import urllib.request | ||
| 3 | + | ||
| 4 | + try: | ||
| 5 | + rfc_number = int(sys.argv[1]) | ||
| 6 | + print("number is %d" % rfc_number) | ||
| 7 | + except (IndexError, ValueError): | ||
| 8 | + print('Must supply an RFC number as first argument') | ||
| 9 | + sys.exit(2) | ||
| 10 | + | ||
| 11 | + template = 'http://www.ietf.org/rfc/rfc{}.txt' | ||
| 12 | + url = template.format(rfc_number) | ||
| 13 | + rfc_raw = urllib.request.urlopen(url).read() | ||
| 14 | + rfc = rfc_raw.docoder() | ||
| 15 | + print(rfc) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + import sys | ||
| 2 | + import socket | ||
| 3 | + | ||
| 4 | + try: | ||
| 5 | + rfc_number = int(sys.argv[1]) | ||
| 6 | + except (IndexError, ValueError): | ||
| 7 | + print('Must supply an RFC number as first argument') | ||
| 8 | + sys.exit(2) | ||
| 9 | + | ||
| 10 | + host = 'www.ietf.org' | ||
| 11 | + port = 80 | ||
| 12 | + sock = socket.create_connection((host, port)) | ||
| 13 | + | ||
| 14 | + req = ( | ||
| 15 | + 'GET /rfc/rfc{rfcnum}.txt HTTP/1.1\r\n' | ||
| 16 | + 'Host: {host}:{port}\r\n' | ||
| 17 | + 'User-Agent: Python {version}\r\n' | ||
| 18 | + 'Connection: close\r\n' | ||
| 19 | + '\r\n' | ||
| 20 | + ) | ||
| 21 | + | ||
| 22 | + req = req.format( | ||
| 23 | + rfcnum=rfc_number, | ||
| 24 | + host=host, | ||
| 25 | + port=port, | ||
| 26 | + version=sys.version_info[0] | ||
| 27 | + ) | ||
| 28 | + | ||
| 29 | + sock.sendall(req.encode('ascii')) | ||
| 30 | + rfc_raw = bytearray() | ||
| 31 | + while True: | ||
| 32 | + buf = sock.recv(4096) | ||
| 33 | + if not len(buf): | ||
| 34 | + break | ||
| 35 | + rfc_raw += buf | ||
| 36 | + rfc = rfc_raw.decode('utf-8') | ||
| 37 | + print(rfc) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments