blueloveTH před 2 roky
rodič
revize
a0770d4191
4 změnil soubory, kde provedl 51 přidání a 1 odebrání
  1. 13 0
      docs/modules/base64.md
  2. 26 0
      docs/modules/requests.md
  3. 10 1
      src/pocketpy.h
  4. 2 0
      tests/70_base64.py

+ 13 - 0
docs/modules/base64.md

@@ -0,0 +1,13 @@
+---
+icon: package
+label: base64
+---
+
+### `base64.b64encode(b: bytes) -> bytes`
+
+Encode bytes-like object `b` using the standard Base64 alphabet.
+
+### `base64.b64decode(b: bytes) -> bytes`
+
+Decode Base64 encoded bytes-like object `b`.
+

+ 26 - 0
docs/modules/requests.md

@@ -0,0 +1,26 @@
+---
+icon: package
+label: requests
+---
+
+!!!
+This module is experimental. To enable it, download `httplib.h` from https://github.com/yhirose/cpp-httplib and place it in the same directory as `pocketpy.h`.
+
+SSL is not supported.
+!!!
+
+### `requests.get(url, headers=None) -> Response`
+
+Send a GET request to `url` and return a `Response` object.
+
+### `requests.post(url, data=None, headers=None) -> Response`
+
+Send a POST request to `url` and return a `Response` object.
+
+### `requests.put(url, data=None, headers=None) -> Response`
+
+Send a PUT request to `url` and return a `Response` object.
+
+### `requests.delete(url, headers=None) -> Response`
+
+Send a DELETE request to `url` and return a `Response` object.

+ 10 - 1
src/pocketpy.h

@@ -595,7 +595,16 @@ inline void init_builtins(VM* _vm) {
     _vm->bind_method<0>("ellipsis", "__repr__", CPP_LAMBDA(VAR("Ellipsis")));
 
     /************ bytes ************/
-    _vm->bind_static_method<1>("bytes", "__new__", CPP_NOT_IMPLEMENTED());
+    _vm->bind_static_method<1>("bytes", "__new__", [](VM* vm, ArgsView args){
+        List& list = CAST(List&, args[0]);
+        std::vector<char> buffer(list.size());
+        for(int i=0; i<list.size(); i++){
+            i64 b = CAST(i64, list[i]);
+            if(b<0 || b>255) vm->ValueError("byte must be in range[0, 256)");
+            buffer[i] = (char)b;
+        }
+        return VAR(Bytes(std::move(buffer)));
+    });
 
     _vm->bind_method<1>("bytes", "__getitem__", [](VM* vm, ArgsView args) {
         const Bytes& self = CAST(Bytes&, args[0]);

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 2 - 0
tests/70_base64.py


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů