Sfoglia il codice sorgente

get rid of untyped code in Sys

frabbit 11 anni fa
parent
commit
01080cca0d
2 ha cambiato i file con 16 aggiunte e 5 eliminazioni
  1. 13 4
      std/python/Lib.hx
  2. 3 1
      std/python/lib/io/BufferedIOBase.hx

+ 13 - 4
std/python/Lib.hx

@@ -2,20 +2,29 @@ package python;
 
 import python.lib.Types;
 
+typedef PySys = python.lib.Sys;
+typedef PyStringTools = python.lib.StringTools;
 
 @:preCode("import sys as _hx_sys")
 class Lib {
 
 	public static function print(v:Dynamic):Void {
 		var str = Std.string(v);
-		untyped __python__('_hx_sys.stdout.buffer.write(("%s"%str).encode(\'utf-8\'))');
-		untyped __python__('_hx_sys.stdout.flush()');
+
+		PySys.stdout.buffer.write( PyStringTools.encode(str, "utf-8"));
+		PySys.stdout.flush();
+		//untyped __python__('_hx_sys.stdout.buffer.write(("%s"%str).encode(\'utf-8\'))');
+		//untyped __python__('_hx_sys.stdout.flush()');
 	}
 
 	public static function println(v:Dynamic):Void {
 		var str = Std.string(v);
-		untyped __python__('_hx_sys.stdout.buffer.write(("%s\\n"%str).encode(\'utf-8\'))');
-		untyped __python__('_hx_sys.stdout.flush()');
+
+		PySys.stdout.buffer.write( PyStringTools.encode('$str\n', "utf-8"));
+		PySys.stdout.flush();
+
+		//untyped __python__('_hx_sys.stdout.buffer.write(("%s\\n"%str).encode(\'utf-8\'))');
+		//untyped __python__('_hx_sys.stdout.flush()');
 	}
 
 	public static function toPythonIterable <T>(it:Iterable<T>):python.lib.Types.NativeIterable<T> {

+ 3 - 1
std/python/lib/io/BufferedIOBase.hx

@@ -2,11 +2,13 @@
 package python.lib.io;
 
 import python.lib.io.RawIOBase;
+import python.lib.Types.ByteArray;
 
 extern class BufferedIOBase extends IOBase {
 
 	/* not always available */
 	public var raw:RawIOBase;
 
-
+	public function write (b:ByteArray):Int;
+	public function readinto (b:ByteArray):Int;
 }