Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
61822667
Kaydet (Commit)
61822667
authored
Eki 28, 2012
tarafından
Andrew Svetlov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #14616: Document pipes.quote and mention this one in subprocess docs.
Patch by Chris Rebert.
üst
0685e146
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
pipes.rst
Doc/library/pipes.rst
+37
-2
subprocess.rst
Doc/library/subprocess.rst
+4
-0
No files found.
Doc/library/pipes.rst
Dosyayı görüntüle @
61822667
...
...
@@ -16,8 +16,6 @@ The :mod:`pipes` module defines a class to abstract the concept of a *pipeline*
Because the module uses :program:`/bin/sh` command lines, a POSIX or compatible
shell for :func:`os.system` and :func:`os.popen` is required.
The :mod:`pipes` module defines the following class:
.. class:: Template()
...
...
@@ -35,6 +33,43 @@ Example::
'HELLO WORLD'
.. function:: quote(s)
.. deprecated:: 1.6
Prior to Python 2.7, this function was not publicly documented. It is
finally exposed publicly in Python 3.3 as the
:func:`quote <shlex.quote>` function in the :mod:`shlex` module.
Return a shell-escaped version of the string *s*. The returned value is a
string that can safely be used as one token in a shell command line, for
cases where you cannot use a list.
This idiom would be unsafe::
>>> filename = 'somefile; rm -rf ~'
>>> command = 'ls -l {}'.format(filename)
>>> print command # executed by a shell: boom!
ls -l somefile; rm -rf ~
:func:`quote` lets you plug the security hole::
>>> command = 'ls -l {}'.format(quote(filename))
>>> print command
ls -l 'somefile; rm -rf ~'
>>> remote_command = 'ssh home {}'.format(quote(command))
>>> print remote_command
ssh home 'ls -l '"'"'somefile; rm -rf ~'"'"''
The quoting is compatible with UNIX shells and with :func:`shlex.split`:
>>> remote_command = shlex.split(remote_command)
>>> remote_command
['ssh', 'home', "ls -l 'somefile; rm -rf ~'"]
>>> command = shlex.split(remote_command[-1])
>>> command
['ls', '-l', 'somefile; rm -rf ~']
.. _template-objects:
Template Objects
...
...
Doc/library/subprocess.rst
Dosyayı görüntüle @
61822667
...
...
@@ -256,6 +256,10 @@ default values. The arguments that are most commonly needed are:
from this vulnerability; see the Note in the :class:`Popen` constructor
documentation for helpful hints in getting ``shell=False`` to work.
When using ``shell=True``, :func:`pipes.quote` can be used to properly
escape whitespace and shell metacharacters in strings that are going to
be used to construct shell commands.
These options, along with all of the other options, are described in more
detail in the :class:`Popen` constructor documentation.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment