File tree Expand file tree Collapse file tree 3 files changed +14
-16
lines changed
Expand file tree Collapse file tree 3 files changed +14
-16
lines changed Original file line number Diff line number Diff line change 11// TODO: we can move more os-specific bindings/interfaces from stdlib::{os, posix, nt} to here
22
3- use std:: io ;
3+ use std:: { io , str :: Utf8Error } ;
44
55#[ cfg( windows) ]
66pub fn errno ( ) -> io:: Error {
@@ -21,3 +21,14 @@ pub fn errno() -> io::Error {
2121pub fn errno ( ) -> io:: Error {
2222 io:: Error :: last_os_error ( )
2323}
24+
25+ #[ cfg( unix) ]
26+ pub fn bytes_as_osstr ( b : & [ u8 ] ) -> Result < & std:: ffi:: OsStr , Utf8Error > {
27+ use std:: os:: unix:: ffi:: OsStrExt ;
28+ Ok ( std:: ffi:: OsStr :: from_bytes ( b) )
29+ }
30+
31+ #[ cfg( not( unix) ) ]
32+ pub fn bytes_as_osstr ( b : & [ u8 ] ) -> Result < & std:: ffi:: OsStr , Utf8Error > {
33+ Ok ( std:: str:: from_utf8 ( b) ?. as_ref ( ) )
34+ }
Original file line number Diff line number Diff line change @@ -378,13 +378,8 @@ pub(super) struct FollowSymlinks(
378378 #[ pyarg( named, name = "follow_symlinks" , default = "true" ) ] pub bool ,
379379) ;
380380
381- #[ cfg( unix) ]
382- use platform:: bytes_as_osstr;
383-
384- #[ cfg( not( unix) ) ]
385381fn bytes_as_osstr < ' a > ( b : & ' a [ u8 ] , vm : & VirtualMachine ) -> PyResult < & ' a ffi:: OsStr > {
386- std:: str:: from_utf8 ( b)
387- . map ( |s| s. as_ref ( ) )
382+ rustpython_common:: os:: bytes_as_osstr ( b)
388383 . map_err ( |_| vm. new_unicode_decode_error ( "can't decode path for utf-8" . to_owned ( ) ) )
389384}
390385
Original file line number Diff line number Diff line change 1- use crate :: { PyObjectRef , PyResult , VirtualMachine } ;
1+ use crate :: { PyObjectRef , VirtualMachine } ;
22use std:: os:: unix:: io:: RawFd ;
33
44pub fn raw_set_inheritable ( fd : RawFd , inheritable : bool ) -> nix:: Result < ( ) > {
@@ -12,14 +12,6 @@ pub fn raw_set_inheritable(fd: RawFd, inheritable: bool) -> nix::Result<()> {
1212 Ok ( ( ) )
1313}
1414
15- pub ( super ) fn bytes_as_osstr < ' a > (
16- b : & ' a [ u8 ] ,
17- _vm : & VirtualMachine ,
18- ) -> PyResult < & ' a std:: ffi:: OsStr > {
19- use std:: os:: unix:: ffi:: OsStrExt ;
20- Ok ( std:: ffi:: OsStr :: from_bytes ( b) )
21- }
22-
2315pub ( crate ) fn make_module ( vm : & VirtualMachine ) -> PyObjectRef {
2416 let module = module:: make_module ( vm) ;
2517 super :: os:: extend_module ( vm, & module) ;
You can’t perform that action at this time.
0 commit comments