def shquote(text): """Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)""" if not text: return "''" text = six.str(text) if not text: return "''" for c in text: if c not in _safechars: break else: return text if "'" not in text: return "'" + text + "'" res = six.str("").join((six.str('\\' + c) if c in _funnychars else c) for c in text) return six.str('"') + res + six.str('"')
def shquote(text): """Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)""" text = six.str(text) if sys.version_info >= (3, 3): return shlex.quote(text) else: import pipes return pipes.quote(text)
def formulate(self, level = 0, args = ()): argv = [six.str(self.executable)] for a in args: if a is None: continue if isinstance(a, BaseCommand): if level >= self.QUOTE_LEVEL: argv.extend(shquote_list(a.formulate(level + 1))) else: argv.extend(a.formulate(level + 1)) elif isinstance(a, (list, tuple)): argv.extend(shquote(b) if level >= self.QUOTE_LEVEL else six.str(b) for b in a) else: argv.append(shquote(a) if level >= self.QUOTE_LEVEL else six.str(a)) # if self.custom_encoding: # argv = [a.encode(self.custom_encoding) for a in argv if isinstance(a, six.string_types)] return argv
def shquote(text): """Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)""" if not text: return "''" text = six.str(text) if not text: return "''" for c in text: if c not in _safechars: break else: return text if "'" not in text: return "'" + text + "'" res = six.str("").join( (six.str('\\' + c) if c in _funnychars else c) for c in text) return six.str('"') + res + six.str('"')
def test_runfile_rich(self): import stat, os name = self.richstr + six.str("_program") with open(name, 'w') as f: f.write("#!/usr/bin/env python\nprint('yes')") st = os.stat(name) os.chmod(name, st.st_mode | stat.S_IEXEC) assert "yes" in local[local.cwd / name]()
def test_runfile_rich(self): import stat, os name = self.richstr + six.str("_program") with open(name, 'w') as f: f.write("#!{}\nprint('yes')".format(sys.executable)) st = os.stat(name) os.chmod(name, st.st_mode | stat.S_IEXEC) assert "yes" in local[local.cwd / name]()
def formulate(self, level=0, args=()): argv = [six.str(self.executable)] for a in args: if a is None: continue if isinstance(a, BaseCommand): if level >= self.QUOTE_LEVEL: argv.extend(shquote_list(a.formulate(level + 1))) else: argv.extend(a.formulate(level + 1)) elif isinstance(a, (list, tuple)): argv.extend( shquote(b) if level >= self.QUOTE_LEVEL else six.str(b) for b in a) else: argv.append( shquote(a) if level >= self.QUOTE_LEVEL else six.str(a)) # if self.custom_encoding: # argv = [a.encode(self.custom_encoding) for a in argv if isinstance(a, six.string_types)] return argv