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,92 @@
/*
* 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 sys.io;
import python.io.IoTools;
import sys.io.FileInput;
@:coreApi
class File {
public static function getContent(path:String):String {
var f:python.lib.io.TextIOBase = cast python.lib.Builtins.open(path, "r", -1, "utf-8", null, "");
var content = f.read(-1);
f.close();
return content;
}
public static function saveContent(path:String, content:String):Void {
var f:python.lib.io.TextIOBase = cast python.lib.Builtins.open(path, "w", -1, "utf-8", null, "");
f.write(content);
f.close();
}
public static function getBytes(path:String):haxe.io.Bytes {
var f:python.lib.io.RawIOBase = cast python.lib.Builtins.open(path, "rb", -1);
var size = f.read(-1);
var b = haxe.io.Bytes.ofData(size);
f.close();
return b;
}
public static function saveBytes(path:String, bytes:haxe.io.Bytes):Void {
var f:python.lib.io.RawIOBase = cast python.lib.Builtins.open(path, "wb", -1);
f.write(bytes.getData());
f.close();
}
public static function read(path:String, binary:Bool = true):FileInput {
var mode = if (binary) "rb" else "r";
var f = python.lib.Builtins.open(path, mode, -1, null, null, binary ? null : "");
return if (binary) IoTools.createFileInputFromBytes(cast f) else IoTools.createFileInputFromText(cast f);
}
public static function write(path:String, binary:Bool = true):FileOutput {
var mode = if (binary) "wb" else "w";
var f = python.lib.Builtins.open(path, mode, -1, null, null, binary ? null : "");
return if (binary) IoTools.createFileOutputFromBytes(cast f) else IoTools.createFileOutputFromText(cast f);
}
public static function append(path:String, binary:Bool = true):FileOutput {
var mode = if (binary) "ab" else "a";
var f = python.lib.Builtins.open(path, mode, -1, null, null, binary ? null : "");
return if (binary) IoTools.createFileOutputFromBytes(cast f) else IoTools.createFileOutputFromText(cast f);
}
public static function update(path:String, binary:Bool = true):FileOutput {
if (!FileSystem.exists(path)) {
write(path).close();
}
var mode = if (binary) "rb+" else "r+";
var f = python.lib.Builtins.open(path, mode, -1, null, null, binary ? null : "");
return if (binary) IoTools.createFileOutputFromBytes(cast f) else IoTools.createFileOutputFromText(cast f);
}
public static function copy(srcPath:String, dstPath:String):Void {
return python.lib.Shutil.copy(srcPath, dstPath);
}
}

View File

@ -0,0 +1,120 @@
/*
* 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 sys.io;
import haxe.io.Bytes;
import haxe.io.Encoding;
import haxe.io.Input;
import python.io.IFileInput;
class FileInput extends Input {
var impl:IFileInput;
function new(impl:IFileInput) {
this.impl = impl;
}
override public function set_bigEndian(b:Bool) {
return impl.bigEndian = b;
}
public function seek(p:Int, pos:FileSeek):Void {
return impl.seek(p, pos);
}
public function tell():Int {
return impl.tell();
}
public function eof():Bool {
return impl.eof();
}
override public function readByte():Int {
return impl.readByte();
}
override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
return impl.readBytes(s, pos, len);
}
override public function close():Void {
impl.close();
}
override public function readAll(?bufsize:Int):Bytes {
return impl.readAll(bufsize);
}
override public function readFullBytes(s:Bytes, pos:Int, len:Int):Void {
impl.readFullBytes(s, pos, len);
}
override public function read(nbytes:Int):Bytes {
return impl.read(nbytes);
}
override public function readUntil(end:Int):String {
return impl.readUntil(end);
}
override public function readLine():String {
return impl.readLine();
}
override public function readFloat():Float {
return impl.readFloat();
}
override public function readDouble():Float {
return impl.readDouble();
}
override public function readInt8():Int {
return impl.readInt8();
}
override public function readInt16():Int {
return impl.readInt16();
}
override public function readUInt16():Int {
return impl.readUInt16();
}
override public function readInt24():Int {
return impl.readInt24();
}
override public function readUInt24():Int {
return impl.readUInt24();
}
override public function readInt32():Int {
return impl.readInt32();
}
override public function readString(len:Int, ?encoding:Encoding):String {
return impl.readString(len);
}
}

View File

@ -0,0 +1,117 @@
/*
* 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 sys.io;
import haxe.io.Bytes;
import haxe.io.Encoding;
import haxe.io.Input;
import haxe.io.Output;
import python.io.IFileOutput;
class FileOutput extends Output {
var impl:IFileOutput;
function new(impl:IFileOutput) {
this.impl = impl;
}
public function seek(p:Int, pos:FileSeek):Void {
return impl.seek(p, pos);
}
public function tell():Int {
return impl.tell();
}
override public function set_bigEndian(b:Bool) {
return impl.bigEndian = b;
}
override public function writeByte(c:Int):Void {
impl.writeByte(c);
}
override public function writeBytes(s:Bytes, pos:Int, len:Int):Int {
return impl.writeBytes(s, pos, len);
}
override public function flush():Void {
impl.flush();
}
override public function close():Void {
impl.close();
}
override public function write(s:Bytes):Void {
impl.write(s);
}
override public function writeFullBytes(s:Bytes, pos:Int, len:Int):Void {
impl.writeFullBytes(s, pos, len);
}
override public function writeFloat(x:Float):Void {
impl.writeFloat(x);
}
override public function writeDouble(x:Float):Void {
impl.writeDouble(x);
}
override public function writeInt8(x:Int):Void {
impl.writeInt8(x);
}
override public function writeInt16(x:Int):Void {
impl.writeInt16(x);
}
override public function writeUInt16(x:Int):Void {
impl.writeUInt16(x);
}
override public function writeInt24(x:Int):Void {
impl.writeInt24(x);
}
override public function writeUInt24(x:Int):Void {
impl.writeUInt24(x);
}
override public function writeInt32(x:Int):Void {
impl.writeInt32(x);
}
override public function prepare(nbytes:Int):Void {
impl.prepare(nbytes);
}
override public function writeInput(i:Input, ?bufsize:Int):Void {
impl.writeInput(i, bufsize);
}
override public function writeString(s:String, ?encoding:Encoding):Void {
impl.writeString(s);
}
}

View File

@ -0,0 +1,82 @@
/*
* 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 sys.io;
import python.io.IoTools;
import python.lib.io.BufferedReader;
import python.lib.io.BufferedWriter;
import python.lib.io.TextIOWrapper;
import python.lib.Subprocess;
import python.lib.subprocess.Popen;
class Process {
public var stdout(default, null):haxe.io.Input;
public var stderr(default, null):haxe.io.Input;
public var stdin(default, null):haxe.io.Output;
var p:Popen;
public function new(cmd:String, ?args:Array<String>, ?detached:Bool):Void {
if (detached)
throw "Detached process is not supported on this platform";
p = Popen.create(args == null ? cmd : [cmd].concat(args), {
shell: args == null,
stdin: Subprocess.PIPE,
stdout: Subprocess.PIPE,
stderr: Subprocess.PIPE
});
this.stdout = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stdout)));
this.stderr = IoTools.createFileInputFromText(new TextIOWrapper(new BufferedReader(p.stderr)));
this.stdin = IoTools.createFileOutputFromText(new TextIOWrapper(new BufferedWriter(p.stdin)));
}
public function getPid():Int {
return p.pid;
}
public function exitCode(block:Bool = true):Null<Int> {
if (block == false)
return p.poll();
return p.wait();
}
public function close():Void {
var ver = python.lib.Sys.version_info;
if (ver[0] > 3 || (ver[0] == 3 && ver[1] >= 3)) // >= 3.3
try {
p.terminate();
} catch (e:python.Exceptions.ProcessLookupError) {
// it has already terminated
}
else
try {
p.terminate();
} catch (e:python.Exceptions.OSError) {
// it has already terminated
}
}
public function kill():Void {
p.kill();
}
}