Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/shellescape-3.4.1.dist-info/DESCRIPTION.rst @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 Source Repository: https://github.com/chrissimpkins/shellescape | |
2 | |
3 Description | |
4 ----------- | |
5 | |
6 The shellescape Python module defines the ``shellescape.quote()`` function that returns a shell-escaped version of a Python string. This is a backport of the ``shlex.quote()`` function from Python 3.4.3 that makes it accessible to users of Python 3 versions < 3.3 and all Python 2.x versions. | |
7 | |
8 quote(s) | |
9 -------- | |
10 | |
11 >From the Python documentation: | |
12 | |
13 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. | |
14 | |
15 This idiom would be unsafe: | |
16 | |
17 .. code-block:: python | |
18 | |
19 >>> filename = 'somefile; rm -rf ~' | |
20 >>> command = 'ls -l {}'.format(filename) | |
21 >>> print(command) # executed by a shell: boom! | |
22 ls -l somefile; rm -rf ~ | |
23 | |
24 | |
25 ``quote()`` lets you plug the security hole: | |
26 | |
27 .. code-block:: python | |
28 | |
29 >>> command = 'ls -l {}'.format(quote(filename)) | |
30 >>> print(command) | |
31 ls -l 'somefile; rm -rf ~' | |
32 >>> remote_command = 'ssh home {}'.format(quote(command)) | |
33 >>> print(remote_command) | |
34 ssh home 'ls -l '"'"'somefile; rm -rf ~'"'"'' | |
35 | |
36 | |
37 The quoting is compatible with UNIX shells and with ``shlex.split()``: | |
38 | |
39 .. code-block:: python | |
40 | |
41 >>> remote_command = split(remote_command) | |
42 >>> remote_command | |
43 ['ssh', 'home', "ls -l 'somefile; rm -rf ~'"] | |
44 >>> command = split(remote_command[-1]) | |
45 >>> command | |
46 ['ls', '-l', 'somefile; rm -rf ~'] | |
47 | |
48 | |
49 Usage | |
50 ----- | |
51 | |
52 Include ``shellescape`` in your project setup.py file ``install_requires`` dependency definition list: | |
53 | |
54 .. code-block:: python | |
55 | |
56 setup( | |
57 ... | |
58 install_requires=['shellescape'], | |
59 ... | |
60 ) | |
61 | |
62 | |
63 Then import the ``quote`` function into your module(s) and use it as needed: | |
64 | |
65 .. code-block:: python | |
66 | |
67 #!/usr/bin/env python | |
68 # -*- coding: utf-8 -*- | |
69 | |
70 from shellescape import quote | |
71 | |
72 filename = "somefile; rm -rf ~" | |
73 escaped_shell_command = 'ls -l {}'.format(quote(filename)) | |
74 | |
75 | |
76 Issue Reporting | |
77 --------------- | |
78 | |
79 Issue reporting is available on the `GitHub repository <https://github.com/chrissimpkins/shellescape/issues>`_ | |
80 | |
81 | |
82 | |
83 |