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 1
1
// TODO: we can move more os-specific bindings/interfaces from stdlib::{os, posix, nt} to here
2
2
3
- use std:: io ;
3
+ use std:: { io , str :: Utf8Error } ;
4
4
5
5
#[ cfg( windows) ]
6
6
pub fn errno ( ) -> io:: Error {
@@ -21,3 +21,14 @@ pub fn errno() -> io::Error {
21
21
pub fn errno ( ) -> io:: Error {
22
22
io:: Error :: last_os_error ( )
23
23
}
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(
378
378
#[ pyarg( named, name = "follow_symlinks" , default = "true" ) ] pub bool ,
379
379
) ;
380
380
381
- #[ cfg( unix) ]
382
- use platform:: bytes_as_osstr;
383
-
384
- #[ cfg( not( unix) ) ]
385
381
fn 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)
388
383
. map_err ( |_| vm. new_unicode_decode_error ( "can't decode path for utf-8" . to_owned ( ) ) )
389
384
}
390
385
Original file line number Diff line number Diff line change 1
- use crate :: { PyObjectRef , PyResult , VirtualMachine } ;
1
+ use crate :: { PyObjectRef , VirtualMachine } ;
2
2
use std:: os:: unix:: io:: RawFd ;
3
3
4
4
pub 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<()> {
12
12
Ok ( ( ) )
13
13
}
14
14
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
-
23
15
pub ( crate ) fn make_module ( vm : & VirtualMachine ) -> PyObjectRef {
24
16
let module = module:: make_module ( vm) ;
25
17
super :: os:: extend_module ( vm, & module) ;
You can’t perform that action at this time.
0 commit comments