10 examples of 'triple quotes in python' in Python

Every line of 'triple quotes in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
42def DoubleQuote(s):
43 """Return an shell-escaped version of the string using double quotes.
44
45 Reliably quote a string which may contain unsafe characters (e.g. space
46 or quote characters), while retaining some shell features such as variable
47 interpolation.
48
49 The returned value can be used in a shell command line as one token that gets
50 to be further interpreted by the shell.
51
52 The set of characters that retain their special meaning may depend on the
53 shell implementation. This set usually includes: '$', '`', '\', '!', '*',
54 and '@'.
55
56 Args:
57 s: The string to quote.
58
59 Return:
60 The string quoted using double quotes.
61 """
62 if not s:
63 return '""'
64 elif all(c in _SafeShellChars for c in s):
65 return s
66 else:
67 return '"' + s.replace('"', '\\"') + '"'
401@utils.check_messages('backtick')
402def visit_backquote(self, node):
403 self.add_message('backtick', node=node)
41def _quote(s):
42 """Return a shell-escaped version of the string *s*."""
43 if not s:
44 return "''"
45 if six.PY3:
46 if _find_unsafe.search(s) is None:
47 return s
48 else:
49 for c in s:
50 if c not in _safechars:
51 break
52 else:
53 if not s:
54 return "''"
55 return s
56
57 # use single quotes, and put single quotes into double quotes
58 # the string $'b is then quoted as '$'"'"'b'
59 return '"' + s.replace('"', '"\'"\'"') + '"'
176def _quote(s):
177 '''Given a string, returns a version that can be used literally on a shell
178 command line, enclosing it with single quotes if necessary.
179
180 As a special case, if given an int, returns a string containing the int,
181 not enclosed in quotes.
182 '''
183 if type(s) == int:
184 return '%d' % s
185
186 # Empty strings need to be quoted to have any significance
187 if s and not SHELL_QUOTE_RE.search(s) and not s.startswith('~'):
188 return s
189
190 # Single quoted strings can contain any characters unescaped except the
191 # single quote itself, which can't even be escaped, so the string needs to
192 # be closed, an escaped single quote added, and reopened.
193 t = type(s)
194 return t("'%s'") % s.replace(t("'"), t("'\\''"))
265def test_quote(lexer):
266 fragment = '> a\n> quote'
267 tokens = [
268 (Keyword, '> '),
269 (Generic.Emph, 'a\n'),
270 (Keyword, '> '),
271 (Generic.Emph, 'quote\n'),
272 ]
273 assert list(lexer.get_tokens(fragment)) == tokens
91def stripQuotes(s):
92 if s.startswith('"') and s.endswith('"'):
93 s = s[1:-1]
94 return s
208def quotes_in_str(value):
209 """ Add quotes around value if it's a string """
210 if type(value) == str:
211 return ("\"%s\"" % value)
212 else:
213 return (value)
11def strip_quotes(string):
12 if string.startswith('"') and string.endswith('"'):
13 return string[1:-1]
14 return string
333def quote(s):
334 return re_quote.sub("_", s)
17def _quote(s):
18 # crude way to sanitise table and field names
19 # conform with the SQL-92 standard. See http://stackoverflow.com/a/214344
20 return quotechar + s.replace(quotechar, quotechar+quotechar) + quotechar

Related snippets