Skip to content

Commit aba6db5

Browse files
fangerertimfel
authored andcommitted
Implement 'socket.gethostname'.
1 parent 325c7de commit aba6db5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SocketModuleBuiltins.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43+
import java.net.InetAddress;
44+
import java.net.UnknownHostException;
4345
import java.util.List;
4446

4547
import com.oracle.graal.python.builtins.Builtin;
@@ -51,6 +53,7 @@
5153
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5254
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5355
import com.oracle.graal.python.runtime.exception.PythonErrorType;
56+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5457
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5558
import com.oracle.truffle.api.dsl.NodeFactory;
5659
import com.oracle.truffle.api.dsl.Specialization;
@@ -75,4 +78,18 @@ Object socket(PythonClass cls, int family, int type, int proto, @SuppressWarning
7578
}
7679
}
7780
}
81+
82+
@Builtin(name = "gethostname", fixedNumOfPositionalArgs = 0)
83+
@GenerateNodeFactory
84+
public abstract static class GetHostnameNode extends PythonBuiltinNode {
85+
@Specialization
86+
@TruffleBoundary
87+
String doGeneric() {
88+
try {
89+
return InetAddress.getLocalHost().getHostName();
90+
} catch (UnknownHostException e) {
91+
throw raise(PythonBuiltinClassType.OSError);
92+
}
93+
}
94+
}
7895
}

0 commit comments

Comments
 (0)