Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 746cb04

Browse filesBrowse files
authored
Merge pull request #4508 from marvinmednick/pathconf_names
Pathconf names
2 parents 2e27587 + 955347e commit 746cb04
Copy full SHA for 746cb04

File tree

2 files changed

+29
-2
lines changed
Filter options

2 files changed

+29
-2
lines changed

‎extra_tests/snippets/stdlib_os.py

Copy file name to clipboardExpand all lines: extra_tests/snippets/stdlib_os.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
507507

508508
for arg in [None, 1, 1.0, TabError]:
509509
assert_raises(TypeError, os.system, arg)
510+
511+
# Testing for os.pathconf_names
512+
if sys.platform.startswith('linux'):
513+
assert len(os.pathconf_names) > 0
514+
assert 'PC_NAME_MAX' in os.pathconf_names
515+
for option,index in os.pathconf_names.items():
516+
assert os.pathconf('/', index) == os.pathconf('/', option)

‎vm/src/stdlib/posix.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/posix.rs
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub mod module {
5151
fs, io,
5252
os::unix::{ffi as ffi_ext, io::RawFd},
5353
};
54-
use strum_macros::EnumString;
54+
use strum_macros::{EnumString, EnumVariantNames};
5555

5656
#[pyattr]
5757
use libc::{PRIO_PGRP, PRIO_PROCESS, PRIO_USER};
@@ -1681,7 +1681,7 @@ pub mod module {
16811681

16821682
// Copy from [nix::unistd::PathconfVar](https://docs.rs/nix/0.21.0/nix/unistd/enum.PathconfVar.html)
16831683
// Change enum name to fit python doc
1684-
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, EnumString)]
1684+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, EnumString, EnumVariantNames)]
16851685
#[repr(i32)]
16861686
#[allow(non_camel_case_types)]
16871687
pub enum PathconfVar {
@@ -1881,6 +1881,26 @@ pub mod module {
18811881
pathconf(PathOrFd::Fd(fd), name, vm)
18821882
}
18831883

1884+
// TODO: this is expected to be run on macOS as a unix, but somehow not.
1885+
#[cfg(target_os = "linux")]
1886+
#[pyattr]
1887+
fn pathconf_names(vm: &VirtualMachine) -> PyDictRef {
1888+
use std::str::FromStr;
1889+
use strum::VariantNames;
1890+
let pathname = vm.ctx.new_dict();
1891+
for variant in PathconfVar::VARIANTS {
1892+
// get the name of variant as a string to use as the dictionary key
1893+
let key = vm.ctx.new_str(variant.to_string());
1894+
// get the enum from the string and convert it to an integer for the dictionary value
1895+
let value: PyObjectRef = vm
1896+
.ctx
1897+
.new_int(PathconfVar::from_str(variant).unwrap() as u8)
1898+
.into();
1899+
pathname.set_item(&*key, value, vm).unwrap();
1900+
}
1901+
pathname
1902+
}
1903+
18841904
#[cfg(any(target_os = "linux", target_os = "macos"))]
18851905
#[derive(FromArgs)]
18861906
struct SendFileArgs {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.