Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd4be55c

Browse files
naonusyouknowone
andauthored
Add command line parameter -P (#4611)
* Add command line parameter -P* Modify the value of safe_path to be set---------Co-authored-by: Jeong YunWon <jeong@youknowone.org>
1 parente2f7d5b commitd4be55c

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

‎Lib/test/test_support.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ def check_options(self, args, func, expected=None):
513513
self.assertEqual(proc.stdout.rstrip(),repr(expected))
514514
self.assertEqual(proc.returncode,0)
515515

516-
# TODO: RUSTPYTHON
517-
@unittest.expectedFailure
518516
deftest_args_from_interpreter_flags(self):
519517
# Test test.support.args_from_interpreter_flags()
520518
foroptsin (

‎extra_tests/snippets/stdlib_sys.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
importsys
2+
importos
3+
importsubprocess
24

35
fromtestutilsimportassert_raises
46

@@ -105,4 +107,23 @@ def recursive_call(n):
105107
sys.set_int_max_str_digits(1)
106108

107109
sys.set_int_max_str_digits(1000)
108-
assertsys.get_int_max_str_digits()==1000
110+
assertsys.get_int_max_str_digits()==1000
111+
112+
# Test the PYTHONSAFEPATH environment variable
113+
code="import sys; print(sys.flags.safe_path)"
114+
env=dict(os.environ)
115+
env.pop('PYTHONSAFEPATH',None)
116+
args= (sys.executable,'-P','-c',code)
117+
118+
proc=subprocess.run(
119+
args,stdout=subprocess.PIPE,
120+
universal_newlines=True,env=env)
121+
assertproc.stdout.rstrip()=='True',proc
122+
assertproc.returncode==0,proc
123+
124+
env['PYTHONSAFEPATH']='1'
125+
proc=subprocess.run(
126+
args,stdout=subprocess.PIPE,
127+
universal_newlines=True,env=env)
128+
assertproc.stdout.rstrip()=='True'
129+
assertproc.returncode==0,proc

‎src/settings.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> {
100100
.short("B")
101101
.help("don't write .pyc files on import"),
102102
)
103+
.arg(
104+
Arg::with_name("safe-path")
105+
.short("P")
106+
.help("don’t prepend a potentially unsafe path to sys.path"),
107+
)
103108
.arg(
104109
Arg::with_name("ignore-environment")
105110
.short("E")
@@ -237,6 +242,12 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) {
237242
};
238243
}
239244

245+
if matches.is_present("safe-path")
246+
||(!ignore_environment && env::var_os("PYTHONSAFEPATH").is_some())
247+
{
248+
settings.safe_path =true;
249+
}
250+
240251
settings.check_hash_based_pycs = matches
241252
.value_of("check-hash-based-pycs")
242253
.unwrap_or("default")

‎vm/src/stdlib/sys.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ mod sys {
754754
dev_mode: settings.dev_mode,
755755
utf8_mode: settings.utf8_mode,
756756
int_max_str_digits: settings.int_max_str_digits,
757-
safe_path:false,
757+
safe_path:settings.safe_path,
758758
warn_default_encoding: settings.warn_default_encodingasu8,
759759
}
760760
}

‎vm/src/vm/setting.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct Settings {
3737
/// -B
3838
pubdont_write_bytecode:bool,
3939

40+
/// -P
41+
pubsafe_path:bool,
42+
4043
/// -b
4144
pubbytes_warning:u64,
4245

@@ -108,6 +111,7 @@ impl Default for Settings {
108111
verbose:0,
109112
quiet:false,
110113
dont_write_bytecode:false,
114+
safe_path:false,
111115
bytes_warning:0,
112116
xopts:vec![],
113117
isolated:false,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp