Просмотр исходного кода

keep track of eof state in NativeInput (this is probably a crappy way of dealing with this, see https://github.com/frabbit/hx2python/issues/33)

Simon Krajewski 11 лет назад
Родитель
Сommit
ee46053acf
2 измененных файлов с 9 добавлено и 10 удалено
  1. 1 1
      std/python/_std/sys/io/FileInput.hx
  2. 8 9
      std/python/io/NativeInput.hx

+ 1 - 1
std/python/_std/sys/io/FileInput.hx

@@ -12,6 +12,6 @@ class FileInput extends NativeInput {
 	}
 
 	public function eof() {
-		return false; // TODO
+		return wasEof;
 	}
 }

+ 8 - 9
std/python/io/NativeInput.hx

@@ -12,11 +12,13 @@ import python.lib.io.IOBase.SeekSet;
 class NativeInput extends Input{
 
 	var stream:RawIOBase;
+	var wasEof:Bool;
 
 	public var canSeek(get_canSeek, null):Bool;
 
 	public function new (stream:RawIOBase) {
 		this.stream = stream;
+		wasEof = false;
 		if (!stream.readable()) throw "Write-only stream";
 	}
 
@@ -40,7 +42,7 @@ class NativeInput extends Input{
 
 		var ret = stream.read(1);
 
-		if (ret.length == 0) throw new Eof();
+		if (ret.length == 0) throwEof();
 
 		return ret.get(0);
 	}
@@ -53,6 +55,7 @@ class NativeInput extends Input{
 			case SeekCur: SeekSet.SeekCur;
 			case SeekEnd: SeekSet.SeekEnd;
 		};
+		wasEof = false;
 		stream.seek(p, pos);
 	}
 
@@ -67,16 +70,12 @@ class NativeInput extends Input{
 		var ret = stream.readinto(ba);
 		s.blit(pos, haxe.io.Bytes.ofData(ba) ,0,len);
 		if (ret == 0)
-			throw new Eof();
+			throwEof();
 		return ret;
 	}
 
-
-	/*
-
-	public function eof() : Bool
-	{
-		return stream.Position == stream.Length;
+	function throwEof() {
+		wasEof = true;
+		throw new Eof();
 	}
-	*/
 }