diff --git a/os/metadata.txt b/os/metadata.txt index 36da8f4b..150da5d2 100644 --- a/os/metadata.txt +++ b/os/metadata.txt @@ -1,4 +1,4 @@ srctype = micropython-lib type = package -version = 0.0.7 +version = 0.0.8 author = Paul Sokolovsky diff --git a/os/os/__init__.py b/os/os/__init__.py index 7d326b79..3af7ca5f 100644 --- a/os/os/__init__.py +++ b/os/os/__init__.py @@ -159,3 +159,14 @@ def waitpid(pid, opts): r = waitpid_(pid, a, opts) check_error(r) return (r, a[0]) + + +def fsencode(s): + if type(s) is bytes: + return s + return bytes(s, "utf-8") + +def fsdecode(s): + if type(s) is str: + return s + return str(s, "utf-8") diff --git a/os/setup.py b/os/setup.py index e66ced62..2813a62f 100644 --- a/os/setup.py +++ b/os/setup.py @@ -6,7 +6,7 @@ from setuptools import setup setup(name='micropython-os', - version='0.0.7', + version='0.0.8', description='os module for MicroPython', long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.", url='https://github.com/micropython/micropython/issues/405', diff --git a/os/test_fsencode.py b/os/test_fsencode.py new file mode 100644 index 00000000..8254f835 --- /dev/null +++ b/os/test_fsencode.py @@ -0,0 +1,7 @@ +import os + +print(os.fsencode("abc")) +print(os.fsencode(b"abc")) + +print(os.fsdecode("abc")) +print(os.fsdecode(b"abc"))