Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,35 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.NativeBytesInput;
import python.io.NativeTextInput;
import python.lib.io.RawIOBase;
import python.lib.io.IOBase.SeekSet;
import python.lib.io.TextIOBase;
class FileBytesInput extends NativeBytesInput implements IFileInput {
public function new(stream:RawIOBase) {
super(stream);
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.IFileOutput;
import python.io.NativeBytesOutput;
import python.lib.io.RawIOBase;
class FileBytesOutput extends NativeBytesOutput implements IFileOutput {
public function new(stream:RawIOBase) {
super(stream);
}
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.NativeBytesInput;
import python.io.NativeTextInput;
import python.lib.io.RawIOBase;
import python.lib.io.IOBase.SeekSet;
import python.lib.io.TextIOBase;
class FileTextInput extends NativeTextInput implements IFileInput {
public function new(stream:TextIOBase) {
super(stream);
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.IFileOutput;
import python.io.NativeBytesOutput;
import python.lib.io.TextIOBase;
class FileTextOutput extends NativeTextOutput implements IFileOutput {
public function new(stream:TextIOBase) {
super(stream);
}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.IInput;
import sys.io.FileSeek;
interface IFileInput extends IInput {
public function seek(p:Int, pos:FileSeek):Void;
public function tell():Int;
public function eof():Bool;
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.IOutput;
import sys.io.FileSeek;
interface IFileOutput extends IOutput {
public function seek(p:Int, pos:FileSeek):Void;
public function tell():Int;
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Bytes;
import haxe.io.Encoding;
interface IInput {
public var bigEndian(default, set):Bool;
public function readByte():Int;
public function readBytes(s:Bytes, pos:Int, len:Int):Int;
public function close():Void;
public function readAll(?bufsize:Int):Bytes;
public function readFullBytes(s:Bytes, pos:Int, len:Int):Void;
public function read(nbytes:Int):Bytes;
public function readUntil(end:Int):String;
public function readLine():String;
public function readFloat():Float;
public function readDouble():Float;
public function readInt8():Int;
public function readInt16():Int;
public function readUInt16():Int;
public function readInt24():Int;
public function readUInt24():Int;
public function readInt32():Int;
public function readString(len:Int, ?encoding:Encoding):String;
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Bytes;
import haxe.io.Encoding;
import haxe.io.Input;
interface IOutput {
public var bigEndian(default, set):Bool;
public function writeByte(c:Int):Void;
public function writeBytes(s:Bytes, pos:Int, len:Int):Int;
public function flush():Void;
public function close():Void;
public function write(s:Bytes):Void;
public function writeFullBytes(s:Bytes, pos:Int, len:Int):Void;
public function writeFloat(x:Float):Void;
public function writeDouble(x:Float):Void;
public function writeInt8(x:Int):Void;
public function writeInt16(x:Int):Void;
public function writeUInt16(x:Int):Void;
public function writeInt24(x:Int):Void;
public function writeUInt24(x:Int):Void;
public function writeInt32(x:Int):Void;
public function prepare(nbytes:Int):Void;
public function writeInput(i:Input, ?bufsize:Int):Void;
public function writeString(s:String, ?encoding:Encoding):Void;
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import python.io.FileBytesInput;
import python.io.FileTextInput;
import python.io.FileTextOutput;
import python.io.FileBytesOutput;
import python.lib.io.RawIOBase;
import python.lib.io.TextIOBase;
import sys.io.FileInput;
import sys.io.FileOutput;
import python.lib.io.IOBase.SeekSet;
class IoTools {
public static function createFileInputFromText(t:TextIOBase) {
return @:privateAccess new FileInput(new FileTextInput(t));
}
public static function createFileInputFromBytes(t:RawIOBase) {
return @:privateAccess new FileInput(new FileBytesInput(t));
}
public static function createFileOutputFromText(t:TextIOBase) {
return @:privateAccess new FileOutput(new FileTextOutput(t));
}
public static function createFileOutputFromBytes(t:RawIOBase) {
return @:privateAccess new FileOutput(new FileBytesOutput(t));
}
public static function seekInTextMode(stream:TextIOBase, tell:Void->Int, p:Int, pos:sys.io.FileSeek) {
var pos = switch (pos) {
case SeekBegin:
SeekSet;
case SeekCur:
p = tell() + p;
SeekSet;
case SeekEnd:
stream.seek(0, SeekEnd);
p = tell() + p;
SeekSet;
}
stream.seek(p, pos);
}
public static function seekInBinaryMode(stream:RawIOBase, p:Int, pos:sys.io.FileSeek) {
var pos = switch (pos) {
case SeekBegin: SeekSet;
case SeekCur: SeekCur;
case SeekEnd: SeekEnd;
};
stream.seek(p, pos);
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Eof;
import haxe.io.Input;
import python.io.IInput;
import python.io.IoTools;
import python.Bytearray;
import python.lib.io.RawIOBase;
import python.lib.io.IOBase.SeekSet;
class NativeBytesInput extends NativeInput<RawIOBase> implements IInput {
public function new(stream:RawIOBase) {
super(stream);
}
override public function readByte():Int {
var ret = stream.read(1);
if (ret.length == 0)
throwEof();
return ret.get(0);
}
override public function seek(p:Int, pos:sys.io.FileSeek):Void {
wasEof = false;
return IoTools.seekInBinaryMode(stream, p, pos);
}
override function readinto(b:Bytearray):Int {
return stream.readinto(b);
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Output;
import python.Bytearray;
import python.lib.io.IOBase;
import python.lib.io.RawIOBase;
class NativeBytesOutput extends NativeOutput<RawIOBase> {
public function new(stream:RawIOBase) {
super(stream);
}
public function seek(p:Int, pos:sys.io.FileSeek):Void {
return IoTools.seekInBinaryMode(stream, p, pos);
}
override public function prepare(nbytes:Int):Void {
stream.truncate(nbytes);
}
override public function writeByte(c:Int):Void {
stream.write(new Bytearray([c]));
}
override function writeBytes(s:haxe.io.Bytes, pos:Int, len:Int):Int {
return stream.write(python.Syntax.code("{0}[{1}:{2}]", s.getData(), pos, pos + len));
}
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Eof;
import haxe.io.Input;
import python.Bytearray;
import python.lib.io.IOBase;
import python.lib.io.RawIOBase;
class NativeInput<T:IOBase> extends Input {
var stream:T;
var wasEof:Bool;
function new(s:T) {
this.stream = s;
this.bigEndian = false;
wasEof = false;
if (!stream.readable())
throw "Write-only stream";
}
public var canSeek(get, never):Bool;
inline function get_canSeek():Bool
return stream.seekable();
override public function close():Void {
stream.close();
}
public function tell():Int {
return stream.tell();
}
function throwEof() {
wasEof = true;
throw new Eof();
}
public function eof() {
return wasEof;
}
function readinto(b:Bytearray):Int {
throw "abstract method, should be overridden";
}
function seek(p:Int, mode:sys.io.FileSeek) {
throw "abstract method, should be overridden";
}
override public function readBytes(s:haxe.io.Bytes, pos:Int, len:Int):Int {
if (pos < 0 || len < 0 || pos + len > s.length)
throw haxe.io.Error.OutsideBounds;
var ba = new Bytearray(len);
var ret = readinto(ba);
if (ret == 0)
throwEof();
s.blit(pos, haxe.io.Bytes.ofData(ba), 0, len);
return ret;
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Output;
import python.lib.io.IOBase;
import python.lib.io.RawIOBase;
class NativeOutput<T:IOBase> extends Output {
var stream:T;
public var canSeek(get, never):Bool;
inline function get_canSeek():Bool
return stream.seekable();
public function new(stream:T) {
this.bigEndian = false;
this.stream = stream;
if (!stream.writable())
throw "Read only stream";
}
override public function close():Void {
stream.close();
}
override public function prepare(nbytes:Int):Void {
stream.truncate(nbytes);
}
override public function flush():Void {
stream.flush();
}
public function tell():Int {
return stream.tell();
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Eof;
import haxe.io.Input;
import python.io.IInput;
import python.io.IoTools;
import python.io.NativeInput;
import python.Bytearray;
import python.lib.io.RawIOBase;
import python.lib.io.IOBase.SeekSet;
import python.lib.io.TextIOBase;
class NativeTextInput extends NativeInput<TextIOBase> implements IInput {
public function new(stream:TextIOBase) {
super(stream);
}
override public function readByte():Int {
var ret = stream.buffer.read(1);
if (ret.length == 0)
throwEof();
return ret[0];
}
override public function seek(p:Int, pos:sys.io.FileSeek):Void {
wasEof = false;
IoTools.seekInTextMode(stream, tell, p, pos);
}
override function readinto(b:Bytearray):Int {
return stream.buffer.readinto(b);
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (C)2005-2019 Haxe Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package python.io;
import haxe.io.Output;
import python.io.IoTools;
import python.lib.io.IOBase;
import python.lib.io.RawIOBase;
import python.lib.io.TextIOBase;
class NativeTextOutput extends NativeOutput<TextIOBase> {
public function new(stream:TextIOBase) {
super(stream);
if (!stream.writable())
throw "Read only stream";
}
public function seek(p:Int, pos:sys.io.FileSeek):Void {
IoTools.seekInTextMode(stream, tell, p, pos);
}
override public function writeBytes(s:haxe.io.Bytes, pos:Int, len:Int):Int {
return stream.buffer.write(python.Syntax.arrayAccess(@:privateAccess s.b, pos, pos + len));
}
override public function writeByte(c:Int):Void {
stream.write(String.fromCharCode(c));
}
}