Types.hx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. package python.lib;
  2. import python.lib.Builtin;
  3. import python.lib.io.IOBase;
  4. abstract Choice <A,B>(Dynamic) {
  5. @:from public static inline function fromA <A,B>(x:A):Choice<A,B> return cast x;
  6. @:from public static inline function fromB <A,B>(x:B):Choice<A,B> return cast x;
  7. }
  8. abstract KwArgs (Dict<String, Dynamic>)
  9. {
  10. inline function new (d:Dict<String, Dynamic>) this = d;
  11. @:to inline function toDict ():Dict<String, Dynamic>
  12. {
  13. return this;
  14. }
  15. @:from static inline function fromDict (d:Dict<String, Dynamic>):KwArgs
  16. {
  17. return new KwArgs(d);
  18. }
  19. public function get <V>(key:String, def:V):V
  20. {
  21. return this.get(key, def);
  22. }
  23. }
  24. abstract VarArgs (Array<Dynamic>)
  25. {
  26. inline function new (d:Array<Dynamic>) this = d;
  27. @:to inline function toArray ():Array<Dynamic>
  28. {
  29. return this;
  30. }
  31. @:from static inline function fromArray (d:Array<Dynamic>):VarArgs
  32. {
  33. return new VarArgs(d);
  34. }
  35. }
  36. extern class ByteArray implements ArrayAccess<Int> {
  37. public var length(get, null):Int;
  38. public inline function get_length ():Int {
  39. return Builtin.len(this);
  40. }
  41. public inline function get(i:Int):Int {
  42. return python.Syntax.arrayAccess(this, i);
  43. }
  44. public inline function set(i:Int,v:Int):Void {
  45. this.__setitem__(i,v);
  46. }
  47. public function __setitem__(i:Int,v:Int):Void;
  48. public function decode(encoding:String="utf-8", errors:String="strict"):String;
  49. }
  50. extern class Bytes extends ByteArray {
  51. //public function decode(encoding:String="utf-8", errors:String="strict"):String;
  52. static function __init__ ():Void
  53. {
  54. Syntax.importFromAs("builtins", "bytes", "python.lib.Bytes");
  55. }
  56. }
  57. typedef Variant<A,B> = Dynamic;
  58. typedef Variant3<A,B,C> = Dynamic;
  59. typedef Variant4<A,B,C,D> = Dynamic;
  60. abstract PyIterator <T>(NativeIterator<T>) to NativeIterator<T> to PyIterable<T> {
  61. public inline function new (p:NativeIterator<T>) this = p;
  62. @:to public static inline function toHaxeIterator <T>(p:NativeIterator<T>):HaxeIterator<T> return new HaxeIterator(p);
  63. @:to public static inline function toPyIterable <T>(p:NativeIterator<T>):PyIterable<T> return p;
  64. public function getNativeIterator <T>():NativeIterator<T> return this;
  65. }
  66. abstract PyIterable <T>(NativeIterable<T>) to NativeIterable<T> from NativeIterable<T> {
  67. @:to public static inline function toHaxeIterable <T>(p:NativeIterable<T>):HaxeIterable<T> return new HaxeIterable(p);
  68. //@:from public static inline function fromArray <T>(p:Array<T>):PyIterable<T> return cast p;
  69. public inline function iterator <T>() return IterHelper.iterableToIterator(this);
  70. public function getNativeIterable <T>():NativeIterable<T> return this;
  71. public function getNativeIterator <T>():NativeIterator<T> return this.__iter__();
  72. }
  73. class IterHelper {
  74. public static inline function iterableToIterator <T>(it:PyIterable<T>):Iterator<T>
  75. {
  76. return it.toHaxeIterable().iterator();
  77. }
  78. }
  79. typedef NativeIterator<T> = {
  80. function __next__ ():T;
  81. function __iter__ ():PyIterator<T>;
  82. }
  83. typedef NativeIterable<T> = {
  84. function __iter__():PyIterator<T>;
  85. }
  86. typedef List<T> = Array<T>;
  87. typedef Hashable = {
  88. public function __hash__():Int;
  89. }
  90. typedef Equal = {
  91. public function __eq__(other:Dynamic):Int;
  92. }
  93. typedef Comparable = {
  94. public function __cmp__(other:Dynamic):Int;
  95. }
  96. typedef FileObject = IOBase;
  97. extern class FileDescriptor {
  98. }
  99. //typedef DictKey<T> = {
  100. // function __hash__():Int;
  101. // function __eq__(other:Dynamic):Int;
  102. // function __cmp__(other:Dynamic):Int;
  103. //}
  104. //@:native("set")
  105. @:native("BaseException")
  106. extern class BaseException
  107. {
  108. public function new (msg:String):Void;
  109. }
  110. @:native("BufferError")
  111. extern class BufferError extends BaseException
  112. {
  113. }
  114. @:native("GeneratorExit")
  115. extern class GeneratorExit extends BaseException
  116. {
  117. }
  118. @:native("KeyboardInterrupt")
  119. extern class KeyboardInterrupt extends BaseException
  120. {
  121. }
  122. @:native("Exception")
  123. extern class Exception extends BaseException
  124. {
  125. }
  126. @:native("SyntaxError")
  127. extern class SyntaxError extends Exception
  128. {
  129. }
  130. @:native("StopIteration")
  131. extern class StopIteration extends Exception
  132. {
  133. public function new (?message:String);
  134. }
  135. @:native("RuntimeError")
  136. extern class RuntimeError extends Exception
  137. {
  138. }
  139. @:native("NotImplementedError")
  140. extern class NotImplementedError extends RuntimeError
  141. {
  142. }
  143. @:native("IndentationError")
  144. extern class IndentationError extends SyntaxError
  145. {
  146. }
  147. @:native("EnvironmentError")
  148. extern class EnvironmentError extends Exception
  149. {
  150. }
  151. @:native("OSError")
  152. extern class OSError extends EnvironmentError
  153. {
  154. }
  155. @:native("BlockingIOError")
  156. extern class BlockingIOError extends OSError
  157. {
  158. }
  159. @:native("ChildProcessError")
  160. extern class ChildProcessError extends OSError
  161. {
  162. }
  163. @:native("ConnectionError")
  164. extern class ConnectionError extends OSError
  165. {
  166. }
  167. @:native("BrokenPipeError")
  168. extern class BrokenPipeError extends ConnectionError
  169. {
  170. }
  171. @:native("ConnectionAbortedError")
  172. extern class ConnectionAbortedError extends ConnectionError
  173. {
  174. }
  175. @:native("ConnectionRefusedError")
  176. extern class ConnectionRefusedError extends ConnectionError
  177. {
  178. }
  179. @:native("ConnectionResetError")
  180. extern class ConnectionResetError extends ConnectionError
  181. {
  182. }
  183. @:native("FileExistsError")
  184. extern class FileExistsError extends OSError
  185. {
  186. }
  187. @:native("FileNotFoundError")
  188. extern class FileNotFoundError extends OSError
  189. {
  190. }
  191. @:native("InterruptedError")
  192. extern class InterruptedError extends OSError
  193. {
  194. }
  195. @:native("IsADirectoryError")
  196. extern class IsADirectoryError extends OSError
  197. {
  198. }
  199. @:native("NotADirectoryError")
  200. extern class NotADirectoryError extends OSError
  201. {
  202. }
  203. @:native("PermissionError")
  204. extern class PermissionError extends OSError
  205. {
  206. }
  207. @:native("ProcessLookupError")
  208. extern class ProcessLookupError extends OSError
  209. {
  210. }
  211. @:native("TimeoutError")
  212. extern class TimeoutError extends OSError
  213. {
  214. }
  215. @:native("NameError")
  216. extern class NameError extends Exception
  217. {
  218. }
  219. @:native("UnboundLocalError")
  220. extern class UnboundLocalError extends NameError
  221. {
  222. }
  223. @:native("MemoryError")
  224. extern class MemoryError extends Exception
  225. {
  226. }
  227. @:native("AssertionError")
  228. extern class AssertionError extends Exception
  229. {
  230. }
  231. @:native("AttributeError")
  232. extern class AttributeError extends Exception
  233. {
  234. }
  235. @:native("EOFError")
  236. extern class EOFError extends Exception
  237. {
  238. }
  239. @:native("ArithmeticError")
  240. extern class ArithmeticError extends Exception
  241. {
  242. }
  243. @:native("FloatingPointError")
  244. extern class FloatingPointError extends ArithmeticError
  245. {
  246. }
  247. @:native("OverflowError")
  248. extern class OverflowError extends ArithmeticError
  249. {
  250. }
  251. @:native("ZeroDivisionError")
  252. extern class ZeroDivisionError extends ArithmeticError
  253. {
  254. }
  255. @:native("ImportError")
  256. extern class ImportError extends Exception
  257. {
  258. }
  259. @:native("LookupError")
  260. extern class LookupError extends Exception
  261. {
  262. }
  263. @:native("IndexError")
  264. extern class IndexError extends LookupError
  265. {
  266. }
  267. @:native("KeyError")
  268. extern class KeyError extends LookupError
  269. {
  270. }
  271. @:native("IOError")
  272. extern class IOError extends EnvironmentError
  273. {
  274. }
  275. @:native("VMSError")
  276. extern class VMSError extends OSError
  277. {
  278. }
  279. @:native("WindowsError")
  280. extern class WindowsError extends OSError
  281. {
  282. }
  283. @:native("ValueError")
  284. extern class ValueError extends Exception
  285. {
  286. }
  287. @:native("UnicodeError")
  288. extern class UnicodeError extends ValueError
  289. {
  290. }
  291. @:native("UnicodeDecodeError")
  292. extern class UnicodeDecodeError extends UnicodeError
  293. {
  294. }
  295. @:native("UnicodeEncodeError")
  296. extern class UnicodeEncodeError extends UnicodeError
  297. {
  298. }
  299. @:native("UnicodeTranslateError")
  300. extern class UnicodeTranslateError extends UnicodeError
  301. {
  302. }
  303. @:native("Warning")
  304. extern class Warning extends Exception
  305. {
  306. }
  307. @:native("DeprecationWarning")
  308. extern class DeprecationWarning extends Warning
  309. {
  310. }
  311. @:native("PendingDeprecationWarning")
  312. extern class PendingDeprecationWarning extends Warning
  313. {
  314. }
  315. @:native("RuntimeWarning")
  316. extern class RuntimeWarning extends Warning
  317. {
  318. }
  319. @:native("SyntaxWarning")
  320. extern class SyntaxWarning extends Warning
  321. {
  322. }
  323. @:native("UserWarning")
  324. extern class UserWarning extends Warning
  325. {
  326. }
  327. @:native("FutureWarning")
  328. extern class FutureWarning extends Warning
  329. {
  330. }
  331. @:native("ImportWarning")
  332. extern class ImportWarning extends Warning
  333. {
  334. }
  335. @:native("UnicodeWarning")
  336. extern class UnicodeWarning extends Warning
  337. {
  338. }
  339. @:native("BytesWarning")
  340. extern class BytesWarning extends Warning
  341. {
  342. }
  343. @:native("ResourceWarning")
  344. extern class ResourceWarning extends Warning
  345. {
  346. }
  347. extern class TB {}
  348. extern class Frame {}