Browse Source

cleanup codecs module

frabbit 10 years ago
parent
commit
c5be51f212

+ 2 - 4
std/python/lib/Codecs.hx

@@ -1,13 +1,11 @@
 package python.lib;
 
 import python.lib.Bytes;
-import python.lib.codecs.StreamReaderWriterText;
+import python.lib.codecs.StreamReaderWriter;
 
 @:pythonImport("codecs")
 extern class Codecs {
-
-	static function open(filename:String, mode:String, ?encoding:String, ?errors:String, ?buffering:Bool):StreamReaderWriterText;
+	static function open(filename:String, mode:String, ?encoding:String, ?errors:String, ?buffering:Bool):StreamReaderWriter;
 	static function encode(obj:String, ?encoding:String = "utf-8", errors:String = "strict"):Bytes;
 	static function decode(obj:Bytes, ?encoding:String = "utf-8", errors:String = "strict"):String;
-
 }

+ 7 - 1
std/python/lib/codecs/Codec.hx

@@ -3,7 +3,13 @@ package python.lib.codecs;
 import python.lib.Bytes;
 import python.lib.Tuple.Tup2;
 
-extern interface Codec {
+@:pythonImport("codecs", "Codec")
+extern class Codec implements ICodec {
+	public function encode(input:Dynamic, ?errors:String = "strict"):Tup2<String, Int>;
+	public function decode(input:Dynamic, ?errors:String = "strict"):Tup2<Bytes, Int>;
+}
+
+@:remove extern interface ICodec {
 	public function encode(input:Dynamic, ?errors:String = "strict"):Tup2<String, Int>;
 	public function decode(input:Dynamic, ?errors:String = "strict"):Tup2<Bytes, Int>;
 }

+ 8 - 1
std/python/lib/codecs/StreamReader.hx

@@ -2,10 +2,17 @@ package python.lib.codecs;
 
 import python.lib.codecs.Codec;
 
-extern interface StreamReader extends Codec {
+@:pythonImport("codecs", "StreamReader")
+extern class StreamReader extends Codec implements IStreamReader {
 	public function read(?size:Int, ?chars:Int, ?firstline:Bool):String;
 	public function readline(?size:Int, ?keepsend:Bool = false):String;
 	public function readlines(?sizehint:Int, ?keepsend:Bool = false):Array<String>;
 	public function reset():Void;
+}
 
+extern interface IStreamReader extends ICodec {
+	public function read(?size:Int, ?chars:Int, ?firstline:Bool):String;
+	public function readline(?size:Int, ?keepsend:Bool = false):String;
+	public function readlines(?sizehint:Int, ?keepsend:Bool = false):Array<String>;
+	public function reset():Void;
 }

+ 14 - 0
std/python/lib/codecs/StreamReaderWriter.hx

@@ -0,0 +1,14 @@
+package python.lib.codecs;
+
+import python.lib.codecs.Codec;
+import python.lib.codecs.StreamReader;
+import python.lib.codecs.StreamWriter;
+
+@:pythonImport("codecs", "StreamReaderWriter")
+extern class StreamReaderWriter extends StreamReader implements IStreamWriter {
+	public function write(object:Dynamic):Void;
+	public function writelines(list:Array<String>):Void;
+
+}
+
+@:remove extern interface IStreamReaderWriter extends IStreamReader extends IStreamWriter {}

+ 0 - 21
std/python/lib/codecs/StreamReaderWriterText.hx

@@ -1,21 +0,0 @@
-package python.lib.codecs;
-
-import python.lib.Bytes;
-import python.lib.Tuple.Tup2;
-import python.lib.codecs.StreamReader;
-import python.lib.codecs.StreamWriter;
-
-extern class StreamReaderWriterText implements StreamReader implements StreamWriter  {
-	public function read(?size:Int, ?chars:Int, ?firstline:Bool):String;
-	public function readline(?size:Int, ?keepsend:Bool = false):String;
-	public function readlines(?sizehint:Int, ?keepsend:Bool = false):Array<String>;
-	public function reset():Void;
-
-	public function write(object:Dynamic):Void;
-	public function writelines(list:Array<String>):Void;
-
-	public function close():Void;
-
-	public function encode(input:Dynamic, ?errors:String = "strict"):Tup2<String, Int>;
-	public function decode(input:Dynamic, ?errors:String = "strict"):Tup2<Bytes, Int>;
-}

+ 9 - 1
std/python/lib/codecs/StreamWriter.hx

@@ -2,7 +2,15 @@ package python.lib.codecs;
 
 import python.lib.codecs.Codec;
 
-extern interface StreamWriter extends Codec {
+@:pythonImport("codecs", "StreamWriter")
+extern class StreamWriter extends Codec implements ICodec {
+	public function write(object:Dynamic):Void;
+	public function writelines(list:Array<String>):Void;
+	public function reset():Void;
+}
+
+
+extern interface IStreamWriter extends ICodec {
 	public function write(object:Dynamic):Void;
 	public function writelines(list:Array<String>):Void;
 	public function reset():Void;