Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/pipes.rst

    r2 r391  
    1 
    21:mod:`pipes` --- Interface to shell pipelines
    32=============================================
     
    87.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
    98
     9**Source code:** :source:`Lib/pipes.py`
     10
     11--------------
    1012
    1113The :mod:`pipes` module defines a class to abstract the concept of a *pipeline*
     
    1416Because the module uses :program:`/bin/sh` command lines, a POSIX or compatible
    1517shell for :func:`os.system` and :func:`os.popen` is required.
    16 
    17 The :mod:`pipes` module defines the following class:
    1818
    1919
     
    2525
    2626   >>> import pipes
    27    >>> t=pipes.Template()
     27   >>> t = pipes.Template()
    2828   >>> t.append('tr a-z A-Z', '--')
    29    >>> f=t.open('/tmp/1', 'w')
     29   >>> f = t.open('pipefile', 'w')
    3030   >>> f.write('hello world')
    3131   >>> f.close()
    32    >>> open('/tmp/1').read()
     32   >>> open('pipefile').read()
    3333   'HELLO WORLD'
     34
     35
     36.. function:: quote(s)
     37
     38   .. deprecated:: 2.7
     39      Prior to Python 2.7, this function was not publicly documented.  It is
     40      finally exposed publicly in Python 3.3 as the
     41      :func:`quote <shlex.quote>` function in the :mod:`shlex` module.
     42
     43   Return a shell-escaped version of the string *s*.  The returned value is a
     44   string that can safely be used as one token in a shell command line, for
     45   cases where you cannot use a list.
     46
     47   This idiom would be unsafe::
     48
     49      >>> filename = 'somefile; rm -rf ~'
     50      >>> command = 'ls -l {}'.format(filename)
     51      >>> print command  # executed by a shell: boom!
     52      ls -l somefile; rm -rf ~
     53
     54   :func:`quote` lets you plug the security hole::
     55
     56      >>> command = 'ls -l {}'.format(quote(filename))
     57      >>> print command
     58      ls -l 'somefile; rm -rf ~'
     59      >>> remote_command = 'ssh home {}'.format(quote(command))
     60      >>> print remote_command
     61      ssh home 'ls -l '"'"'somefile; rm -rf ~'"'"''
     62
     63   The quoting is compatible with UNIX shells and with :func:`shlex.split`:
     64
     65      >>> remote_command = shlex.split(remote_command)
     66      >>> remote_command
     67      ['ssh', 'home', "ls -l 'somefile; rm -rf ~'"]
     68      >>> command = shlex.split(remote_command[-1])
     69      >>> command
     70      ['ls', '-l', 'somefile; rm -rf ~']
    3471
    3572
Note: See TracChangeset for help on using the changeset viewer.