WIP mediaWikiSystem

This commit is contained in:
2021-08-01 18:27:58 -06:00
parent 2623b5d543
commit f443ca0867
12 changed files with 96 additions and 12 deletions

View File

@@ -5,21 +5,36 @@ import python.Dict;
import python.KwArgs;
import requests_externs.Response;
typedef NativeRequestKwArgs = {
?headers:Dict<String, String>
}
typedef RequestKwArgs = {
?headers:Map<String, String>
}
@:pythonImport("requests")
extern class NativeRequests {
public static function get(url:String, params:Dict<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):Response;
public static function get(url:String, params:Dict<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):NativeResponse;
}
class Requests {
public static function get(url:String, params:Map<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):Response {
public static function get(url:String, params:Map<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):NativeResponse {
return NativeRequests.get(url, mapToDict(params), kwArgs);
}
static function mapToDict(?map:Map<String,String>) {
if (map == null) return null;
var dict = new Dict<String, String>();
for (param => value in params) {
dict.set(param, value);
for (key => value in map) {
dict.set(key, value);
}
return NativeRequests.get(url, dict, kwArgs);
return dict;
}
static function kwArgsToNativeKwArgs(kwArgs:RequestKwArgs) {
return {
headers: mapToDict(kwArgs.headers)
};
}
}

View File

@@ -1,4 +1,6 @@
package requests_externs;
@:pythonImport("requests.Response")
extern class Response {}
extern class NativeResponse {}
typedef Response = {};