Pārlūkot izejas kodu

rename ByteArray to Bytearray, remove Builtin.bytearray and add constructor to Bytearray

frabbit 10 gadi atpakaļ
vecāks
revīzija
1d6eac4890

+ 6 - 6
std/haxe/io/Bytes.hx

@@ -207,8 +207,8 @@ class Bytes {
 		return length - other.length;
 		return length - other.length;
 		#end
 		#end
 	}
 	}
-	
-	
+
+
 	/**
 	/**
 		Returns the IEEE double precision value at given position (in low endian encoding).
 		Returns the IEEE double precision value at given position (in low endian encoding).
 		Result is unspecified if reading outside of the bounds
 		Result is unspecified if reading outside of the bounds
@@ -291,8 +291,8 @@ class Bytes {
 		setI32(pos, FPHelper.floatToI32(v));
 		setI32(pos, FPHelper.floatToI32(v));
 		#end
 		#end
 	}
 	}
-	
-	/** 
+
+	/**
 		Returns the 32 bit integer at given position (in low endian encoding).
 		Returns the 32 bit integer at given position (in low endian encoding).
 	**/
 	**/
 	public inline function getI32( pos : Int ) : Int {
 	public inline function getI32( pos : Int ) : Int {
@@ -433,7 +433,7 @@ class Bytes {
 		#elseif java
 		#elseif java
 		return new Bytes(length, new java.NativeArray(length));
 		return new Bytes(length, new java.NativeArray(length));
 		#elseif python
 		#elseif python
-		return new Bytes(length, python.lib.Builtin.bytearray(length));
+		return new Bytes(length, new python.lib.Bytearray(length));
 		#else
 		#else
 		var a = new Array();
 		var a = new Array();
 		for( i in 0...length )
 		for( i in 0...length )
@@ -468,7 +468,7 @@ class Bytes {
 		catch (e:Dynamic) throw e;
 		catch (e:Dynamic) throw e;
 
 
 		#elseif python
 		#elseif python
-			var b:BytesData = python.lib.Builtin.bytearray(s, "UTF-8");
+			var b:BytesData = new python.lib.Bytearray(s, "UTF-8");
 			return new Bytes(b.length, b);
 			return new Bytes(b.length, b);
 
 
 		#else
 		#else

+ 3 - 3
std/haxe/io/BytesBuffer.hx

@@ -136,7 +136,7 @@ class BytesBuffer {
 		add(b.getBytes());
 		add(b.getBytes());
 		#end
 		#end
 	}
 	}
-	
+
 	public inline function addDouble( v : Float ) {
 	public inline function addDouble( v : Float ) {
 		#if neko
 		#if neko
 		untyped StringBuf.__add(b, Output._double_bytes(v, false));
 		untyped StringBuf.__add(b, Output._double_bytes(v, false));
@@ -148,7 +148,7 @@ class BytesBuffer {
 		add(b.getBytes());
 		add(b.getBytes());
 		#end
 		#end
 	}
 	}
-	
+
 	public inline function addBytes( src : Bytes, pos : Int, len : Int ) {
 	public inline function addBytes( src : Bytes, pos : Int, len : Int ) {
 		#if !neko
 		#if !neko
 		if( pos < 0 || len < 0 || pos + len > src.length ) throw Error.OutsideBounds;
 		if( pos < 0 || len < 0 || pos + len > src.length ) throw Error.OutsideBounds;
@@ -196,7 +196,7 @@ class BytesBuffer {
 		var buf = b.toByteArray();
 		var buf = b.toByteArray();
 		var bytes = new Bytes(buf.length, buf);
 		var bytes = new Bytes(buf.length, buf);
 		#elseif python
 		#elseif python
-		var buf = python.lib.Builtin.bytearray(b);
+		var buf = new python.lib.Bytearray(b);
 		var bytes = new Bytes(buf.length, buf);
 		var bytes = new Bytes(buf.length, buf);
 		#elseif js
 		#elseif js
 		var bytes = new Bytes(new js.html.Uint8Array(b).buffer);
 		var bytes = new Bytes(new js.html.Uint8Array(b).buffer);

+ 1 - 1
std/haxe/io/BytesData.hx

@@ -35,7 +35,7 @@ package haxe.io;
 #elseif cs
 #elseif cs
 	typedef BytesData = cs.NativeArray<cs.StdTypes.UInt8>;
 	typedef BytesData = cs.NativeArray<cs.StdTypes.UInt8>;
 #elseif python
 #elseif python
-	typedef BytesData = python.lib.ByteArray;
+	typedef BytesData = python.lib.Bytearray;
 #elseif js
 #elseif js
 	typedef BytesData = js.html.ArrayBuffer;
 	typedef BytesData = js.html.ArrayBuffer;
 #else
 #else

+ 2 - 2
std/python/io/NativeBytesInput.hx

@@ -7,7 +7,7 @@ import haxe.io.Input;
 import python.io.IInput;
 import python.io.IInput;
 import python.io.IoTools;
 import python.io.IoTools;
 import python.lib.Builtin;
 import python.lib.Builtin;
-import python.lib.ByteArray;
+import python.lib.Bytearray;
 import python.lib.io.RawIOBase;
 import python.lib.io.RawIOBase;
 import python.lib.io.IOBase.SeekSet;
 import python.lib.io.IOBase.SeekSet;
 
 
@@ -36,7 +36,7 @@ class NativeBytesInput extends NativeInput<RawIOBase> implements IInput {
 		return IoTools.seekInBinaryMode(stream, p, pos);
 		return IoTools.seekInBinaryMode(stream, p, pos);
 	}
 	}
 
 
-	override function readinto (b:ByteArray):Int {
+	override function readinto (b:Bytearray):Int {
 		return stream.readinto(b);
 		return stream.readinto(b);
 	}
 	}
 
 

+ 2 - 1
std/python/io/NativeBytesOutput.hx

@@ -4,6 +4,7 @@ package python.io;
 import haxe.io.Output;
 import haxe.io.Output;
 
 
 import python.lib.Builtin;
 import python.lib.Builtin;
+import python.lib.Bytearray;
 import python.lib.io.IOBase;
 import python.lib.io.IOBase;
 import python.lib.io.RawIOBase;
 import python.lib.io.RawIOBase;
 
 
@@ -25,6 +26,6 @@ class NativeBytesOutput extends NativeOutput<RawIOBase>{
 
 
 	override public function writeByte(c:Int):Void
 	override public function writeByte(c:Int):Void
 	{
 	{
-		stream.write(Builtin.bytearray([c]));
+		stream.write(new Bytearray([c]));
 	}
 	}
 }
 }

+ 3 - 3
std/python/io/NativeInput.hx

@@ -4,7 +4,7 @@ package python.io;
 import haxe.io.Eof;
 import haxe.io.Eof;
 import haxe.io.Input;
 import haxe.io.Input;
 import python.lib.Builtin;
 import python.lib.Builtin;
-import python.lib.ByteArray;
+import python.lib.Bytearray;
 import python.lib.io.IOBase;
 import python.lib.io.IOBase;
 import python.lib.io.RawIOBase;
 import python.lib.io.RawIOBase;
 
 
@@ -45,7 +45,7 @@ class NativeInput<T:IOBase> extends Input{
 		return wasEof;
 		return wasEof;
 	}
 	}
 
 
-	function readinto (b:ByteArray):Int {
+	function readinto (b:Bytearray):Int {
 		throw "abstract method, should be overriden";
 		throw "abstract method, should be overriden";
 	}
 	}
 
 
@@ -55,7 +55,7 @@ class NativeInput<T:IOBase> extends Input{
 			throw haxe.io.Error.OutsideBounds;
 			throw haxe.io.Error.OutsideBounds;
 
 
 		stream.seek(pos, python.lib.io.IOBase.SeekSet.SeekCur);
 		stream.seek(pos, python.lib.io.IOBase.SeekSet.SeekCur);
-		var ba = Builtin.bytearray(len);
+		var ba = new Bytearray(len);
 		var ret = readinto(ba);
 		var ret = readinto(ba);
 		s.blit(pos, haxe.io.Bytes.ofData(ba) ,0,len);
 		s.blit(pos, haxe.io.Bytes.ofData(ba) ,0,len);
 		if (ret == 0)
 		if (ret == 0)

+ 2 - 2
std/python/io/NativeTextInput.hx

@@ -8,7 +8,7 @@ import python.io.IInput;
 import python.io.IoTools;
 import python.io.IoTools;
 import python.io.NativeInput;
 import python.io.NativeInput;
 import python.lib.Builtin;
 import python.lib.Builtin;
-import python.lib.ByteArray;
+import python.lib.Bytearray;
 import python.lib.io.RawIOBase;
 import python.lib.io.RawIOBase;
 import python.lib.io.IOBase.SeekSet;
 import python.lib.io.IOBase.SeekSet;
 import python.lib.io.TextIOBase;
 import python.lib.io.TextIOBase;
@@ -35,7 +35,7 @@ class NativeTextInput extends NativeInput<TextIOBase> implements IInput {
 		IoTools.seekInTextMode(stream, tell, p, pos);
 		IoTools.seekInTextMode(stream, tell, p, pos);
 	}
 	}
 
 
-	override function readinto (b:ByteArray):Int {
+	override function readinto (b:Bytearray):Int {
 		return stream.buffer.readinto(b);
 		return stream.buffer.readinto(b);
 	}
 	}
 
 

+ 3 - 1
std/python/lib/Builtin.hx

@@ -37,7 +37,7 @@ extern class Builtin {
 	@:overload(function (f:Dict<Dynamic, Dynamic>):Int {})
 	@:overload(function (f:Dict<Dynamic, Dynamic>):Int {})
 	@:overload(function (f:Bytes):Int {})
 	@:overload(function (f:Bytes):Int {})
 	@:overload(function (f:DictView<Dynamic>):Int {})
 	@:overload(function (f:DictView<Dynamic>):Int {})
-	@:overload(function (f:ByteArray):Int {})
+	@:overload(function (f:Bytearray):Int {})
 	@:overload(function (f:Tuple<Dynamic>):Int {})
 	@:overload(function (f:Tuple<Dynamic>):Int {})
 	public static function len(x:String):Int;
 	public static function len(x:String):Int;
 
 
@@ -80,10 +80,12 @@ extern class Builtin {
 	//public static function range():Void;
 	//public static function range():Void;
 
 
 	public static function type():Void;
 	public static function type():Void;
+	/*
 	@:overload(function (it:Array<Int>):python.lib.ByteArray {})
 	@:overload(function (it:Array<Int>):python.lib.ByteArray {})
 	@:overload(function (it:NativeIterable<Int>):python.lib.ByteArray {})
 	@:overload(function (it:NativeIterable<Int>):python.lib.ByteArray {})
 	@:overload(function (size:Int):python.lib.ByteArray {})
 	@:overload(function (size:Int):python.lib.ByteArray {})
 	public static function bytearray(source:String,encoding:String,?errors:Dynamic):python.lib.ByteArray;
 	public static function bytearray(source:String,encoding:String,?errors:Dynamic):python.lib.ByteArray;
+	*/
 	public static function float(x:Dynamic):Float;
 	public static function float(x:Dynamic):Float;
 
 
 	@:overload(function <T>(f:Array<T>):Array<T> {})
 	@:overload(function <T>(f:Array<T>):Array<T> {})

+ 8 - 1
std/python/lib/ByteArray.hx → std/python/lib/Bytearray.hx

@@ -4,8 +4,15 @@ import python.lib.Builtin;
 import python.Syntax;
 import python.Syntax;
 
 
 @:pythonImport("builtins", "bytearray")
 @:pythonImport("builtins", "bytearray")
-extern class ByteArray implements ArrayAccess<Int> {
+extern class Bytearray implements ArrayAccess<Int> {
+
 	public var length(get, null):Int;
 	public var length(get, null):Int;
+
+	@:overload(function (it:Array<Int>):Void {})
+	@:overload(function (it:NativeIterable<Int>):Void {})
+	@:overload(function (size:Int):Void {})
+	public function new (source:String,encoding:String,?errors:Dynamic):Void;
+
 	public inline function get_length ():Int {
 	public inline function get_length ():Int {
 		return Builtin.len(this);
 		return Builtin.len(this);
 	}
 	}

+ 2 - 2
std/python/lib/Bytes.hx

@@ -1,10 +1,10 @@
 
 
 package python.lib;
 package python.lib;
 
 
-import python.lib.ByteArray;
+import python.lib.Bytearray;
 
 
 @:pythonImport("builtins", "bytes")
 @:pythonImport("builtins", "bytes")
-extern class Bytes extends ByteArray {
+extern class Bytes extends Bytearray {
 
 
 	//public function decode(encoding:String="utf-8", errors:String="strict"):String;
 	//public function decode(encoding:String="utf-8", errors:String="strict"):String;
 
 

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

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

+ 2 - 2
std/python/lib/io/RawIOBase.hx

@@ -8,6 +8,6 @@ extern class RawIOBase extends IOBase{
 
 
 	public function readall():Bytes;
 	public function readall():Bytes;
 	public function read(n:Int=-1):Null<Bytes>;
 	public function read(n:Int=-1):Null<Bytes>;
-	public function write(b:ByteArray):Null<Int>;
-	public function readinto(b:ByteArray):Null<Int>;
+	public function write(b:Bytearray):Null<Int>;
+	public function readinto(b:Bytearray):Null<Int>;
 }
 }