FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

提交一下 · noah1985/python_example@375a88e · GitHub

Commit 375a88e

Browse files
Noah Guo
committed
提交一下
0 parents  commit 375a88e

8 files changed

Lines changed: 351 additions & 0 deletions

File tree

‎.idea/misc.xml‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/python_example.iml‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/workspace.xml‎

Lines changed: 253 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.vscode/launch.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

‎.vscode/settings.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.pythonPath": "/Users/Noah/anaconda3/envs/python3/bin/python"
3+
}

‎network_learn/001.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

‎network_learn/002.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL