about summary refs log tree commit diff stats
path: root/apps/arith.mu
diff options
context:
space:
mode:
Diffstat (limited to 'apps/arith.mu')
0 files changed, 0 insertions, 0 deletions
f metacharacters to OpenConsole' href='/akspecs/ranger/commit/ranger/ext/shell_escape.py?id=c8c92966bbbd2425fff1c3e4ae83cda8fa13a703'>c8c92966 ^
9f5eeff7 ^
e52629c1 ^

dd6b4723 ^
76791a70 ^
51ec08da ^
8f2f1767 ^

ab41c776 ^
d906b0dd ^
d1a1173d ^

8f2f1767 ^
ab41c776 ^
d906b0dd ^
d1a1173d ^



39e5b4c6 ^
b3d031a9 ^

d1a1173d ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

                                                                 
 
                                                                         
 
                                                                  

 
                                                     
                                                           
                                                                                         

                                                        
 
                        

                                                        
 
 
                      



                                       
                                                                        

                                        
              
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

"""Functions to escape metacharacters of arguments for shell commands."""

from __future__ import (absolute_import, division, print_function)


META_CHARS = (' ', "'", '"', '`', '&', '|', ';', '#',
              '$', '!', '(', ')', '[', ']', '<', '>', '\t')
UNESCAPABLE = set(map(chr, list(range(9)) + list(range(10, 32)) + list(range(127, 256))))
META_DICT = dict([(mc, '\\' + mc) for mc in META_CHARS])


def shell_quote(string):
    """Escapes by quoting"""
    return "'" + str(string).replace("'", "'\\''") + "'"


def shell_escape(arg):
    """Escapes by adding backslashes"""
    arg = str(arg)
    if UNESCAPABLE & set(arg):
        return shell_quote(arg)
    arg = arg.replace('\\', '\\\\')  # make sure this comes at the start
    for key, value in META_DICT.items():
        arg = arg.replace(key, value)
    return arg