Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/python-wasm/src/test/posix/netdb.test.ts
1067 views
1
import { syncPython } from "../../node";
2
3
/*
4
>>> import socket; socket.gethostbyaddr('2001:4860:4860::8888')
5
('dns.google', ['8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa'], ['2001:4860:4860::8888'])
6
*/
7
8
test("gethostbyaddr for google's v4 ip -- consistency check", async () => {
9
const { exec, repr } = await syncPython();
10
exec("import socket");
11
exec("s = socket.gethostbyaddr(socket.gethostbyname('google.com'))");
12
// console.log(repr("s"));
13
expect(repr("s[0].endswith('.net')")).toBe("True");
14
});
15
16
// test("gethostbyaddr on a domain name should also work (it does in native cpython)", async () => {
17
// await exec("s = socket.gethostbyaddr('google.com')");
18
// expect(await repr("s[0].endswith('.net')")).toBe("True");
19
// });
20
21
// test("gethostbyaddr for google's v6 ip", async () => {
22
// await exec("s = socket.gethostbyaddr('2001:4860:4860::8888')");
23
// expect(
24
// await repr("s[0] == 'dns.google' and s[-1] == ['2001:4860:4860::8888']")
25
// ).toBe("True");
26
// });
27
28
// test("gethostbyname for google (not sure how stable output is)", async () => {
29
// const ip = eval(await repr("socket.gethostbyname('google.com')"));
30
// expect(ip).toMatch(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/g);
31
// });
32
33
// test("gethostbyaddr on google's ip doesn't fail", async () => {
34
// await exec("google = socket.gethostbyname('google.com')");
35
// expect(await repr("socket.gethostbyaddr(google)[-1][0] == google")).toBe(
36
// "True"
37
// );
38
// });
39
40
// test("getting an error code via a system call", async () => {
41
// await exec(
42
// "try: socket.getaddrinfo('google.com',-10)\nexcept Exception as e: the_error=e"
43
// );
44
// expect((await repr("the_error")).startsWith("gaierror")).toBe(true);
45
// });
46
47
// test("using getaddrinfo with a SOCK_STREAM", async () => {
48
// expect(
49
// await repr(
50
// "socket.getaddrinfo('httpbin.org',80, socket.AF_INET, socket.SOCK_STREAM)"
51
// )
52
// ).toContain("AddressFamily.AF_INET");
53
// });
54
55