blueloveTH 3 лет назад
Родитель
Сommit
e737c33b85

+ 2 - 1
plugins/flutter/CHANGELOG.md

@@ -1,6 +1,7 @@
-## 0.5.1+1
+## 0.5.1+2
 
 + Fix a bug of parsing large `list/dict/set`
++ Add `os.path.join`
 
 ## 0.5.0+7
 

+ 1 - 1
plugins/flutter/pubspec.yaml

@@ -1,6 +1,6 @@
 name: pocketpy
 description: A lightweight Python interpreter for game engines.
-version: 0.5.1+1
+version: 0.5.1+2
 homepage: https://pocketpy.dev
 repository: https://github.com/blueloveth/pocketpy
 

+ 13 - 3
plugins/flutter/src/pocketpy.h

@@ -2664,17 +2664,17 @@ class FileIO:
   def __init__(self, path, mode):
     assert type(path) is str
     assert type(mode) is str
-    assert mode in ['r', 'w']
+    assert mode in ['r', 'w', 'rt', 'wt']
     self.path = path
     self.mode = mode
     self.fp = jsonrpc('fopen', [path, mode])
 
   def read(self):
-    assert self.mode == 'r'
+    assert self.mode in ['r', 'rt']
     return jsonrpc('fread', [self.fp])
 
   def write(self, s):
-    assert self.mode == 'w'
+    assert self.mode in ['w', 'wt']
     assert type(s) is str
     jsonrpc('fwrite', [self.fp, s])
 
@@ -2812,6 +2812,16 @@ def __path4exists(path):
   return jsonrpc("os.path.exists", [path])
 path.exists = __path4exists
 del __path4exists
+
+def __path4join(*paths):
+  s = '/'.join(paths)
+  s = s.replace('\\', '/')
+  s = s.replace('//', '/')
+  s = s.replace('//', '/')
+  return s
+
+path.join = __path4join
+del __path4join
 )";
 
 const char* __RANDOM_CODE = R"(

+ 1 - 1
plugins/godot/godot-cpp

@@ -1 +1 @@
-Subproject commit 8d72bddf3e80119e0f095aea14cf669024a8bee0
+Subproject commit be3b15ee0aa6a3f56a83e130035c7eb82d753d42

+ 13 - 3
src/builtins.h

@@ -291,17 +291,17 @@ class FileIO:
   def __init__(self, path, mode):
     assert type(path) is str
     assert type(mode) is str
-    assert mode in ['r', 'w']
+    assert mode in ['r', 'w', 'rt', 'wt']
     self.path = path
     self.mode = mode
     self.fp = jsonrpc('fopen', [path, mode])
 
   def read(self):
-    assert self.mode == 'r'
+    assert self.mode in ['r', 'rt']
     return jsonrpc('fread', [self.fp])
 
   def write(self, s):
-    assert self.mode == 'w'
+    assert self.mode in ['w', 'wt']
     assert type(s) is str
     jsonrpc('fwrite', [self.fp, s])
 
@@ -439,6 +439,16 @@ def __path4exists(path):
   return jsonrpc("os.path.exists", [path])
 path.exists = __path4exists
 del __path4exists
+
+def __path4join(*paths):
+  s = '/'.join(paths)
+  s = s.replace('\\', '/')
+  s = s.replace('//', '/')
+  s = s.replace('//', '/')
+  return s
+
+path.join = __path4join
+del __path4join
 )";
 
 const char* __RANDOM_CODE = R"(

+ 12 - 0
tests/_os_path.py

@@ -0,0 +1,12 @@
+import os
+
+# test os.path.join
+
+f = os.path.join
+
+assert f('/', 'a') == '/a'
+assert f('/', 'a/', 'b/') == '/a/b/'
+assert f('c', 'd') == 'c/d'
+assert f('C:\\', 'a') == 'C:/a'
+assert f('C:\\', 'a\\', 'b\\') == 'C:/a/b/'
+assert f('c\\', 'd/') == 'c/d/'