22import logging
33import os
44
5- from pyscript import sync
5+ from pyscript import sync , ffi
66from fsspec .spec import AbstractFileSystem , AbstractBufferedFile
77import fsspec .utils
88
@@ -17,7 +17,6 @@ class PyscriptFileSystem(AbstractFileSystem):
1717 def __init__ (self , base_url = default_endpoint ):
1818 super ().__init__ ()
1919 self .base_url = base_url
20- self .session = sync .session
2120
2221 def _split_path (self , path ):
2322 key , * relpath = path .split ("/" , 1 )
@@ -34,22 +33,19 @@ def _call(self, path, method="GET", range=None, binary=False, data=0, json=0):
3433 outmode = "text"
3534 if range :
3635 headers ["Range" ] = f"bytes={ range [0 ]} -{ range [1 ]} "
37- try :
38- print (method , f"{ self .base_url } /{ path } " , headers , data , json , outmode )
39- out = self .session (
40- method , f"{ self .base_url } /{ path } " ,
41- #hearder=headers, data=data, json=json, outmode=outmode
42- )
43- print (out )
44- if isinstance (out , tuple ) and out [0 ] == "error" :
45- num , txt = out [1 :]
46- raise OSError (num , txt )
47- except OSError as e :
48- if e .errno == 404 :
49- raise FileNotFoundError (path )
50- if e .errno == 403 :
51- raise PermissionError
52- raise
36+ if data :
37+ data = memoryview (data )
38+ outmode = None
39+ out = sync .session (
40+ method , f"{ self .base_url } /{ path } " , ffi .to_js (data ),
41+ ffi .to_js (headers ), outmode
42+ )
43+ if isinstance (out , str ) and out == "ISawAnError" :
44+ raise OSError (0 , out )
45+ if out is not None and not isinstance (out , str ):
46+ # may need a different conversion
47+ out = bytes (out .to_py ())
48+ return out
5349
5450 def ls (self , path , detail = True , ** kwargs ):
5551 path = self ._strip_protocol (path )
0 commit comments