From 1c98b9cc38d34647f1d6357919a0f4e1d5ebd4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 21 Nov 2019 03:29:16 +0100 Subject: [PATCH] Remove current directory from sys.path in python invocations (#8408) * Remove current directory from sys.path in python invocations --- plugins/django/django.plugin.zsh | 3 ++- plugins/jsontools/jsontools.plugin.zsh | 13 ++++++++----- plugins/salt/_salt | 2 +- plugins/urltools/urltools.plugin.zsh | 8 ++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/django/django.plugin.zsh b/plugins/django/django.plugin.zsh index 86558ff2e..c2d00c171 100644 --- a/plugins/django/django.plugin.zsh +++ b/plugins/django/django.plugin.zsh @@ -374,7 +374,8 @@ _managepy-commands() { _applist() { local line local -a apps - _call_program help-command "python -c \"import os.path as op, re, django.conf, sys;\\ + _call_program help-command "python -c \"import sys; del sys.path[0];\\ + import os.path as op, re, django.conf;\\ bn=op.basename(op.abspath(op.curdir));[sys\\ .stdout.write(str(re.sub(r'^%s\.(.*?)$' % bn, r'\1', i)) + '\n') for i in django.conf.settings.\\ diff --git a/plugins/jsontools/jsontools.plugin.zsh b/plugins/jsontools/jsontools.plugin.zsh index 20d5eb1c9..912c83509 100644 --- a/plugins/jsontools/jsontools.plugin.zsh +++ b/plugins/jsontools/jsontools.plugin.zsh @@ -11,9 +11,10 @@ if [[ $(whence node) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_METH alias urlencode_json='xargs -0 node -e "console.log(encodeURIComponent(process.argv[1]))"' alias urldecode_json='xargs -0 node -e "console.log(decodeURIComponent(process.argv[1]))"' elif [[ $(whence python) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_METHOD" = "xpython" ) ]]; then - alias pp_json='python -mjson.tool' + alias pp_json='python -c "import sys; del sys.path[0]; import runpy; runpy._run_module_as_main(\"json.tool\")"' alias is_json='python -c " -import json, sys; +import sys; del sys.path[0]; +import json; try: json.loads(sys.stdin.read()) except ValueError, e: @@ -22,11 +23,13 @@ else: print True sys.exit(0)"' alias urlencode_json='python -c " -import urllib, json, sys; +import sys; del sys.path[0]; +import urllib, json; print urllib.quote_plus(sys.stdin.read()) sys.exit(0)"' alias urldecode_json='python -c " -import urllib, json, sys; +import sys; del sys.path[0]; +import urllib, json; print urllib.unquote_plus(sys.stdin.read()) sys.exit(0)"' elif [[ $(whence ruby) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_METHOD" = "xruby" ) ]]; then @@ -36,4 +39,4 @@ elif [[ $(whence ruby) != "" && ( "x$JSONTOOLS_METHOD" = "x" || "x$JSONTOOLS_MET alias urldecode_json='ruby -e "require \"uri\"; puts URI.unescape(STDIN.read)"' fi -unset JSONTOOLS_METHOD \ No newline at end of file +unset JSONTOOLS_METHOD diff --git a/plugins/salt/_salt b/plugins/salt/_salt index 10b782af4..78d8611d2 100644 --- a/plugins/salt/_salt +++ b/plugins/salt/_salt @@ -271,7 +271,7 @@ _salt_comp(){ fi if _cache_invalid salt/salt_dir || ! _retrieve_cache salt/salt_dir; then - salt_dir="${$(python2 -c 'import salt; print(salt.__file__);')%__init__*}" + salt_dir="${$(python2 -c 'import sys; del sys.path[0]; import salt; print(salt.__file__);')%__init__*}" _store_cache salt/salt_dir salt_dir fi } diff --git a/plugins/urltools/urltools.plugin.zsh b/plugins/urltools/urltools.plugin.zsh index 47d9a34e4..b443e5027 100644 --- a/plugins/urltools/urltools.plugin.zsh +++ b/plugins/urltools/urltools.plugin.zsh @@ -12,11 +12,11 @@ if [[ $(whence node) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD alias urlencode='node -e "console.log(encodeURIComponent(process.argv[1]))"' alias urldecode='node -e "console.log(decodeURIComponent(process.argv[1]))"' elif [[ $(whence python3) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xpython" ) ]]; then - alias urlencode='python3 -c "import sys, urllib.parse as up; print(up.quote_plus(sys.argv[1]))"' - alias urldecode='python3 -c "import sys, urllib.parse as up; print(up.unquote_plus(sys.argv[1]))"' + alias urlencode='python3 -c "import sys; del sys.path[0]; import urllib.parse as up; print(up.quote_plus(sys.argv[1]))"' + alias urldecode='python3 -c "import sys; del sys.path[0]; import urllib.parse as up; print(up.unquote_plus(sys.argv[1]))"' elif [[ $(whence python2) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xpython" ) ]]; then - alias urlencode='python2 -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])"' - alias urldecode='python2 -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])"' + alias urlencode='python2 -c "import sys; del sys.path[0]; import urllib as ul; print ul.quote_plus(sys.argv[1])"' + alias urldecode='python2 -c "import sys; del sys.path[0]; import urllib as ul; print ul.unquote_plus(sys.argv[1])"' elif [[ $(whence xxd) != "" && ( "x$URLTOOLS_METHOD" = "x" || "x$URLTOOLS_METHOD" = "xshell" ) ]]; then function urlencode() {echo $@ | tr -d "\n" | xxd -plain | sed "s/\(..\)/%\1/g"} function urldecode() {printf $(echo -n $@ | sed 's/\\/\\\\/g;s/\(%\)\([0-9a-fA-F][0-9a-fA-F]\)/\\x\2/g')"\n"}